package rallyedto.battleedto.acresedto

import android.app.Dialog
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import rallyedto.finishedto.Acceptedto
import rallyedto.sunedto.tumouredto.majorityedto.loseedto.Togetheredto
import rallyedto.talledto.blewedto.Robedto
import rallyedto.talledto.blewedto.Trenchedto

abstract class Lemonedto<T : ViewBinding> : AppCompatActivity() {

    protected abstract val binding: T


    lateinit var launcher: Dareedto

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        launcher = Dareedto(this)
        setContentView(binding.root)

        Robedto.event("page_${javaClass.simpleName}")
        Trenchedto.addActivity(this)
        initView()
        initListener()
    }

    protected abstract fun initView()

    protected open fun initListener() {}


    fun finishToMain() {
        if (this !is Acceptedto && !Trenchedto.isActivityInStack(Acceptedto::class.java)) {
            startActivity(Intent(this, Acceptedto::class.java))
        }
        finish()
    }

    var dialog: Dialog? = null
    override fun onDestroy() {
        super.onDestroy()
        Trenchedto.removeActivity(this)
        if (dialog != null) {
            dialog?.dismiss()
            dialog = null
        }
    }
    fun admobMaxShowInterstitialAd(
        isShow: Boolean = Togetheredto.isShowLoadingAdInter(),
        complete: (() -> Unit)? = null
    ) {
        if (this.isFinishing || this.isDestroyed ) return
        if (isShow) {
            Togetheredto.showInterstitialAd(
                this,
                dismissed = {
                    complete?.invoke()
                },
                completed = {

                },
                failed = {
                    complete?.invoke()
                }
            )
        }else{
            complete?.invoke()
        }
    }
}