package com.gamedog.vididin.features.withdrawrecord.fragments



import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.ama.core.architecture.appBase.AppViewsFragment
import com.ama.core.architecture.appBase.OnFragmentBackgroundListener
import com.ama.core.architecture.util.setStatusBarDarkFont
import com.gamedog.vididin.core.login.login.AccountManager
import com.gamedog.vididin.features.withdrawrecord.RecordGoldRvAdapter
import com.gamedog.vididin.manager.RecordsManager
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import kotlin.getValue
import com.viddin.videos.free.databinding.FragmentWithdrawRecordGoldBinding as ViewBinding
import com.gamedog.vididin.features.withdrawrecord.RecordGoldUiState as UiState
import com.gamedog.vididin.features.withdrawrecord.RecordGoldViewModel as ViewModel




@AndroidEntryPoint
class GoldRecordFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(),
    OnFragmentBackgroundListener {
    private lateinit var mAdapter: RecordGoldRvAdapter
    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() {
        binding?.root?.let { setImmerseRootView(it) }
        isStatusBarDarkFont = true
    }

    override fun ViewBinding.initViews() {
        setupRecyclerView()
        tvGoldNum.text = AccountManager.getGold().toString()
    }

    override fun ViewBinding.initListeners() {

    }

    override fun ViewBinding.initObservers() {
    }

    override fun ViewBinding.onUiStateCollect(uiState: UiState) {

    }

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


    private fun setupRecyclerView() {
        mAdapter = RecordGoldRvAdapter()
        binding?.recyclerView?.adapter = mAdapter
        binding?.recyclerView?.layoutManager = LinearLayoutManager(requireContext())

        lifecycleScope.launch {
            mAdapter.submitList(RecordsManager.instance().getGoldRecords())
        }
    }

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