package com.base.datarecovery.fragment

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.base.datarecovery.R
import com.base.datarecovery.activity.MainActivity
import com.base.datarecovery.activity.guide.GuideActivity
import com.base.datarecovery.ads.AdmobMaxHelper
import com.base.datarecovery.bean.ConstObject.isGuide
import com.base.datarecovery.databinding.FragmentGuideBinding
import com.base.datarecovery.help.BaseFragment
import com.base.datarecovery.utils.AppPreferences

class GuideFragment constructor() : BaseFragment<FragmentGuideBinding>() {

    var page: Int = 1

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


    @SuppressLint("SetTextI18n")
    override fun setView() {
        if (page == 1) {
            binding.iv.setImageResource(R.mipmap.ydytu1)
            binding.tv0.text = "All Free"
            binding.tvBtn.text = "Next"
//            binding.flSkip.visibility = View.VISIBLE
        } else {
            binding.iv.setImageResource(R.mipmap.ydytu2)
            binding.tv0.text = "Effective recovery"
            binding.tvBtn.text = "Start"
//            binding.flSkip.visibility = View.GONE
        }
    }

    override fun setListener() {
        super.setListener()
        binding.tvBtn.setOnClickListener {
            if (page == 1) {
                (requireActivity() as GuideActivity).setPosition(1)
            } else {
                jumpMain()
            }
        }
        binding.flSkip.setOnClickListener {
            jumpMain()
        }
    }

    private fun jumpMain() {
        val showAd = AppPreferences.getInstance().getString("isShowGuideAd", "0")?.toInt()
        if (showAd == 1) {
            AdmobMaxHelper.admobMaxShowInterstitialAd(requireActivity(),false) {
                startActivity(Intent(requireContext(), MainActivity::class.java))
                requireActivity().finish()
                isGuide = true
            }
        } else {
            startActivity(Intent(requireContext(), MainActivity::class.java))
            requireActivity().finish()
            isGuide = true
        }
    }
}