package com.base.datarecovery.activity.guide

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.base.datarecovery.ads.admob.AdmobManager
import com.base.datarecovery.databinding.ActivityGuideBinding
import com.base.datarecovery.help.BaseActivity
import com.base.datarecovery.utils.BarUtils


class FirstGuestActivity : BaseActivity<ActivityGuideBinding>() {
    override val binding: ActivityGuideBinding by lazy {
        ActivityGuideBinding.inflate(layoutInflater)
    }
    private val page1: GuestFragment by lazy {
        GuestFragment().apply { page = 0 }
    }
    private val page2: GuestFragment by lazy {
        GuestFragment().apply { page = 1 }
    }
    private val adPage: AdFragment by lazy {
        AdFragment().apply { page = 2 }
    }
    private val page3: GuestFragment by lazy {
        GuestFragment().apply { page = 3 }
    }
    private val page4: GuestFragment by lazy {
        GuestFragment().apply { page = 4 }
    }
    private val fragments by lazy {
        mutableListOf(page1, page2, adPage, page3, page4)
    }


    override fun initView() {
        BarUtils.setStatusBarLightMode(this, true)
        if (!AdmobManager.checkNative()) {
            fragments.removeAt(2)
        }

        binding.idViewPager.run {
            adapter = object : FragmentStateAdapter(this@FirstGuestActivity) {
                override fun getItemCount(): Int {
                    return fragments.size
                }

                override fun createFragment(position: Int): Fragment {
                    return fragments[position]
                }
            }
        }
        binding.idViewPager.registerOnPageChangeCallback(object :
            ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
            }
        })

    }

    fun setPosition(position: Int) {
        binding.idViewPager.currentItem = position
    }
}