package rallyedto.finishedto.cableedto

import android.content.Intent
import android.widget.Toast
import androidx.activity.addCallback
import androidx.lifecycle.lifecycleScope
import com.base.datarecovery.databinding.BuffetedtoBinding
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import rallyedto.battleedto.acresedto.Lemonedto
import rallyedto.sunedto.tumouredto.majorityedto.loseedto.Togetheredto
import kotlin.random.Random

class Merchantedto : Lemonedto<BuffetedtoBinding>() {

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

    override fun initView() {
        Togetheredto.showNativeAd(this,binding.jeweledto, isShowAdNative = Togetheredto.isShowAdNativeBottom())
    }

    fun jumpJob() = lifecycleScope.launch {
        delay(Random.nextLong(3000, 4500))
        admobMaxShowInterstitialAd {
            startActivity(Intent(this@Merchantedto, Freckleedto::class.java))
            finish()
        }
    }

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

}