package com.cooleshow.student.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.cooleshow.base.bean.EquipmentTestingBean;
import com.cooleshow.student.R;

import java.util.LinkedList;
import java.util.List;

/**
 * 创建日期：2022/6/1 17:11
 *
 * @author Ryan
 * 类说明：
 */
public class TestingListAdapter extends RecyclerView.Adapter<TestingListAdapter.ViewHolder> {


    private Context mContext;
    private int cont = 0;
    private List<EquipmentTestingBean> list = new LinkedList<>();

    public TestingListAdapter(Context mContex, List<EquipmentTestingBean> list1) {
        this.mContext = mContex;
        list.addAll(list1);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflater = LayoutInflater.from(mContext).inflate(R.layout.testing_list_item, parent, false);
        return new ViewHolder(inflater);

    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        if (position == 5) {
            holder.line.setVisibility(View.INVISIBLE);
        } else {
            holder.line.setVisibility(View.VISIBLE);

        }
        if (position != 0) {
            holder.tvStartLine.setVisibility(View.VISIBLE);
        } else {
            holder.tvStartLine.setVisibility(View.INVISIBLE);
        }

        if (list.get(position).getState() == 1) {
            holder.ivIcon.setBackgroundResource(com.cooleshow.base.R.drawable.icon_testing_success);
        } else if (list.get(position).getState() == 2) {
            holder.ivIcon.setBackgroundResource(com.cooleshow.base.R.drawable.icon_testing_closea);
        } else if (list.get(position).getState() == 3) {
            holder.ivIcon.setBackgroundResource(com.cooleshow.base.R.drawable.icon_testing_wait);
        } else if (list.get(position).getState() == 4) {
            holder.ivIcon.setBackgroundResource(com.cooleshow.base.R.drawable.icon_testing_default);
        }

        if (position < cont) {
            if (position == cont - 1) {
                holder.line.setBackgroundResource(com.cooleshow.base.R.drawable.ic_dash_line);
            } else {
                holder.line.setBackgroundResource(com.cooleshow.base.R.color.gray_AA);
            }
            holder.tvStartLine.setBackgroundResource(com.cooleshow.base.R.color.gray_AA);
        } else {

            holder.line.setBackgroundResource(com.cooleshow.base.R.drawable.ic_dash_line);
            holder.tvStartLine.setBackgroundResource(com.cooleshow.base.R.drawable.ic_dash_line);

        }

    }

    @Override
    public int getItemCount() {
        return 6;
    }


    public void setData(List<EquipmentTestingBean> list1, int cont) {
        list.clear();
        list.addAll(list1);
        this.cont = cont;
        notifyDataSetChanged();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {


        private ImageView ivIcon;
        private View line;
        private View tvStartLine;

        public ViewHolder(View itemView) {
            super(itemView);
            ivIcon = itemView.findViewById(R.id.iv_icon);
            line = itemView.findViewById(R.id.tv_line);
            tvStartLine = itemView.findViewById(R.id.tv_start_line);
        }


    }

}