package com.base.filerecoveryrecyclebin.fragment

import android.annotation.SuppressLint
import android.content.Intent
import com.base.filerecoveryrecyclebin.R
import com.base.filerecoveryrecyclebin.activity.MainActivity
import com.base.filerecoveryrecyclebin.activity.guide.GuideActivity
import com.base.filerecoveryrecyclebin.ads.AdmobMaxHelper
import com.base.filerecoveryrecyclebin.databinding.FragmentGuideBinding
import com.base.filerecoveryrecyclebin.help.BaseFragment
import com.base.filerecoveryrecyclebin.utils.AppPreferences
import com.base.filerecoveryrecyclebin.utils.LogEx

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

    private val TAG = "GuideFragment"

    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"
        } 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()
            }
        }
    }

    private fun jumpNext() {
        if (false) {
//            startActivity(Intent(requireContext(), VipActivity::class.java).apply {
//                putExtra("isSkip", true)
//            })
//            requireActivity().finish()
//            isInstallVip = false
        } else {
            val showAd = AppPreferences.getInstance().getString("isShowGuideAd", "0")?.toInt()
            LogEx.logDebug(TAG, "showAd=$showAd")
            if (showAd == 1) {
                AdmobMaxHelper.admobMaxShowInterstitialAd(requireActivity(), isLoading = false) {
                    startActivity(Intent(requireContext(), MainActivity::class.java))
                    requireActivity().finish()
                }
            } else {
                startActivity(Intent(requireContext(), MainActivity::class.java))
                requireActivity().finish()
            }
        }
    }
}