package com.hongyegroup.cpt_business.ui.fragment

import com.guadou.cs_cptservices.base.fragment.YYBaseVDBFragment
import com.guadou.lib_baselib.bean.DataBindingConfig
import com.guadou.lib_baselib.ext.vertical
import com.guadou.lib_baselib.view.titlebar.EasyUtil
import com.hongyegroup.cpt_business.BR
import com.hongyegroup.cpt_business.R
import com.hongyegroup.cpt_business.databinding.FragmentBusinessAppointmentBinding
import com.hongyegroup.cpt_business.mvvm.vm.BusinessAppointmentViewModel
import com.hongyegroup.cpt_business.ui.activity.BusinessAppointmentDateActivity
import com.hongyegroup.cpt_business.ui.activity.BusinessAppointmentMakeActivity


/**
 * 公司用户 首页第二个Tab
 * 公司下面全部的预约列表 按时间日期计数
 */
class BusinessAppointmentFragment : YYBaseVDBFragment<BusinessAppointmentViewModel, FragmentBusinessAppointmentBinding>() {

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.fragment_business_appointment)
            .addBindingParams(BR.click, ClickProxy())
    }

    override fun startObserve() {

    }

    override fun init() {
        //状态栏高度动态设置
        mBinding.statusPaddingView.layoutParams = mBinding.statusPaddingView.layoutParams.apply {
            height = EasyUtil.getStateBarHeight(context)
        }

        initRV()
        initData()
        initListener()
    }

    private fun initData() {

        for (i in 1..10) {
            mViewModel.mDatas.add(i.toString())
        }

        mViewModel.mAdapter.notifyDataSetChanged()

    }

    private fun initListener() {

        mViewModel.mAdapter.setOnItemClickListener { _, _, position ->
            val item = mViewModel.mDatas[position]
            BusinessAppointmentDateActivity.startInstance()
        }
    }

    private fun initRV() {

        mBinding.recyclerView.vertical().adapter = mViewModel.mAdapter

    }

    fun scrollTopRefresh() {

    }

    /**
     * DataBinding事件处理
     */
    inner class ClickProxy {

        //去預約頁面
        fun gotoMakeAppointmentPage() {
            BusinessAppointmentMakeActivity.startInstance()
        }

    }

}