package importantedto.appliededto.surgeonedto.promiseedto.enteredto.eatenedto.ridingedto

import android.content.Intent
import android.view.View
import android.widget.Toast
import androidx.activity.addCallback
import androidx.lifecycle.lifecycleScope
import com.base.datarecovery.databinding.DirectedtoBinding
import importantedto.admireedto.sweptedto.Differenceedto
import importantedto.afteredto.constitutionaledto.Murderedto
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class Madeedto : Murderedto<DirectedtoBinding>() {

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

    private var job: Job? = null

    override fun initView() {
    }

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


    private fun jumpJob() = lifecycleScope.launch(Dispatchers.Main) {
        delay(5000)
        binding.senioredto.visibility = View.GONE
        binding.senioredto.clearAnimation()
        binding.eternaledto.visibility = View.VISIBLE
        binding.eternaledto.playAnimation()
        binding.lickedto.text = "Completed!"
        delay(1000)
        Differenceedto.admobMaxShowInterstitialAd(this@Madeedto) {
            startActivity(Intent(this@Madeedto, Premiumedto::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
    }
}