package com.base.filerecoveryrecyclebin.fragment

import android.annotation.SuppressLint
import android.content.Intent
import android.view.View
import com.base.filerecoveryrecyclebin.R
import com.base.filerecoveryrecyclebin.activity.MainActivity
import com.base.filerecoveryrecyclebin.activity.guide.GuideActivity
import com.base.filerecoveryrecyclebin.activity.vip.VipActivity
import com.base.filerecoveryrecyclebin.ads.AdmobMaxHelper
import com.base.filerecoveryrecyclebin.bean.ConstObject.isGuide
import com.base.filerecoveryrecyclebin.bean.ConstObject.isInstallVip
import com.base.filerecoveryrecyclebin.databinding.FragmentGuideBinding
import com.base.filerecoveryrecyclebin.help.BaseFragment
import com.base.filerecoveryrecyclebin.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.yindaoye1)
            binding.tv0.text = "Effective recovery"
            binding.tvBtn.text = "Next"
            binding.flSkip.visibility = View.VISIBLE
        } else {
            binding.iv.setImageResource(R.mipmap.yindaoye2)
            binding.tv0.text = "Recycle Bin"
            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 {
                jumpNext()
            }
        }
        binding.flSkip.setOnClickListener {
            jumpNext()
        }
    }

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