package rowedto.jockeyedto.sheetedto.atticedto.equipmentedto.exactedto.costumeedto

import android.animation.ValueAnimator
import android.content.Intent
import android.graphics.Color
import android.view.animation.LinearInterpolator
import android.widget.Toast
import androidx.activity.addCallback
import androidx.lifecycle.lifecycleScope
import com.base.datarecovery.databinding.EyeedtoBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import rowedto.jockeyedto.sheetedto.knewedto.economicedto.copyrightedto.Crossingedto
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Spareedto
import rowedto.jockeyedto.sheetedto.strangeedto.pyramidedto.particlesedto.Scandaledto
import kotlin.random.Random

class Swimmingedto : Crossingedto<EyeedtoBinding>() {
    override val binding: EyeedtoBinding by lazy {
        EyeedtoBinding.inflate(layoutInflater)
    }

    override fun initView() {
        Spareedto.setStatusBarLightMode(this,false)
        Spareedto.setStatusBarColor(this, Color.TRANSPARENT)
        Scandaledto.admobMaxShowNativeAd(this,binding.tooledto,1)
        ValueAnimator.ofFloat(0f, 360f).apply {
            duration = 1100
            repeatMode = ValueAnimator.RESTART
            repeatCount = ValueAnimator.INFINITE
            interpolator = LinearInterpolator()
            addUpdateListener { binding.motifedto.rotation = it.animatedValue as Float }
            start()
        }
    }
    override fun initListener() {
        onBackPressedDispatcher.addCallback {
            Toast.makeText(this@Swimmingedto, "wait a moment", Toast.LENGTH_SHORT).show()
        }
    }
    private var isPasue = false
    override fun onPause() {
        super.onPause()
        isPasue = false

    }

    override fun onResume() {
        super.onResume()
        isPasue = true
        playAnimal()
    }
    private fun playAnimal() {
        lifecycleScope.launch(Dispatchers.Main) {
            binding.root.postDelayed({
                animaEnd()
            }, Random.nextLong(3000, 5000))
        }
    }
    private fun animaEnd(){
        if (isPasue) {
            Scandaledto.admobMaxShowInterstitialAd(this){
                startActivity(Intent(this, Metaledto::class.java).apply {
                    putExtra("url", "https://www.horoscope.com/us/index.aspx")
                })
                finish()
            }
        }
    }
}
