package rowedto.jockeyedto.sheetedto.atticedto.salonedto.safetyedto.makeupedto

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.CorrectionedtoBinding
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 Massedto : Crossingedto<CorrectionedtoBinding>() {

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

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

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

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

    @SuppressLint("SetTextI18n")
    private fun jumpJob() = lifecycleScope.launch(Dispatchers.Main) {
        delay(Random.nextLong(4000, 6000))
        binding.giftedto.visibility = View.GONE
        binding.innovationedto.visibility = View.VISIBLE
        binding.innovationedto.playAnimation()
        binding.lightedto.text = "Completed!"
        delay(1000)

        Scandaledto.admobMaxShowInterstitialAd(this@Massedto) {
            startActivity(Intent(this@Massedto, Conceiveedto::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
    }
}