package com.develop.auth.ui

import android.graphics.Color
import android.text.Spannable
import android.text.SpannableString
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.auth.viewmodel.FragmentTag
import com.develop.auth.viewmodel.MemberViewModel
import com.develop.base.ext.navigateTo
import com.develop.base.mvvm.BaseBVMFragment
import com.develop.common.router.Screens
import com.develop.common.ui.CommonBVMFragment

class MemberLaunchFragment: CommonBVMFragment<FragmentMemberLaunchBinding, MemberViewModel>() {

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

    override fun onPostCreateView() {
        super.onPostCreateView()
        val memberText = getString(com.develop.common.R.string.member)
        val description = getString(com.develop.common.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 {
            viewModel.fragmentChangeLiveData.postValue(FragmentTag.MEMBER_LOGIN)
        }
        binding.tvSkipForNow.setOnClickListener {
            navigateTo(Screens.Main.ENTRANCE_CHOSEN)
        }
    }

    override fun createViewModel(): MemberViewModel {
        return getViewModelOfActivity(MemberViewModel::class.java)
    }
}