package com.xty.server.act


import androidx.viewpager2.widget.ViewPager2
import com.alibaba.android.arouter.facade.annotation.Route
import com.androidkun.xtablayout.XTabLayout
import com.xty.base.act.IBaseAct
import com.xty.base.vp2.VpAdapter
import com.xty.common.arouter.ARouterUrl
import com.xty.server.R
import com.xty.server.databinding.ActMyAppointmentBinding
import com.xty.server.frag.HistoryFrag
import com.xty.server.frag.WattingFrag

/**
 * 我的预约
 */
@Route(path = ARouterUrl.MY_APPOINT)
class MyAppointmentAct: IBaseAct() {
    val binding by lazy{ActMyAppointmentBinding.inflate(layoutInflater)}
    val reportArray by lazy { resources.getStringArray(R.array.appointment_array) }
    val listFrag by lazy { listOf(WattingFrag.newInstance(2), WattingFrag.newInstance(3),
        WattingFrag.newInstance(4),WattingFrag.newInstance(7)) }
    override fun setLayout()=binding.root
    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mTvTitle.text=getString(R.string.my_appoint)
        binding.title.mIvBack.setOnClickListener { finish() }
        initTab()
        initVp2()
    }

    private fun initTab() {
        reportArray.forEach {
            var tab = binding.xTablayout.newTab()
            tab.text = it
            binding.xTablayout.addTab(tab)
        }
        binding.xTablayout.setOnTabSelectedListener(object : XTabLayout.OnTabSelectedListener{
            override fun onTabSelected(tab: XTabLayout.Tab?) {
                binding.mVp2.currentItem = tab!!.position
            }

            override fun onTabUnselected(tab: XTabLayout.Tab?) {
            }

            override fun onTabReselected(tab: XTabLayout.Tab?) {
            }

        })
    }

    private fun initVp2() {
        binding.mVp2.adapter= VpAdapter(listFrag, this)
        binding.mVp2.offscreenPageLimit = 2
        binding.mVp2.currentItem = 0
        binding.mVp2.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                binding.xTablayout.getTabAt(position)!!.select()
            }
        })
    }
}