package xn.hxp.ui.adapter

import android.content.Context
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import xn.hxp.R
import com.blankj.utilcode.util.LogUtils
import com.rc.httpcore.bean.UseLedgerListBean
import xn.hxp.weidith.TextTool

class ChecklistsAdapter(private val ct: Context) :
    BaseQuickAdapter<UseLedgerListBean, BaseViewHolder>(R.layout.item_checklists) {
    override fun convert(holder: BaseViewHolder, item: UseLedgerListBean) {
        holder.setText(R.id.chemicalName, "${item.chemicalName}")
        val chemicalNameTV = holder.getView<TextView>(R.id.chemicalName);
        chemicalNameTV.setOnClickListener {
            TextTool.showPop(context, chemicalNameTV)
        }
        holder.setText(R.id.tagCode, "${item.tagCode}")
        val tagCodeTV = holder.getView<TextView>(R.id.tagCode);
        tagCodeTV.setOnClickListener {
            TextTool.showPop(context, tagCodeTV)
        }
        holder.setText(R.id.cabinetName, "${item.cabinetName}-${item.doorName}-${item.layers}层")
        val cabinetNameTV = holder.getView<TextView>(R.id.cabinetName);
        cabinetNameTV.setOnClickListener {
            TextTool.showPop(context, cabinetNameTV)
        }
//        // 截取后5位
//        if (item.collectTime!=null){
//            val splitDateTime = item.collectTime.split(" ")
//            val date = splitDateTime[0]
//            val time = splitDateTime[1]
//            holder.setText(R.id.collectTime, "$date")
//            holder.setText(R.id.times, "$time")
//        }else{
//            holder.setText(R.id.collectTime, "")
//            holder.setText(R.id.times, "")
//        }
        // 截取后5位
        if (item.collectTime != null) {
            holder.setText(R.id.collectTime, "${item.collectTime}")
        } else {
            holder.setText(R.id.collectTime, "")
        }

        holder.setText(R.id.createByName, "${item.createByName}")
        holder.setText(R.id.collectStockNum, "${item.collectStockNum}${item.specUnit}")
        if (item.outOneUserName != null && item.outTwoUserName != null) {
            holder.setText(R.id.outOneName, "${item.outOneUserName}-${item.outTwoUserName}")
        } else {
            holder.setText(R.id.outOneName, "")
        }
        holder.setText(R.id.duration, "${item.duration}")

        //0已归还，1使用中，2超时未归还，3用结出库，4作废出库，5整瓶领用
//        when (item.status) {
        when (item.useStatus) {
            2 -> {
                holder.setTextColor(
                    R.id.status,
                    ContextCompat.getColor(ct, R.color.purple_FFFF8C11)
                )
                holder.setText(R.id.status, "超时未归还")
            }

            1 -> {
                holder.setTextColor(R.id.status, ContextCompat.getColor(ct, R.color.black))
                holder.setText(R.id.status, "待归还")
            }

            else -> {
                holder.setTextColor(R.id.status, ContextCompat.getColor(ct, R.color.black))
                holder.setText(R.id.status, " ")
            }
        }
    }
}