package com.zj365.mime.act

import android.os.Bundle
import android.util.Log
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.zj365.mime.R
import com.zj365.mime.databinding.ActSportDetailBinding
import com.zj365.mime.fragment.SportDetailProgrammeFrag
import com.zj365.mime.fragment.SportDetailResultFrag

/**
*  运动方案详情
*/
@Route(path = ARouterUrl.SPORT_DETAIL)
class SportDetailAct  : IBaseAct() {
    val listFrag= listOf(SportDetailProgrammeFrag(), SportDetailResultFrag())
    val binding by lazy { ActSportDetailBinding.inflate(layoutInflater) }
    var userId = ""
    var id = ""
    override fun setLayout() = binding.root
    override fun initData() {
        super.initData()
        userId = intent.extras!!.getString("userId").toString()
        id = intent.extras!!.getString("id").toString()
    }

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mIvBack.setOnClickListener { finish() }
        binding.title.mTvTitle.text = getString(R.string.sport_detail)


        var titleArray = resources.getStringArray(R.array.sport_detail)
        titleArray.forEach {
            var tab = binding.xTablayout.newTab()
            tab.text = it
            binding.xTablayout.addTab(tab)
        }


        listFrag.forEach {
            var bundle = Bundle()
            bundle.putString("userId", userId)
            bundle.putString("id", id)
            it.arguments = bundle
        }
        binding.mVp2.adapter = VpAdapter(listFrag, this)
        binding.mVp2.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                binding.xTablayout.getTabAt(position)!!.select()
            }
        })
        binding.xTablayout.setOnTabSelectedListener(object : XTabLayout.OnTabSelectedListener {
            override fun onTabSelected(tab: XTabLayout.Tab?) {
                binding.mVp2.setCurrentItem(tab!!.position, false)
                Log.e("TAG", "tab: " + tab!!.position)
            }

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

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

        })

    }
    fun toResultPage(){
        binding.mVp2.setCurrentItem(1, true)
    }

}

