package com.xty.server.frag

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.xty.base.fragment.BaseFragList
import com.xty.base.fragment.BaseVmFrag
import com.xty.network.model.AppointmentBean
import com.xty.network.model.AppointmentNewBean
import com.xty.server.adapter.AppointmentAdapter
import com.xty.server.databinding.FragHistoryBinding
import com.xty.server.vm.MyAppointmentVm

class WattingFrag : BaseFragList<MyAppointmentVm>(){
    val adapter by lazy{ AppointmentAdapter(0) }
    val binding by lazy { FragHistoryBinding.inflate(layoutInflater)}
    var type =2
    override fun setLayout()=binding.root

    override fun setViewModel()=MyAppointmentVm()

    override fun observer() {
        mViewModel.apponitMentBean.observe(this){
            var list= mutableListOf<AppointmentNewBean>()
            it.data.forEach {
//                if(it.orderStatus==2){
                    list.add(it)
//                }
            }
            setDate(adapter,list)

        }
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        type = arguments?.getInt("type", 0) ?: 0
    }
    companion object {
        fun newInstance(type: Int): WattingFrag {
            val fragment = WattingFrag()
            val bundle = Bundle()
            bundle.putInt("type", type)
            fragment.arguments = bundle
            return fragment
        }
    }
    override fun initView() {
        super.initView()
        initAdapter()
        setRecycleRefresh(binding.mRecycle,binding.mRefresh)
    }


    override fun refresh() {
        mViewModel.getAppointment(type)
    }

    override fun initAdapter() {
        binding.mRecycle.layoutManager= LinearLayoutManager(requireContext())
        binding.mRecycle.adapter=adapter
    }
}