package com.base.datarecovery.activity.guide

import android.graphics.Color
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.base.datarecovery.R
import com.base.datarecovery.databinding.ActivityGuideBinding
import com.base.datarecovery.fragment.GuideFragment
import com.base.datarecovery.help.BaseActivity
import com.base.datarecovery.utils.BarUtils
import com.zhpan.indicator.enums.IndicatorSlideMode
import com.zhpan.indicator.enums.IndicatorStyle

class GuideActivity : BaseActivity<ActivityGuideBinding>() {

    private val page1: GuideFragment by lazy {
        GuideFragment(1)
    }
    private val page2: GuideFragment by lazy {
        GuideFragment(2)
    }
    private val fragments by lazy {
        mutableListOf(page1, page2)
    }


    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) {
            }
        })

        val normalColor = ContextCompat.getColor(this, R.color.color_cccccc)
        val selectedColor = ContextCompat.getColor(this, R.color.color_4f86eb)
        binding.indicatorView
            .setSliderColor(normalColor, selectedColor)
            .setSliderWidth(resources.getDimension(R.dimen.dp_9))
            .setSliderHeight(resources.getDimension(R.dimen.dp_9))
            .setSlideMode(IndicatorSlideMode.WORM)
            .setIndicatorStyle(IndicatorStyle.CIRCLE)
            .setupWithViewPager(binding.viewpager2)
    }

}