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.ResUtil
import com.ama.core.architecture.util.setStatusBarDarkFont
import com.gamedog.vididin.features.withdrawrecord.RecordCashRvAdapter
import com.gamedog.vididin.manager.RecordsManager
import com.gamedog.vididin.manager.WithdrawManager
import com.viddin.videos.free.R
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import kotlin.getValue
import com.viddin.videos.free.databinding.FragmentWithdrawRecordCashBinding as ViewBinding
import com.gamedog.vididin.features.withdrawrecord.RecordCashUiState as UiState
import com.gamedog.vididin.features.withdrawrecord.RecordCashViewModel as ViewModel




@AndroidEntryPoint
class CashRecordFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(),
    OnFragmentBackgroundListener {
    private lateinit var mAdapter: RecordCashRvAdapter
    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()

        tvCashNum.text = buildString {
            append(ResUtil.getString(R.string.cash))
            append(" ")
            append(WithdrawManager.instance().getHasWithdrawSuccessCashCount())
        }
    }

    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 = RecordCashRvAdapter()
        binding?.recyclerView?.adapter = mAdapter
        binding?.recyclerView?.layoutManager = LinearLayoutManager(requireContext())

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

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