package com.yidian.shenghuoquan.buserorder.ui

import androidx.activity.viewModels
import com.yidian.bcommon.constant.IntentConstants
import com.yidian.bcommon.constant.XRouterPathConstants
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.CHOOSE_VOUCHER_ACTIVITY
import com.yidian.bcommon.mvvm.BaseMvvmActivity
import com.yidian.shenghuoquan.buserorder.R
import com.yidian.shenghuoquan.buserorder.adapter.VoucherAdapter
import com.yidian.shenghuoquan.buserorder.utils.SpaceItemDecoration
import com.yidian.shenghuoquan.buserorder.viewmodel.VoucherViewModel
import com.yidian.shenghuoquan.buserorder.databinding.BorderActivityVoncherBinding
import com.yidian.shenghuoquan.buserorder.dto.CouponDto
import com.yidian.xpage.XPageViewProtocol

/**
 * 我的代金券
 */
class VoucherActivity : BaseMvvmActivity<BorderActivityVoncherBinding, VoucherViewModel>(), XPageViewProtocol {

  override val layoutId: Int = R.layout.border_activity_voncher

  override val vm: VoucherViewModel by viewModels()

  private val listAdapter by lazy { VoucherAdapter() }

  override fun initView() {
    initRecycleView()
  }

  override fun getXPageName(): String {
    return CHOOSE_VOUCHER_ACTIVITY
  }

  private fun initRecycleView() {
    intent.getSerializableExtra(XRouterPathConstants.ParamsKey)?.let { params ->
      (params as HashMap<*, *>).let {
        val list = params[IntentConstants.KEY_EXTRA_COUPON_LIST] as List<CouponDto>
        binding.rvVoucherList.addItemDecoration(SpaceItemDecoration(resources.getDimensionPixelSize(R.dimen.dp10)))
        binding.rvVoucherList.adapter = listAdapter
        listAdapter.setList(list)
      }
    }
  }
}
