package com.base.filerecoveryrecyclebin.activity.guide

import android.content.Intent
import android.graphics.Color
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.base.filerecoveryrecyclebin.databinding.ActivityGuideBinding
import com.base.filerecoveryrecyclebin.fragment.GuideFragment
import com.base.filerecoveryrecyclebin.help.BaseActivity
import com.base.filerecoveryrecyclebin.utils.BarUtils

class GuideActivity : BaseActivity<ActivityGuideBinding>() {

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

    private val page3: GuideFragment by lazy {
        GuideFragment().apply { page = 3 }
    }
    private val fragments by lazy {
        mutableListOf(page1, page2, pageNative, page3)
    }

    private var currentIndex = 0


    override val binding: ActivityGuideBinding by lazy {
        ActivityGuideBinding.inflate(layoutInflater)
    }

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


    override fun initView() {
        BarUtils.setStatusBarLightMode(this, true)
        BarUtils.setStatusBarColor(this, Color.TRANSPARENT)

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

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

    fun next(page: Int) {

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

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


}