package com.gamedog.vididin.main.fragments



import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.fragment.app.viewModels
import com.ama.core.architecture.appBase.AppViewsFragment
import com.ama.core.architecture.appBase.OnFragmentBackgroundListener
import com.ama.core.architecture.util.setOnClickBatch
import com.ama.core.architecture.util.setStatusBarDarkFont
import com.ama.core.common.util.dp
import com.gamedog.vididin.router.Router
import dagger.hilt.android.AndroidEntryPoint
import kotlin.getValue
import com.gamedog.vididin.databinding.VididinappFeatureMineFragmentMineBinding as ViewBinding
import com.gamedog.vididin.main.fragments.mine.MineUiState as UiState
import com.gamedog.vididin.main.fragments.mine.MineViewModel as ViewModel




@AndroidEntryPoint
class MineFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(),
    OnFragmentBackgroundListener {
    override val mViewModel: ViewModel by viewModels()
    override var isBackgroundBright: Boolean = true



    private var isStatusBarDarkFont = false

    override fun inflateViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?,
    ) = ViewBinding.inflate(inflater, container, false)

    override fun ViewBinding.initWindowInsets() {
        ViewCompat.setOnApplyWindowInsetsListener(topBackground) { v, insets ->
            val systemBars =
                insets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
            v.updatePadding(top = systemBars.top + 20.dp)
            insets
        }
    }

    override fun ViewBinding.initViews() {
        setOnClickBatch(rlPrivacy, rlVersion, rlFeedback) {
            when (this) {
                rlPrivacy -> {
                    Router.Privacy.startActivity(requireActivity())
                }
                rlVersion -> {
                    Router.Version.startActivity(requireActivity())
                }
                rlFeedback -> {
                    Router.Feedback.startActivity(requireActivity())
                }
            }
        }
    }

    override fun ViewBinding.initListeners() {
        nestedScrollView.setOnScrollChangeListener { _, _, scrollY, _, _ ->
            isStatusBarDarkFont = scrollY > topBackground.height
            setStatusBarDarkFont(isStatusBarDarkFont)
        }
    }

    override fun ViewBinding.initObservers() {
    }

    override fun ViewBinding.onUiStateCollect(uiState: UiState) {
        //dynamicColorsSwitch.isChecked = uiState.useDynamicColor
    }

    override fun onResume() {
        super.onResume()
        setStatusBarDarkFont(isDarkFont = isStatusBarDarkFont)
    }

    companion object {
        internal fun newInstance() = MineFragment()
    }
}