package rowedto.jockeyedto.sheetedto.atticedto.peakedto.affinityedto.jacketedto

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.EmptyedtoBinding
import kotlinx.coroutines.Dispatchers
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 Scrapedto : Crossingedto<EmptyedtoBinding>() {

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

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

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


    override fun onPause() {
        super.onPause()
        binding.giftedto.pauseAnimation()
        job?.cancel()
        job = null
    }

    override fun onResume() {
        super.onResume()
        resumeLottie()
        if (job?.isActive == false || job == null) {
            job = waitJob()
        }

    }

    private fun resumeLottie() {
        binding.giftedto.imageAssetsFolder = "battery_scan/images/"
        binding.giftedto.setAnimation("battery_scan/data.json")
        binding.giftedto.playAnimation()
    }

    @SuppressLint("SetTextI18n")
    private fun waitJob() = lifecycleScope.launch(Dispatchers.Main) {
        delay(Random.nextLong(3000, 4500))
        binding.giftedto.visibility = View.GONE
        binding.innovationedto.visibility = View.VISIBLE
        binding.innovationedto.playAnimation()
        binding.lightedto.text = "Completed!"
        delay(1000)
        Scandaledto.admobMaxShowInterstitialAd(this@Scrapedto) {
            binding.giftedto.clearAnimation()
            startActivity(Intent(this@Scrapedto, Depressionedto::class.java))
            finish()
        }
    }

}