package com.base.locationsharewhite.ui.howuse

import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import androidx.activity.addCallback
import androidx.core.view.updatePadding
import com.base.locationsharewhite.R
import com.base.locationsharewhite.ads.AdsMgr
import com.base.locationsharewhite.ads.AdsShowCallBack
import com.base.locationsharewhite.databinding.ActivityHowUseBinding
import com.base.locationsharewhite.helper.BaseActivity
import com.base.locationsharewhite.utils.BarUtils
import com.base.locationsharewhite.utils.LogEx

class HowUseActivity : BaseActivity<ActivityHowUseBinding>() {

    override val binding: ActivityHowUseBinding by lazy {
        ActivityHowUseBinding.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())
    }

    override fun onResumeOneShoot() {
        super.onResumeOneShoot()
        val recreated = changeLanguage(this, intent.extras ?: Bundle())
        if (recreated) return

        isGuide = intent.extras?.getBoolean("isGuide", false) ?: false
        LogEx.logDebug(TAG, "isGuide=$isGuide")

        if (AdsMgr.adsConfigBean.functionInShowAd && !isGuide) {
            AdsMgr.showInsert(this, showCallBack = object : AdsShowCallBack() {
                override fun close(where: Int) {
                    LogEx.logDebug(TAG, "where=$where")
                }

                override fun failed(where: Int) {
                    LogEx.logDebug(TAG, "where=$where")
                }

                override fun googleFailed(where: Int) {
                    LogEx.logDebug(TAG, "where=$where")
                }
            })
        }
        AdsMgr.showNative(binding.flAd, R.layout.layout_admob_app_exit)
    }

    override fun initListener() {
        super.initListener()
        onBackPressedDispatcher.addCallback {
            if (AdsMgr.adsConfigBean.functionBackShowAd) {
                AdsMgr.showInsert(this@HowUseActivity, false, object : AdsShowCallBack() {
                    override fun close(where: Int) {
                        finishToMain(200)
                    }

                    override fun failed(where: Int) {
                        finishToMain(200)
                    }

                    override fun googleFailed(where: Int) {
                        finishToMain(200)
                    }
                })
            } else {
                finishToMain()
            }
        }
        binding.flFanhui.setOnClickListener {
            onBackPressedDispatcher.onBackPressed()
        }
        binding.flShareLocation.setOnClickListener {
            startActivity(Intent(this, HowUseShareActivity::class.java))
        }
        binding.flViewLocation.setOnClickListener {
            startActivity(Intent(this, HowViewOtherActivity::class.java))
        }
    }

}