package com.mobiuz.app.dev.ui.settings.safety

import android.os.Bundle
import android.view.View
import android.widget.SeekBar
import androidx.core.os.bundleOf
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import com.mobiuz.app.R
import com.mobiuz.app.databinding.FragmentSafetyBinding
import com.mobiuz.app.dev.model.SharedPref
import com.mobiuz.app.dev.ui.base.BaseFragment
import com.mobiuz.app.dev.ui.global.ButtonClick
import com.mobiuz.app.dev.ui.global.CONSTANTS
import com.mobiuz.app.dev.utils.Utils
import com.mobiuz.app.dev.utils.extensions.showMessage
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class SafetyFragment : BaseFragment(R.layout.fragment_safety) {

    @Inject
    lateinit var pref: SharedPref

    private var _bn: FragmentSafetyBinding? = null
    private val bn get() = _bn ?: throw NullPointerException("cannot inflate")
    private val navController: NavController by lazy(LazyThreadSafetyMode.NONE) { NavHostFragment.findNavController(this) }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        _bn = FragmentSafetyBinding.bind(view)
        setUpUI()
        collects()

    }

    override fun setUpUI() {
        bn.apply {

            toolbar.setNavigationOnClickListener {
                navController.navigateUp()
            }
            val text = getString(R.string.settings_safety)
            val myText = text.replace(CONSTANTS.DEFAULT_PHONE,pref.userPhone)
            txtPhoneSafety.text = myText
            switchBiometria.isChecked = pref.isUseFingerPrint
            switchBiometria.setOnCheckedChangeListener { _, isChecked ->
                val message = if(isChecked) getString(R.string.biometric_enabled) else getString(R.string.biometric_disabled)
                showToastMessage(message)
                pref.isUseFingerPrint = isChecked
            }
            btn1.setOnClickListener(object : ButtonClick(){
                override fun onSingleClick(v: View?) {
                }
            })
            btnChangePin.setOnClickListener(object : ButtonClick(){
                override fun onSingleClick(v: View?) {
                    navController.navigate(R.id.pinFragment, bundleOf(CONSTANTS.TYPE_PIN  to CONSTANTS.CURRENT_PIN), Utils.navOptions())
                }
            })
            btnChangePassword.setOnClickListener(object : ButtonClick(){
                override fun onSingleClick(v: View?) {
                    navController.navigate(R.id.changePasswordFragment, bundleOf(CONSTANTS.TYPE_PASSWORD to CONSTANTS.CURRENT_PASSWORD),Utils.navOptions())
                }
            })
        }
    }


    override fun collects() {
    }


    override fun onDestroy() {
        _bn = null
        super.onDestroy()
    }
}