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.toast
import com.guadou.lib_baselib.ext.vertical
import com.guadou.lib_baselib.utils.KeyboardUtils
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.FragmentBusinessEmployeesBinding
import com.hongyegroup.cpt_business.mvvm.vm.BusinessEmployeesViewModel
import com.hongyegroup.cpt_business.ui.activity.BusinessAddStaffActivity

/**
 * 公司用户 首页第一个Tab
 * 公司旗下全部员工列表
 */
class BusinessEmployeesFragment : YYBaseVDBFragment<BusinessEmployeesViewModel, FragmentBusinessEmployeesBinding>() {

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.fragment_business_employees)
            .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.addChildClickViewIds(R.id.btn_edit_employee)
        mViewModel.mAdapter.setOnItemChildClickListener { _, _, position ->
            val item = mViewModel.mDatas[position]
            BusinessAddStaffActivity.startInstance()
        }
    }

    private fun initRV() {

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

    }

    fun scrollTopRefresh() {

    }

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

        //执行搜索
        fun doSearch() {
            KeyboardUtils.hideSoftInput(mActivity)

            val searchText = mViewModel.mKeywordLiveData.value

            toast("Search:$searchText")

        }

        //搜索的删除
        fun searchDel() {
            mViewModel.mKeywordLiveData.value = ""
        }

    }

}