package com.tgv.malware.ui.guide

import android.annotation.SuppressLint
import android.content.Intent
import com.tgv.malware.R
import com.tgv.malware.base.BaseFragment
import com.tgv.malware.business.ads.AdsMgr
import com.tgv.malware.business.ads.AdsShowCallBack
import com.tgv.malware.databinding.FragmentGuideBinding
import com.tgv.malware.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.tvTitle.text = getString(R.string.guide_title_1)
                binding.tvContent.text = getString(R.string.guide_tip_1)
            }

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

            3 -> {
                binding.iv.setImageResource(R.drawable.yingdaoye3)
                binding.ivDian.setImageResource(R.drawable.dian_3)
                binding.tvTitle.text = getString(R.string.guide_title_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)
        }
    }
}