package com.cheng.blzb.ui.fragment.mine.history

import com.cheng.blzb.R
import com.cheng.blzb.bean.BidDetailEntity
import com.cheng.blzb.databinding.FragmentHistoryBinding
import com.cheng.blzb.ui.activity.PublicActivity
import com.cheng.blzb.ui.fragment.bid.detail.BidDetailFragment
import com.cheng.blzb.ui.fragment.mine.vip.VipFragment
import com.example.base.ui.list.ListFragment

class HistoryFragment: ListFragment<FragmentHistoryBinding, HistoryViewModel, BidDetailEntity>() {
    private var item: BidDetailEntity? = null

    override fun noDataClick() {

    }

    override fun bindAdapter() = HistoryAdapter()

    override fun initView() {
        super.initView()
        mTitleBar?.background = null

        mEmptyView.setNoDataLogo(R.mipmap.ic_empty_history)
        mEmptyView.setNoDataText("暂无足迹")
    }

    override fun initData() {
        super.initData()
        firstLoad()
    }

    override fun initListener() {
        super.initListener()
        mAdapter.setOnItemClickListener { _, _, i ->
            item = mAdapter.getItem(i)
            mViewModel.checkAuth()
        }
    }

    override fun initObserve() {
        super.initObserve()
        mViewModel.authLiveData.observe(this) {
            if (it.auth) {
                PublicActivity.start(
                    requireContext(),
                    BidDetailFragment::class.java,
                    Pair("id", item!!.id),
                    Pair("info_source", item!!.info_source)
                )
            } else {
                PublicActivity.start(requireContext(), VipFragment::class.java, Pair("origin", "view_bid"))
            }
        }
    }
}