package rowedto.jockeyedto.sheetedto.atticedto.jobedto.basinedto.civilianedto

import android.content.Intent
import android.widget.Toast
import androidx.activity.addCallback
import androidx.lifecycle.lifecycleScope
import com.base.datarecovery.databinding.RoyaltyedtoBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import rowedto.jockeyedto.sheetedto.knewedto.economicedto.copyrightedto.Crossingedto
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Ecstasyedto
import rowedto.jockeyedto.sheetedto.strangeedto.pyramidedto.particlesedto.Scandaledto
import kotlin.random.Random

class Searchedto : Crossingedto<RoyaltyedtoBinding>() {

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

    private var job: Job? = null

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

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

//    fun jumpJob() = lifecycleScope.launch {
//        delay(Random.nextLong(3000, 4500))
//        Scandaledto.admobMaxShowInterstitialAd(this@Searchedto) {
//            startActivity(Intent(this@Searchedto, Quarteredto::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
//    }

    private var isPasue = false
    override fun onPause() {
        super.onPause()
        isPasue = false

    }

    override fun onResume() {
        super.onResume()
        isPasue = true
        playAnimal()
    }
    private fun playAnimal() {
        lifecycleScope.launch(Dispatchers.Main) {
            binding.root.postDelayed({
                Ecstasyedto.getImageFiles {
                    animaEnd()
                }

            }, Random.nextLong(500, 1000))
        }
    }
    private fun animaEnd(){
        if (isPasue) {

            Scandaledto.admobMaxShowInterstitialAd(this){
                startActivity(Intent(this, Tossedto::class.java))
                finish()
            }
        }
    }
}