package importantedto.appliededto.surgeonedto.promiseedto.produceredto.motionedto.momentumedto

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

class Collectionedto : Murderedto<CreededtoBinding>() {

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


    }

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

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

    override fun initListener() {
        super.initListener()
        onBackPressedDispatcher.addCallback {
            Toast.makeText(this@Collectionedto, "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
    }

}