package rowedto.jockeyedto.sheetedto.atticedto.openedto.postedto

import android.annotation.SuppressLint
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.BelledtoBinding
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 Killeredto : Crossingedto<BelledtoBinding>() {


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

    private var job: Job? = null
    override fun initView() {
        Scandaledto.admobMaxShowNativeAd(this,binding.tooledto,1)
        playLottie()

    }

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

    @SuppressLint("SetTextI18n")
    private fun playLottie() {
        binding.giftedto.imageAssetsFolder = "junk_scan/images/"
        binding.giftedto.setAnimation("junk_scan/data.json")
        binding.giftedto.playAnimation()
    }

    @SuppressLint("SetTextI18n")
    fun jumpJob() = lifecycleScope.launch {
        delay(Random.nextLong(3500, 4500))
        binding.giftedto.cancelAnimation()
        binding.giftedto.visibility = View.GONE
        binding.innovationedto.visibility = View.VISIBLE
        binding.innovationedto.playAnimation()
        binding.lightedto.text = "Completed!"
        delay(1000)
        Scandaledto.admobMaxShowInterstitialAd(this@Killeredto) {
            startActivity(Intent(this@Killeredto, Chestedto::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
    }

}