package com.zj365.mime.fragment

import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.fragment.BaseFragList
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.common.recycleUtils.RecycleItem
import com.xty.common.util.CommonUtils
import com.zj365.mime.adapter.ProgrammeAdapter
import com.zj365.mime.databinding.FragProgremmHistoryBinding
import com.zj365.mime.vm.ProgrammeHistoryVm
import com.xty.network.model.ProgrammeBean

/**
 * 历史方案
 */
class ProgrammeHistoryFrag : BaseFragList<ProgrammeHistoryVm>() {

    val binding by lazy { FragProgremmHistoryBinding.inflate(layoutInflater) }
    private val mAdapter by lazy { ProgrammeAdapter() }

    var userId: String? = null
    override fun setLayout() = binding.root

    override fun initView() {
        super.initView()
        setRecycleRefresh(binding.mRecycle, binding.mRefresh)
    }

    override fun initData() {
        super.initData()
        userId = arguments?.getString("userId")
    }

    override fun initAdapter() {
        setRecycleRefresh(binding.mRecycle, binding.mRefresh)
        binding.mRecycle.adapter = mAdapter
        binding.mRecycle.layoutManager = LinearLayoutManager(requireContext())
        binding.mRecycle.addItemDecoration(RecycleItem(requireContext(), 20))
        mAdapter.setOnItemClickListener { adapter, view, position ->
            val bean = adapter.getItem(position) as ProgrammeBean
            bundle.clear()
            bundle.putSerializable("bean", bean)
            RouteManager.goAct(ARouterUrl.PROGRAMME_DETAIL_NEW, bundle)

        }
    }

    override fun refresh() {
        mViewModel.getNesProg(userId)
    }

    override fun setViewModel(): ProgrammeHistoryVm = ProgrammeHistoryVm()

    override fun observer() {
        mViewModel.progLive.observe(this) {
            setDate(mAdapter, it.data)
        }
    }
}