package com.yzx.escreen.activity


import androidx.viewpager2.widget.ViewPager2
import com.blankj.utilcode.util.KeyboardUtils
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener
import com.yzx.escreen.HomePagerAdapter
import com.yzx.escreen.R
import com.yzx.escreen.activity.base.BaseActivity
import com.yzx.escreen.model.LeaveID
import com.yzx.escreen.model.TabEntity
import com.yzx.escreen.presenter.MainPresenter
import com.yzx.escreen.presenter.MainView
import kotlinx.android.synthetic.main.activity_test.tabLayout
import kotlinx.android.synthetic.main.activity_test.viewPager2

class TestActivity : BaseActivity<MainPresenter>(), MainView {
    override val inflateId: Int
        get() = R.layout.activity_test

    override fun initView() {
        val tabData = arrayListOf<CustomTabEntity>()
        tabData.add(TabEntity("学生请假", R.mipmap.leave_select, R.mipmap.leave_unselect))
        tabData.add(TabEntity("学籍异动", R.mipmap.change_select, R.mipmap.change_unselect))
        tabData.add(TabEntity("访客管理", R.mipmap.visitor_select, R.mipmap.visitor_unselect))
        tabData.add(TabEntity("我的", R.mipmap.my_select, R.mipmap.my_unselect))
        tabLayout.setTabData(tabData)

        viewPager2.adapter = HomePagerAdapter(this)
        viewPager2.offscreenPageLimit = 3
        viewPager2.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                tabLayout.currentTab = position
            }
        })
        tabLayout.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
//                viewPager2.currentItem = position
                viewPager2.setCurrentItem(position, false)
                KeyboardUtils.hideSoftInput(viewPager2)
            }

            override fun onTabReselect(position: Int) {
            }

        })
    }

    override fun initData() {

    }

    override fun initPresenter(): MainPresenter=MainPresenter(this)


    override fun onLeaveIDsSuccess(list: MutableList<LeaveID>) {

    }

    override fun onLeaveIDsError() {

    }
}