package rowedto.jockeyedto.sheetedto.atticedto.expandedto.colonyedto.dietedto

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.ValidedtoBinding
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
import kotlin.random.Random

class Successedto : Crossingedto<ValidedtoBinding>() {

    override val binding: ValidedtoBinding by lazy {
        ValidedtoBinding.inflate(layoutInflater)
    }
            ;
    private var job: Job? = null
    override fun initView() {

        Scandaledto.admobMaxShowNativeAd(this,binding.tooledto,1)
    }

    private fun jumpJob() = lifecycleScope.launch(Dispatchers.Main) {
        delay(Random.nextLong(4000, 4500))
        binding.giftedto.visibility = View.INVISIBLE
        binding.innovationedto.visibility = View.VISIBLE
        binding.innovationedto.playAnimation()
        delay(1500)

        val tittle = this@Successedto.intent?.extras?.getString("tittle")
        Scandaledto.admobMaxShowInterstitialAd(this@Successedto) {
            startActivity(Intent(this@Successedto, Beautifuledto::class.java).apply {
                tittle?.let { putExtra("tittle", it) }
            })
            finish()
        }
    }

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

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

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

}