package com.ritoq.quickphone.ui.guide

import android.annotation.SuppressLint
import android.content.Intent
import com.ritoq.quickphone.R
import com.ritoq.quickphone.base.BaseFragment
import com.ritoq.quickphone.business.ads.AdsMgr
import com.ritoq.quickphone.business.ads.AdsShowCallBack
import com.ritoq.quickphone.databinding.FragmentGuideBinding
import com.ritoq.quickphone.ui.main.MainActivity

class GuideFragment : BaseFragment<FragmentGuideBinding>(FragmentGuideBinding::inflate) {
    var page: Int = 1


    @SuppressLint("SetTextI18n")
    override fun initView() {
        super.initView()

        when (page) {
            0 -> {
                binding.iv.setImageResource(R.drawable.yindaoye1)
                binding.ivDian.setImageResource(R.drawable.dian_1)
                binding.tvContent.text = getString(R.string.guide_tip_1)
            }

            1 -> {
                binding.iv.setImageResource(R.drawable.yindaoye2)
                binding.ivDian.setImageResource(R.drawable.dian_2)
                binding.tvContent.text = getString(R.string.guide_tip_2)
            }

            3 -> {
                binding.iv.setImageResource(R.drawable.yindaoye3)
                binding.ivDian.setImageResource(R.drawable.dian_3)
                binding.tvContent.text = getString(R.string.guide_tip_3)
                binding.tvBtn.text = getString(R.string.get_started)
            }
        }

    }

    override fun initListener() {
        super.initListener()
        binding.tvSkip.setOnClickListener {

            AdsMgr.showInsert(requireActivity(), showCallBack = object : AdsShowCallBack() {
                override fun next() {
                    val activity = requireActivity() as GuideActivity
                    activity.startActivity(Intent(activity, MainActivity::class.java))
                    activity.finish()
                }
            })

        }
        binding.tvBtn.setOnClickListener {
            val activity = requireActivity() as GuideActivity?
            activity ?: requireActivity()
            activity?.next(page)
        }
    }


    override fun onResume() {
        super.onResume()

        if (!binding.flAd.isAdShowed) {
            AdsMgr.showNative(binding.flAd, R.layout.layout_admob_native_custom)
        }
    }
}