package com.abbidot.tracker.deprecated.ui.activity.profile.recharge.cn

import androidx.activity.viewModels
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.abbidot.tracker.R
import com.abbidot.tracker.deprecated.adapter.RechargeHistoryCNAdapter
import com.abbidot.tracker.base.BaseActivity
import com.abbidot.tracker.constant.ConstantString
import com.abbidot.tracker.constant.GetResultCallback
import com.abbidot.tracker.databinding.ActivityRechargeHistoryCnBinding
import com.abbidot.tracker.deprecated.ui.activity.vm.RechargeHistoryViewModel

/**
 * 国内充值记录
 */
class RechargeHistoryCNActivity :
    BaseActivity<ActivityRechargeHistoryCnBinding>(ActivityRechargeHistoryCnBinding::inflate) {

    private val mRechargeHistoryViewModel: RechargeHistoryViewModel by viewModels()

    private lateinit var mRechargeHistoryCNAdapter: RechargeHistoryCNAdapter

    override fun getTopBar() = mViewBinding.rechargeDeviceDetailCnBar.titleTopBar

    override fun initData() {
        super.initData()
        setTopBarTitle(R.string.txt_card_history)

        val deviceId = intent.extras?.getString(ConstantString.DeviceId, "").toString()

        mRechargeHistoryCNAdapter = RechargeHistoryCNAdapter(mContext!!, null)

        mViewBinding.rechargeHistoryCnRecyclerView.apply {
            layoutManager = LinearLayoutManager(mContext)
            addItemDecoration(DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL))
            adapter = mRechargeHistoryCNAdapter
        }

        mRechargeHistoryViewModel.getRechargeHistory(this, deviceId)
    }

    override fun liveDataObserve() {
        mRechargeHistoryViewModel.mRechargeHistoryListLiveData.observe(this) {
            dealRequestResult(it, object : GetResultCallback {
                override fun onResult(any: Any) {
                    val list = it.getOrNull()!!
                    mRechargeHistoryCNAdapter.setData(list, true)
                }
            })
        }
    }
}