package rowedto.jockeyedto.sheetedto.atticedto.rededto.knifeedto.economyedto

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.LeadedtoBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import rowedto.jockeyedto.sheetedto.knewedto.economicedto.copyrightedto.Crossingedto
import rowedto.jockeyedto.sheetedto.strangeedto.pyramidedto.particlesedto.Scandaledto

class Viableedto : Crossingedto<LeadedtoBinding>() {

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

    private var job: Job? = null

    override fun initView() {
        Scandaledto.admobMaxShowNativeAd(this,binding.tooledto,1)
    }

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


    private fun jumpJob() = lifecycleScope.launch(Dispatchers.Main) {
        delay(5000)
        binding.giftedto.visibility = View.GONE
        binding.giftedto.clearAnimation()
        binding.innovationedto.visibility = View.VISIBLE
        binding.innovationedto.playAnimation()
        binding.lightedto.text = "Completed!"
        delay(1000)
        Scandaledto.admobMaxShowInterstitialAd(this@Viableedto) {
            startActivity(Intent(this@Viableedto, Restrictedto::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
    }
}