package com.hongyegroup.cpt_ewallet.ui

import android.os.Bundle
import com.guadou.cs_cptservices.base.activity.YYBaseVDBActivity
import com.guadou.lib_baselib.bean.DataBindingConfig
import com.guadou.lib_baselib.ext.commContext
import com.guadou.lib_baselib.ext.gotoActivity
import com.guadou.lib_baselib.ext.vertical
import com.hongyegroup.cpt_ewallet.BR
import com.hongyegroup.cpt_ewallet.R
import com.hongyegroup.cpt_ewallet.databinding.ActivityMonthlyInvoiceBinding
import com.hongyegroup.cpt_ewallet.mvvm.MonthlyInvoiceViewModel
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.scwang.smart.refresh.layout.listener.OnRefreshListener
import dagger.hilt.android.AndroidEntryPoint

/**
 * 月度的发票账单
 */
@AndroidEntryPoint
class MonthlyInvoiceActivity : YYBaseVDBActivity<MonthlyInvoiceViewModel, ActivityMonthlyInvoiceBinding>(), OnRefreshListener {

    companion object {
        fun startInstance() {
            commContext().gotoActivity<MonthlyInvoiceActivity>()
        }
    }

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.activity_monthly_invoice, BR.viewModel, mViewModel)
    }

    override fun startObserve() {

    }

    override fun init(savedInstanceState: Bundle?) {
        setStatusBarBlackText()

        initRV()
        initData()
        initListener()
    }

    private fun initData() {
        mViewModel.getInvoiceList().observe(this) {
            mBinding.refreshLayout.finishRefresh()
        }
    }

    private fun initListener() {
        mViewModel.mAdapter.loadMoreModule.isEnableLoadMore = false

        //刷新控件初始化
        mBinding.refreshLayout.setEnableNestedScroll(true)
        mBinding.refreshLayout.setEnableLoadMore(false)
        mBinding.refreshLayout.setEnableRefresh(true)
        mBinding.refreshLayout.setOnRefreshListener(this)

        //点击事件
        mViewModel.mAdapter.setOnItemClickListener { _, view, position ->
            if (view.id == R.id.btn_query_status) {
                //去反馈页面
                AppointmentEnquiryActivity.startInstance()
            }
        }
    }

    override fun onRefresh(refreshLayout: RefreshLayout) {
        initData()
    }

    private fun initRV() {
        mBinding.recyclerView.vertical().adapter = mViewModel.mAdapter
    }

}