package com.base.datarecovery.activity

import android.graphics.Color
import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
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.ActivityPrivacySpaceBinding
import com.base.datarecovery.fragment.PrivacyPageFragment
import com.base.datarecovery.help.BaseActivity
import com.base.datarecovery.utils.BarUtils

class PrivacySpaceActivity : BaseActivity<ActivityPrivacySpaceBinding>() {

    override val binding: ActivityPrivacySpaceBinding by lazy {
        ActivityPrivacySpaceBinding.inflate(layoutInflater)
    }
    private val photosFragment: PrivacyPageFragment by lazy {
        PrivacyPageFragment("Photos")
    }

    private val videosFragment: PrivacyPageFragment by lazy {
        PrivacyPageFragment("Videos")
    }
    private val fragments by lazy {
        mutableListOf(photosFragment, videosFragment)
    }


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

        binding.viewpager2.run {
            adapter = object : FragmentStateAdapter(this@PrivacySpaceActivity) {
                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) {
                if (position == 0) {
                    binding.llPhotos.isSelected = true
                    binding.llVideos.isSelected = false
                } else {
                    binding.llVideos.isSelected = true
                    binding.llPhotos.isSelected = false
                }
            }
        })
    }

    override fun initListener() {
        super.initListener()

        binding.tvGoIt.setOnClickListener {
            binding.llUninstallTip.visibility = View.GONE
        }
        binding.llPhotos.setOnClickListener {
            binding.viewpager2.currentItem = 0
        }
        binding.llVideos.setOnClickListener {
            binding.viewpager2.currentItem = 1
        }

    }

}