package com.base.scanqr.ui.guide

import android.content.Intent
import com.base.scanqr.R
import com.base.scanqr.ads.AdsMgr
import com.base.scanqr.base.BaseFragment
import com.base.scanqr.databinding.FragmentGuideBinding
import com.base.scanqr.ui.main.MainActivity

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

    private var pageIndex = 0

    constructor(pageIndex: Int) : this() {
        this.pageIndex = pageIndex
    }

    override fun initView() {
        super.initView()
        when (pageIndex) {
            0 -> {
                binding.iv.setImageResource(R.mipmap.yindaoye1)
                binding.tvTitle.text = this.resources.getString(R.string.scan_barcode_qr_code)
                binding.tvDesc.text = this.resources.getString(R.string.guide_1)
            }

            1 -> {
                binding.iv.setImageResource(R.mipmap.yindaoye2)
                binding.tvTitle.text = getString(R.string.quickly_scan_products)
                binding.tvDesc.text = getString(R.string.guide_2)
            }

            2 -> {
                binding.iv.setImageResource(R.mipmap.yindaoye3)
                binding.tvTitle.text = getString(R.string.create_share_qr_code)
                binding.tvDesc.text = getString(R.string.guide_3)

                binding.tvBtn.text = getString(R.string.complete)
            }
        }
    }

    override fun onResumeOneShoot() {
        super.onResumeOneShoot()
        AdsMgr.showNative(binding.flAd, R.layout.layout_admob_app_exit)
    }

    override fun initListener() {
        super.initListener()
        binding.tvBtn.setOnClickListener {
            if (pageIndex == 2) {
                completeAction()
            } else {
                val activity = requireActivity() as GuideActivity?
                activity?.nextPage()
            }
        }
    }

    private fun completeAction() {
        val activity = requireActivity() as GuideActivity?
        activity?.startActivity(Intent(activity, MainActivity::class.java))
        activity?.finish()
    }

}