package importantedto.appliededto.surgeonedto.promiseedto.wonderedto

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.AdministrationedtoBinding
import importantedto.admireedto.sweptedto.Differenceedto
import importantedto.afteredto.constitutionaledto.Murderedto
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.random.Random

class Tiptoeedto : Murderedto<AdministrationedtoBinding>() {


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

    private var job: Job? = null
    override fun initView() {
        playLottie()
    }

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

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

    @SuppressLint("SetTextI18n")
    fun jumpJob() = lifecycleScope.launch {
        delay(Random.nextLong(3500, 4500))
        binding.senioredto.cancelAnimation()
        binding.senioredto.visibility = View.GONE
        binding.eternaledto.visibility = View.VISIBLE
        binding.eternaledto.playAnimation()
        binding.lickedto.text = "Completed!"
        delay(1000)
        Differenceedto.admobMaxShowInterstitialAd(this@Tiptoeedto) {
            startActivity(Intent(this@Tiptoeedto, Contraryedto::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
    }

}