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

import android.graphics.Color
import com.cheng.blzb.R
import com.cheng.blzb.bean.SubscriptionMessageEntity
import com.cheng.blzb.databinding.FragmentMessageBinding
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 MessageFragment: ListFragment<FragmentMessageBinding, MessageViewModel, SubscriptionMessageEntity>() {
    private var item: SubscriptionMessageEntity? = null

    override fun noDataClick() {
    }

    override fun bindAdapter() = MessageAdapter()

    override fun initView() {
        super.initView()
        mTitleBar?.setBackgroundColor(Color.WHITE)

        mEmptyView.setNoDataLogo(R.mipmap.ic_empty_message)
        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!!.extra.recommend_id)
                )
            } else {
                PublicActivity.start(requireContext(), VipFragment::class.java, Pair("origin", "view_bid"))
            }
        }
    }
}