package com.yidian.shenghuoquan.buserorder.adapter

import android.annotation.SuppressLint
import android.app.Activity
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yidian.bcommon.constant.XEventConfig
import com.yidian.bcommon.extensions.clickAntiShake
import com.yidian.shenghuoquan.buserorder.R
import com.yidian.shenghuoquan.buserorder.dto.CouponDto
import com.yidian.xarc.xevent.XBaseEvent
import com.yidian.xarc.xevent.XEventManager

/**
 * 代金券适配器
 */
class VoucherAdapter : BaseQuickAdapter<CouponDto, BaseViewHolder>(R.layout.border_voucher_item) {

  @SuppressLint("SetTextI18n")
  override fun convert(holder: BaseViewHolder, item: CouponDto) {
    holder.getView<TextView>(R.id.tv_voucher_name).text = item.name
    holder.getView<TextView>(R.id.tv_voucher_amount).text = item.amount
    holder.getView<TextView>(R.id.tv_start_end_time).text = item.startTime + item.endTime
    holder.getView<TextView>(R.id.tv_voucher_condition).text = item.scopeUse
    holder.getView<TextView>(R.id.tv_voucher_desc).text = item.desc
    holder.getView<TextView>(R.id.tv_use_immediately).clickAntiShake {
      val list = mutableListOf<Int>()
      list.add(holder.layoutPosition)
      XEventManager.post(XBaseEvent(XEventConfig.CONFIRM_ORDER_CHOOSE_COUPON_SUCCESS, list))
      val activity = context as Activity
      activity.finish()
    }
  }
}
