package com.tools.device.devcheck.main

import android.view.LayoutInflater
import android.widget.ImageView
import androidx.core.view.isVisible
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayoutMediator
import com.tools.device.devcheck.base.BaseActivity
import com.tools.device.devcheck.R
import com.tools.device.devcheck.dashboard.BatteryFragment
import com.tools.device.devcheck.dashboard.CameraFragment
import com.tools.device.devcheck.dashboard.DashboardFragment
import com.tools.device.devcheck.dashboard.NetworkFragment
import com.tools.device.devcheck.dashboard.SystemShowFragment
import com.tools.device.devcheck.databinding.ActivityMainBinding

class MainActivity : BaseActivity<ActivityMainBinding>() {
    override fun inflateBinding(inflater: LayoutInflater): ActivityMainBinding =
        ActivityMainBinding.inflate(inflater)

    override fun initView() {
        super.initView()
        binding.run {

            val stringArray = resources.getStringArray(R.array.tab_title)
            TabLayoutMediator(tablelayout, viewpager3.apply {
                adapter = ViewPagerAdapter(
                    this@MainActivity, listOf(
                        DashboardFragment.newInstance(),
                        DashboardFragment.newInstance(),
                        SystemShowFragment.newInstance(),
                        BatteryFragment.newInstance(),
                        NetworkFragment.newInstance(),
                        DashboardFragment.newInstance(),
                        CameraFragment.newInstance(),
                        DashboardFragment.newInstance()
                    )
                )
                registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
                    override fun onPageSelected(position: Int) {
                        super.onPageSelected(position)

                    }
                })
            }) { tab, position ->
                tab.text = stringArray[position]
//                tab.setCustomView(R.layout.custom_tab)
//
//                tab.customView?.run {
//                    val indicator: ImageView = findViewById(R.id.image_indicator)
//                    indicator.isVisible = position == 0
//                }
            }.attach()
        }

    }

    override fun initData() {
        super.initData()
    }

}