package xn.hxp.ui.adapter

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.rc.httpcore.bean.StockDetailsModel
import xn.hxp.R

class PrintLabelAdapter :
    BaseQuickAdapter<StockDetailsModel, BaseViewHolder>(R.layout.item_print_label_rv) {

    companion object {
        const val DEFAULT_RFID_HINT = "请用读卡器扫描RFID标签"
    }

    init {
        addChildClickViewIds(R.id.rescanBtn)
    }

    override fun convert(holder: BaseViewHolder, item: StockDetailsModel) {
        holder.setText(R.id.no, item.no.toString())
        holder.setText(R.id.tagCode, item.tagCode ?: "")
        val rfidView = holder.getView<TextView>(R.id.rfidCode)
        val rfid = item.rfidCode?.trim().orEmpty()
        if (rfid.isEmpty()) {
            rfidView.text = DEFAULT_RFID_HINT
        } else {
            rfidView.text = rfid
        }
    }
}
