package foamyic

import Cycloneic
import android.content.Intent
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import tooic.fatalityic.jittersic.Reinstateic
import tooic.fatalityic.corroborateic.indexic.Lurkic
import com.easy.clean.databinding.VanquishicBinding
import waific.Teflonic.therapistic.Hauntingic

class Onlyic : Reinstateic<VanquishicBinding>(VanquishicBinding::inflate) {

    private val page1: Backpackic by lazy {
        Backpackic().apply { page = 0 }
    }
    private val page2: Backpackic by lazy {
        Backpackic().apply { page = 1 }
    }
    private val pageNative: Cycloneic by lazy {
        Cycloneic()
    }

    private val page3: Backpackic by lazy {
        Backpackic().apply { page = 3 }
    }
    private val fragments: MutableList<Fragment> by lazy {
        mutableListOf(page1, page2, page3)
    }

    private var currentIndex = 0

    override fun initView() {
        super.initView()
        if (Lurkic.adsConfigBean.fullNativeShow && Lurkic.adsConfigBean.isAdShow) {
            fragments.add(2, pageNative)
        }

        binding.czaric.run {
            offscreenPageLimit = 4
            adapter = object : FragmentStateAdapter(this@Onlyic) {
                override fun getItemCount(): Int {
                    return fragments.size
                }

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


    fun next(page: Int) {

        if (page == 0) {
            binding.czaric.currentItem = 1
            return
        }

        if (page == 1) {
            binding.czaric.currentItem = 2
            return
        }
        if (page == 3) {
            startActivity(Intent(this, Hauntingic::class.java))
            finish()
        }
    }
}