package com.swiftcleaner.chovey.view.activity

import android.annotation.SuppressLint
import android.view.View
import androidx.core.view.isVisible
import com.swiftcleaner.chovey.R
import com.swiftcleaner.chovey.business.newAdmob.AdmobHelps
import com.swiftcleaner.chovey.databinding.FragmentGuideBinding
import com.swiftcleaner.chovey.view.BaseFragment

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() {

        when (page) {
            0 -> {
                if (AdmobHelps.isShowGuideAd()) {
                    AdmobHelps.showNativeAd(requireActivity(), binding.idFlNative, layout = R.layout.layout_ad_native_guide)
                }
                binding.ivGuide.setImageResource(R.mipmap.gudie_one)
                binding.ivGuideIndex.setImageResource(R.mipmap.icon1)
                binding.tvGuideContent.text = getString(R.string.fragment_gudie_one_text)
            }

            1 -> {
                binding.ivGuide.setImageResource(R.mipmap.gudie_two_img)
                binding.ivGuideIndex.setImageResource(R.mipmap.icon2)
                binding.tvGuideContent.text = getString(R.string.fragment_gudie_two_text)
                binding.tvSideNext.isVisible = true
            }

            3 -> {
                binding.ivGuide.setImageResource(R.mipmap.guide_three)
                binding.ivGuideIndex.setImageResource(R.mipmap.icon3)
                binding.tvGuideContent.text = getString(R.string.fragment_gudie_three_text)
                binding.tvFinishBtn.isVisible = true
                binding.tvBtn.visibility = View.INVISIBLE
                binding.idFlNative.visibility = View.INVISIBLE
            }
        }
    }

    override fun setListener() {
        super.setListener()
        binding.tvBtn.setOnClickListener {
            val activity = requireActivity() as GuideActivity?
            activity ?: requireActivity()
            activity?.next()
        }
        binding.tvFinishBtn.setOnClickListener {
            val activity = requireActivity() as GuideActivity?
            activity ?: requireActivity()
            activity?.next()
        }
    }

//    override fun onResume() {
//        super.onResume()
//        if (AdmobHelps.isShowGuideAd() && page == 0) {
//            kotlin.runCatching {
//                AdmobHelps.admobMaxShowNativeAd(requireActivity(), binding.idFlNative, 4)
//            }
//        }
//
//    }

}