package com.develop.auth.ui

import android.graphics.Color
import android.text.Spannable
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.style.ForegroundColorSpan
import android.view.LayoutInflater
import android.view.ViewGroup
import com.develop.auth.R
import com.develop.auth.databinding.FragmentMemberLaunchBinding
import com.develop.food.base.router.Screens
import com.develop.food.base.ui.ViewBindingFragment
import com.develop.food.base.router.navigateTo

class MemberLaunchFragment: ViewBindingFragment<FragmentMemberLaunchBinding>() {

    override fun createViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): FragmentMemberLaunchBinding {
        return FragmentMemberLaunchBinding.inflate(inflater, container, false)
    }

    override fun onPostCreateView() {
        val memberText = getString(R.string.member)
        val description = getString(R.string.not_a_member_yet, memberText)
        val memberIndex = description.indexOf(memberText)
        val spannable = SpannableString(description)
        spannable.setSpan(
            ForegroundColorSpan(Color.RED),
            memberIndex,
            memberIndex + memberText.length,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        binding.tvTitle.text = spannable
        binding.tvLoginOrSignup.setOnClickListener {
            parentFragmentManager
                .beginTransaction()
                .replace(R.id.fl_container, MemberLoginFragment())
                .commitAllowingStateLoss()
        }
        binding.tvSkipForNow.setOnClickListener {
            navigateTo(Screens.Main.ENTRANCE_CHOSEN)
        }
    }
}