package rowedto.jockeyedto.sheetedto.atticedto.allowedto
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.HemoglobinedtoBinding
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 Provideedto : Crossingedto<HemoglobinedtoBinding>() {

    override val binding: HemoglobinedtoBinding by lazy {
        HemoglobinedtoBinding.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@Provideedto, "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")
    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@Provideedto) {
            startActivity(Intent(this@Provideedto, Smokeedto::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
    }
}