package com.sipai.jspatrol.Fault.adapter;

import android.content.Context;
import android.view.View;

import com.sipai.jspatrol.Bean.Fault;
import com.sipai.jspatrol.Fault.FaultFlowChartActivity;
import com.sipai.jspatrol.R;
import com.superrecycleview.superlibrary.adapter.BaseViewHolder;
import com.superrecycleview.superlibrary.adapter.SuperBaseAdapter;

import java.util.List;

/**
 * Created by lvliming on 2019/3/19.
 */

public class DoneFaultAdapter extends SuperBaseAdapter<Fault> {
    private List<Fault> data;
    private Context context;

    public DoneFaultAdapter(Context context, List<Fault> data) {
        super(context, data);
        this.data = data;
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder holder, Fault item, final int position) {
        item = data.get(position);
        final Fault finalItem = item;
        holder.setOnClickListener(R.id.moudle_item_done_fault_ll_all, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                DoneFaultActivity.actionStart(context,finalItem);
//                Toast.makeText(context, "工单详情完善中，敬请期待...", Toast.LENGTH_SHORT).show();
                FaultFlowChartActivity.actionStart(context, finalItem);
            }
        });
        if (item.getProcessSection().getName()!=null&&!item.getProcessSection().getName().equals("")){
            holder.setVisible(R.id.moudle_item_done_fault_tv_area,true);
            holder.setVisible(R.id.moudle_item_done_fault_ll_area,true);
            holder.setText(R.id.moudle_item_done_fault_tv_area,item.getProcessSection().getName());
        }else {
            holder.setVisible(R.id.moudle_item_done_fault_ll_area,false);
            holder.setVisible(R.id.moudle_item_done_fault_tv_area,false);
        }
        holder.setText(R.id.moudle_item_done_fault_tv_content,item.getProblemcontent());
        if (item.getProblemTypeNames()!=null&&item.getProblemTypeNames().length()>0) {
            holder.setText(R.id.moudle_item_done_fault_tv_remark,item.getProblemTypeNames());
        }else {
            holder.setVisible(R.id.moudle_item_done_fault_tv_remark,false);
        }
        if (item.getEquipmentCard()!=null&&!item.getEquipmentCard().getEquipmentname().equals("")){
            holder.setVisible(R.id.moudle_item_done_fault_tv_equ,true);
            holder.setText(R.id.moudle_item_done_fault_tv_equ,item.getEquipmentCard().getEquipmentname());
        }else {
            holder.setVisible(R.id.moudle_item_done_fault_tv_equ,false);
        }
        if (item.getInsdt().length()>16) {
            holder.setText(R.id.moudle_item_done_fault_tv_date,item.getInsdt().substring(5, 16));
        }else {
            holder.setText(R.id.moudle_item_done_fault_tv_date,"");
        }
        holder.setText(R.id.moudle_item_done_fault_tv_man,item.getInsuser());
    }

    @Override
    protected int getItemViewLayoutId(int position, Fault item) {
        return R.layout.item_done_fault;
    }
}
