package importantedto.afteredto.constitutionaledto

import android.app.Dialog
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import importantedto.appliededto.surgeonedto.promiseedto.Byedto
import importantedto.gallonedto.Rideredto
import importantedto.gallonedto.Rocketedto

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

    protected abstract val binding: T


    lateinit var launcher: Peakedto

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

        Rideredto.event("page_${javaClass.simpleName}")
        Rocketedto.getInstance().addActivity(this)
        initView()
        initListener()
    }

    protected abstract fun initView()

    protected open fun initListener() {}


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

    var dialog: Dialog? = null
    override fun onDestroy() {
        super.onDestroy()
        Rocketedto.getInstance().removeActivity(this)
        if (dialog != null) {
            dialog?.dismiss()
            dialog = null
        }
    }

}