package com.yidian.shenghuoquan.bmanagercenter.wallet.ui

import android.os.Bundle
import com.yidian.bcommon.constant.XRouterPathConstants
import com.yidian.bcommon.base.BaseActivity
import com.yidian.bcommon.extensions.initTitleBar
import com.yidian.shenghuoquan.bmanagercenter.R
import com.yidian.shenghuoquan.bmanagercenter.databinding.ActivityTransactionListBinding
import com.yidian.shenghuoquan.bmanagercenter.wallet.adapter.TransactionListAdapter
import com.yidian.shenghuoquan.bmanagercenter.wallet.bean.TransactionListItemDto
import com.yidian.utils.ToastUtil


/**
 * 钱包 - 交易列表
 */
class TransactionListActivity : BaseActivity<ActivityTransactionListBinding>() {

  private val adapter = TransactionListAdapter()

  override fun createViewBinding(): ActivityTransactionListBinding {
    return ActivityTransactionListBinding.inflate(layoutInflater)
  }

  override fun getXPageName(): String {
    return XRouterPathConstants.TRANSACTION_LIST
  }

  override fun init(savedInstanceState: Bundle?) {
    super.init(savedInstanceState)
    initView()
    initList()
    setupRefreshLayout()
  }

  private fun initView() {
    initTitleBar(viewBind.include.toolbar, viewBind.include.tvTitle, "")
    requestTransactionList(true)
  }

  private fun initList() {
    viewBind.rvList.adapter = adapter
    adapter.setEmptyView(R.layout.empty_view)
    adapter.setOnItemClickListener { adapter, _, position ->
      val item = adapter.getItem(position) as TransactionListItemDto
      ToastUtil.showToast(this, "携带交易数据进入交易详情")
    }
  }

  /**
   * 设置刷新
   */
  private fun setupRefreshLayout() {
    viewBind.smartRefreshLayout.apply {
      setEnableRefresh(true)
      setEnableLoadMore(true)
      setOnRefreshListener {
        requestTransactionList(true)
      }
      setOnLoadMoreListener {
        requestTransactionList(false)
      }
    }
  }

  /**
   * 请求交易列表
   */
  private fun requestTransactionList(refresh: Boolean) {
    // 请求成功，给adapter 赋值，更新请求页数和刷新，加载的状态
//    adapter.setList(it)
  }

}
