package com.unis.sxzcl.ui.facility.facility_check;

import android.graphics.Color;
import android.view.View;

import androidx.cardview.widget.CardView;

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.BasicModel;
import com.unis.model.bean.facility_check.FacilityLastBean;
import com.unis.sxzcl.R;

import org.jetbrains.annotations.NotNull;


/**
 * 最新设施检查适配器
 * 创建人: mQ
 * 时间: 2021/3/23 17:11
 */
public class FacilityCheckLastAdapter extends BaseQuickAdapter<FacilityLastBean, BaseViewHolder>
        implements LoadMoreModule {

    public Callback mCallback;

    public FacilityCheckLastAdapter() {
        super(R.layout.item_list_facility_check_last);
    }

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

        holder.setText(R.id.tv_status, BasicModel.get().getEnumName(item.kind))
                .setText(R.id.tv_time,
                        item.checkTime == null ? null : "最近检查时间" + item.checkTime);

        // 检查结果(0:蓝,1:黄)
        CardView cardView = holder.getView(R.id.card_show);
        String checkResult = item.checkResult;
        if (checkResult != null) {
            cardView.setVisibility(View.VISIBLE);
            if (checkResult.equals("0")) {
                cardView.setCardBackgroundColor(Color.parseColor("#199856"));
            } else {
                cardView.setCardBackgroundColor(Color.parseColor("#FFFF00"));
            }
        } else {
            cardView.setVisibility(View.INVISIBLE);
        }

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

    }

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

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