package importantedto.appliededto.surgeonedto.promiseedto.nobleedto.defendedto.tastyedto

import android.content.Intent
import android.widget.Toast
import androidx.activity.addCallback
import androidx.lifecycle.lifecycleScope
import com.base.datarecovery.databinding.CapedtoBinding
import importantedto.admireedto.sweptedto.Differenceedto
import importantedto.afteredto.constitutionaledto.Murderedto
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.random.Random

class Weakedto : Murderedto<CapedtoBinding>() {

    override val binding: CapedtoBinding by lazy {
        CapedtoBinding.inflate(layoutInflater)
    }

    private var job: Job? = null

    override fun initView() {

    }

    override fun initListener() {
        onBackPressedDispatcher.addCallback {
            Toast.makeText(this@Weakedto, "wait a moment", Toast.LENGTH_SHORT).show()
        }
    }

    fun jumpJob() = lifecycleScope.launch {
        delay(Random.nextLong(3000, 4500))
        Differenceedto.admobMaxShowInterstitialAd(this@Weakedto) {
            startActivity(Intent(this@Weakedto, Trafficedto::class.java))
            finish()
        }
    }

    override fun onResume() {
        super.onResume()
        if (job?.isActive == false || job == null) {
            job = jumpJob()
        }
    }

    override fun onPause() {
        super.onPause()
        job?.cancel()
        job = null
    }


}