package com.base.filerecoveryrecyclebin.activity.guide

import android.content.Intent
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.filerecoveryrecyclebin.R
import com.base.filerecoveryrecyclebin.ads.AdmobMaxHelper
import com.base.filerecoveryrecyclebin.databinding.ActivityGuideBinding
import com.base.filerecoveryrecyclebin.fragment.GuideFragment
import com.base.filerecoveryrecyclebin.help.BaseActivity
import com.base.filerecoveryrecyclebin.help.PermissionHelp.requestStorePermission
import com.base.filerecoveryrecyclebin.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().apply { page = 1 }
    }
    private val page2: GuideFragment by lazy {
        GuideFragment().apply { page = 2 }
    }
    private val page3: GuideFragment by lazy {
        GuideFragment().apply { page = 3 }
    }
    private val fragments by lazy {
        mutableListOf(page1, page2, page3)
    }


    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)
        AdmobMaxHelper.admobMaxShowNativeAd(this, binding.idFlNative)
        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)
    }

    fun lauchPermisson() {
        startActivity(Intent(this, CleanGuideActivity::class.java))
        finish()
        requestStorePermission(launcher) {
        }
    }

}