package com.base.locationsharewhite.ui.set

import android.content.Intent
import android.graphics.Color
import androidx.core.view.updatePadding
import com.base.locationsharewhite.R
import com.base.locationsharewhite.ads.AdsMgr
import com.base.locationsharewhite.bean.ConstObject.appLanguageCountrySp
import com.base.locationsharewhite.bean.ConstObject.appLanguageSp
import com.base.locationsharewhite.bean.LanguageBean
import com.base.locationsharewhite.databinding.ActivityLanguageBinding
import com.base.locationsharewhite.helper.BaseActivity
import com.base.locationsharewhite.ui.howuse.HowUseActivity
import com.base.locationsharewhite.utils.BarUtils
import com.base.locationsharewhite.utils.LogEx
import java.util.Locale

class LanguageActivity : BaseActivity<ActivityLanguageBinding>() {

    private lateinit var adapter: LanguageAdapter

    override val binding: ActivityLanguageBinding by lazy {
        ActivityLanguageBinding.inflate(layoutInflater)
    }
    private var isGuide: Boolean = false
    override fun initView() {
        BarUtils.setStatusBarLightMode(this, true)
        BarUtils.setStatusBarColor(this, Color.WHITE)
        binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
        isGuide = intent.extras?.getBoolean("isGuide") ?: false

        AdsMgr.showNative(binding.flAd, R.layout.layout_admob_app_exit)
        adapter = LanguageAdapter(click = { item ->

        })
        binding.rv.adapter = adapter

        initData()

    }

    private fun initData() {
        val languageBeanList = listOf(
            LanguageBean(LanguageBean.English, Locale.ENGLISH.language, Locale.ENGLISH.country),
            LanguageBean(LanguageBean.简体中文, Locale.SIMPLIFIED_CHINESE.language, Locale.SIMPLIFIED_CHINESE.country),
//            LanguageBean(LanguageBean.繁體中文, Locale.TRADITIONAL_CHINESE.language, Locale.TRADITIONAL_CHINESE.country),
            LanguageBean(LanguageBean.日本語, Locale.JAPAN.language, Locale.JAPAN.country),
            LanguageBean(LanguageBean.한국인, Locale.KOREAN.language, Locale.KOREAN.country),
        )

        languageBeanList.findLast { it.language == appLanguageSp && it.country == appLanguageCountrySp }?.isSelect = true

        adapter.submitList(languageBeanList)
    }


    override fun initListener() {
        super.initListener()
        binding.tvNext.setOnClickListener {
            val selectLanguageBean = adapter.items.findLast { it.isSelect }
            selectLanguageBean ?: return@setOnClickListener
            LogEx.logDebug(TAG, "selectLanguageBean=$selectLanguageBean")
            appLanguageSp = selectLanguageBean.language
            appLanguageCountrySp = selectLanguageBean.country

            if (isGuide) {
                startActivity(Intent(this, HowUseActivity::class.java).apply {
                    putExtra("isGuide", true)
                })
            }
            finish()
        }
    }

    override fun onResume() {
        super.onResume()
    }

}