package com.base.filerecoveryrecyclebin.fragment

import android.annotation.SuppressLint
import android.content.Intent
import androidx.core.view.isVisible
import com.base.filerecoveryrecyclebin.R
import com.base.filerecoveryrecyclebin.activity.MainActivity
import com.base.filerecoveryrecyclebin.activity.guide.CleanGuideActivity
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

class GuideFragment : 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 = "Deleted precious photos or important\n" +
                    "filesbyaccident?Regret kicks in."
            binding.tvBtn.text = "Next"
        } else if (page == 2) {
            binding.iv.setImageResource(R.mipmap.yindaoye2)
            binding.tv0.text = "Don't leave any regrets! Our APP\n" +
                    "can accurately retrieve the files\n" +
                    "you've accidentally deleted."
            binding.tvBtn.text = "Next"
//            binding.flSkip.visibility = View.GONE
        } else {
            binding.iv.isVisible = false
            binding.tv0.isVisible = false
            binding.idLl111.isVisible = true
            binding.tvBtn.text = "Next"
        }
    }

    override fun setListener() {
        super.setListener()
        binding.tvBtn.setOnClickListener {
            if (page == 1) {
                (requireActivity() as GuideActivity).setPosition(1)
            } else if (page == 2) {
                (requireActivity() as GuideActivity).setPosition(2)
            } else {
                (requireActivity() as GuideActivity).lauchPermisson()
            }
        }
        binding.idTvAllow.setOnClickListener {
            (requireActivity() as GuideActivity).lauchPermisson()
        }
        binding.idTvNotAllow.setOnClickListener {
            startActivity(Intent(requireContext(), MainActivity::class.java))
            requireActivity().finish()
        }
    }

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