package xn.xxp.main.risk;

import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.List;

import http.vo.response.LabHazardVo;
import xn.xxp.R;

public class RiskListAdapter extends BaseQuickAdapter<LabHazardVo, BaseViewHolder> {
    private String selectedItemId;  // 当前选中项的ID

    public RiskListAdapter(List<LabHazardVo> data) {
        super(R.layout.item_risk, data);
    }

    public void setSelectedItemId(String id) {
        this.selectedItemId = id;
        notifyDataSetChanged();  // 刷新列表显示状态
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, LabHazardVo item) {
        TextView textView = (TextView) holder.itemView;
        // 显示编号和中文名称
        textView.setText(String.format("%s %s",
                item.hazardCode,
                item.chName
        ));

        // 根据选中状态设置背景
        int bgRes = item.hazardId.equals(selectedItemId)
                ? R.drawable.bg_item_checked
                : R.drawable.bg_item_normal;
        textView.setBackgroundResource(bgRes);
    }
}
