package com.unis.sxzcl.ui.aeration;

import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.unis.model.bean.aeration.AerationBean;
import com.unis.sxzcl.R;

import org.jetbrains.annotations.NotNull;

/**
 * 机械通风列表适配器
 * 创建人: mQ
 * 时间: 2020/12/14 18:05
 */
public class AerationListAdapter extends BaseQuickAdapter<AerationBean, BaseViewHolder>
        implements LoadMoreModule {

    public Callback mCallback;

    public AerationListAdapter() {
        super(R.layout.item_list_aeration);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, AerationBean item) {

        holder.setText(R.id.tv_time, item.getApplyTime());

        ImageView imageView = holder.getView(R.id.iv_show);
        TextView tvStatus = holder.getView(R.id.tv_status);

        //0:提交,1审批通过:,2:审批不通过，3:审批完成进行中，4已完成
        String recordStatus = item.getAuditState() != null ? item.getAuditState() : "0";
        switch (recordStatus) {
            case "0":
                // 提交
                imageView.setImageResource(R.drawable.ic_wait_blue);
                tvStatus.setText("待审批");
                break;
            case "1":
                // 审批通过
                imageView.setImageResource(R.drawable.ic_wait_blue);
                tvStatus.setText("待审批");
                break;
            case "2":
                // 审批不通过
                imageView.setImageResource(R.drawable.ic_yellow_cancel);
                tvStatus.setText("审批不通过");
                break;
            case "3":
                // 审批完成进行中
                imageView.setImageResource(R.drawable.ic_wait_blue);
                tvStatus.setText("进行中");
                break;
            case "4":
                // 已完成
                imageView.setImageResource(R.drawable.ic_finish_accent);
                tvStatus.setText("已完成");
                break;
        }

        holder.itemView.setTag(item);
        holder.itemView.setOnClickListener(v -> {
            if (mCallback != null)
                mCallback.onItemClickListener((AerationBean) v.getTag());
        });

    }

    public void setCallback(Callback callback) {
        mCallback = callback;
    }

    public interface Callback {
        void onItemClickListener(AerationBean item);
    }
}
