package com.base.datarecovery.activity.guide

import android.annotation.SuppressLint
import android.content.Intent
import android.view.View
import androidx.core.view.isVisible
import com.base.datarecovery.R
import com.base.datarecovery.activity.MainActivity
import com.base.datarecovery.ads.admob.AdmobManager
import com.base.datarecovery.bean.ConstObject
import com.base.datarecovery.databinding.FragmentGuestBinding
import com.base.datarecovery.help.BaseFragment


class GuestFragment : BaseFragment<FragmentGuestBinding>() {

    var page: Int = 0

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

    @SuppressLint("SetTextI18n")
    override fun setView() {
        if (page == 0) {
            binding.idFlNative.visibility = View.VISIBLE
            AdmobManager.showNativeAd(
                requireActivity(),
                binding.idFlNative
            )
        } else {
            binding.idFlNative.visibility = View.INVISIBLE
        }
        binding.root.postDelayed({
            binding.idTvSkip.isVisible = true
        }, 2000)
        when (page) {
            0 -> {
                binding.idImg01.setImageResource(R.mipmap.jindu1)
                binding.idImg02.setImageResource(R.mipmap.yuan1)
                binding.idImg03.setImageResource(R.mipmap.yuan1)
                binding.idImg04.setImageResource(R.mipmap.yuan1)
                binding.iv.setImageResource(R.mipmap.yindao1)
                binding.idTrip1.text = "Bring Your Memories Back"
                binding.idTrip2.text = "Recover Deleted Photos and Videos"
            }

            1 -> {
                binding.iv.setImageResource(R.mipmap.yindao2)
                binding.idTrip1.text = "Fast Recovery, No Stress"
                binding.idTrip2.text = "Quickly scan and restore your files with afew taps"
                binding.idImg01.setImageResource(R.mipmap.yuan1)
                binding.idImg02.setImageResource(R.mipmap.jindu1)
                binding.idImg03.setImageResource(R.mipmap.yuan1)
                binding.idImg04.setImageResource(R.mipmap.yuan1)
            }

            2 -> {
                binding.iv.setImageResource(R.mipmap.yindao3)
                binding.idTrip1.text = "Everything You Need,Recovered"
                binding.idTrip2.text =
                    "Search, preview, and recover various other files-all in one place"
                binding.idImg01.setImageResource(R.mipmap.yuan1)
                binding.idImg02.setImageResource(R.mipmap.yuan1)
                binding.idImg03.setImageResource(R.mipmap.jindu1)
                binding.idImg04.setImageResource(R.mipmap.yuan1)
            }

            3 -> {
                binding.iv.setImageResource(R.mipmap.yindao3)
                binding.idTrip1.text = "Everything You Need,Recovered"
                binding.idTrip2.text =
                    "Search, preview, and recover various other files-all in one place"
                binding.idImg01.setImageResource(R.mipmap.yuan1)
                binding.idImg02.setImageResource(R.mipmap.yuan1)
                binding.idImg03.setImageResource(R.mipmap.jindu1)
                binding.idImg04.setImageResource(R.mipmap.yuan1)
            }

            4 -> {
                binding.iv.setImageResource(R.mipmap.yindao4)
                binding.idTrip1.text = "All-in-One Solution"
                binding.idTrip2.text = "Recover, manage, and organize your files—all in one intuitive interface."
                binding.idImg01.setImageResource(R.mipmap.yuan1)
                binding.idImg02.setImageResource(R.mipmap.yuan1)
                binding.idImg03.setImageResource(R.mipmap.yuan1)
                binding.idImg04.setImageResource(R.mipmap.jindu1)
            }
        }
        binding.idTvNext.setOnClickListener {
            if (page == 0) {
                (requireActivity() as FirstGuestActivity).setPosition(1)
            } else if (page == 1) {
                (requireActivity() as FirstGuestActivity).setPosition(2)
            } else if (page == 2) {
                (requireActivity() as FirstGuestActivity).setPosition(3)
            } else if (page == 3) {
                (requireActivity() as FirstGuestActivity).setPosition(4)
            } else {
                jumpNext()
            }
        }
        binding.idTvSkip.setOnClickListener {
            jumpNext()
        }

    }

    private fun jumpNext() {
        ConstObject.isGuide = true
        (requireActivity() as FirstGuestActivity).admobMaxShowInterstitialAd {
            startActivity(Intent(requireContext(), MainActivity::class.java))
        }
//        val showAd = SPUtils.getInstance().getString("isShowGuideAd", "0")?.toInt()
//        if (showAd == 1) {
//
//        } else {
//            if (!ConfigHelper.ifGuest) {
//                startActivity(Intent(requireContext(), DeviceScanActivity::class.java))
//                requireActivity().finish()
//            }else{
//                startActivity(Intent(requireContext(), MainActivity::class.java))
//            }
//        }
    }
}