package com.gamedog.vididin.features.withdrawrecord

import android.app.Activity
import android.content.Intent
import android.view.LayoutInflater
import androidx.activity.viewModels
import com.ama.core.architecture.appBase.AppViewsActivity
import com.ama.core.architecture.util.ResUtil
import com.ama.core.architecture.util.setOnClickBatch
import com.viddin.videos.free.R
import com.gamedog.vididin.main.interfaces.OnTabStyleListener
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import dagger.hilt.android.AndroidEntryPoint
import kotlin.getValue
import com.viddin.videos.free.databinding.ActivityWithdrawRecordBinding as ViewBinding
import com.gamedog.vididin.main.MainUiState as UiState
import com.gamedog.vididin.main.MainViewModel as ViewModel


@AndroidEntryPoint
class WithdrawRecordActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(), OnTabStyleListener {

    override val mViewModel: ViewModel by viewModels()
    override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater)

    override fun ViewBinding.initViews() {

        with(binding) {
            setupViewPager()

            setOnClickBatch(ivBack) {
                when (this) {
                    ivBack ->  {
                        finish()
                    }
                }
            }
        }

    }

    override fun ViewBinding.initWindowInsets() {
        setImmerseRootView(binding.root)
    }

    override fun ViewBinding.initListeners() {
        //TODO("Not yet implemented")
    }

    override fun ViewBinding.initObservers() {
        //TODO("Not yet implemented")
    }

    override fun ViewBinding.onUiStateCollect(uiState: UiState) {
        //TODO("Not yet implemented")
    }

    override fun onTabIsDarkFont(isDarkFont: Boolean) {
        //TODO("Not yet implemented")
    }


    private fun setupViewPager() {
        val adapter = ViewPagerAdapter(this)
        binding.viewPager.adapter = adapter

        with (binding.tabLayout) {
            addOnTabSelectedListener(object: TabLayout.OnTabSelectedListener {
                override fun onTabSelected(tab: TabLayout.Tab?) {
                    setTabTextColors(ResUtil.getColor(R.color.black),
                        ResUtil.getColor(if (selectedTabPosition == 0) R.color.green_39 else R.color.yellow_0b))
                }

                override fun onTabUnselected(tab: TabLayout.Tab?) {
                }

                override fun onTabReselected(tab: TabLayout.Tab?) {
                }

            })
        }

        TabLayoutMediator(binding.tabLayout, binding.viewPager) { tab, position ->
            tab.text = when (position) {
                0 -> ResUtil.getString(R.string.record_cash_title)
                1 -> ResUtil.getString(R.string.record_gold_title)
                else -> null
            }
        }.attach()
    }


    companion object {
        internal fun startActivity(activity: Activity) {
            activity.startActivity(Intent(activity.applicationContext, WithdrawRecordActivity::class.java))
        }
    }

}





