package com.tomas.ckd_system.Adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

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

import com.tomas.ckd_system.List_Class.EventLog_list;
import com.tomas.ckd_system.List_Class.Outer_list;
import com.tomas.ckd_system.R;

import java.util.List;

public class EventLog_Adapter extends RecyclerView.Adapter<EventLog_Adapter.ViewHolder> {
    private List<EventLog_list>data;
    public Context context;

    public EventLog_Adapter(List <EventLog_list> dataset, Context context){
        data = dataset;
        this.context = context;
    }

    @NonNull
    @Override
    public EventLog_Adapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View content_view = LayoutInflater.from(parent.getContext()).inflate(R.layout.content_event_log_list,parent,false);
        context = parent.getContext();
        return new ViewHolder(content_view);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public LinearLayout layout;
        public TextView txt_stage, txt_date, txt_event, txt_event_det, txt_user, txt_status;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            layout = (LinearLayout) itemView.findViewById(R.id.row_even_log);
            txt_stage = (TextView) itemView.findViewById(R.id.txt_stage);
            txt_date = (TextView) itemView.findViewById(R.id.txt_date);
            txt_event = (TextView) itemView.findViewById(R.id.txt_event);
            txt_event_det = (TextView) itemView.findViewById(R.id.txt_event_det);
            txt_user = (TextView) itemView.findViewById(R.id.txt_user);
            txt_status = (TextView) itemView.findViewById(R.id.txt_status);

        }
    }

    @Override
    public void onBindViewHolder(@NonNull EventLog_Adapter.ViewHolder holder, int position) {
        final EventLog_list list = data.get(position);

        String error_detail, event_detail;
        error_detail = list.getError_det();
        event_detail = list.getEvent_det();

        if (error_detail.trim().equals("0")){
            holder.txt_event_det.setText("Detail :     "+event_detail);
        }else {
            holder.txt_event_det.setText("Detail :     "+error_detail);
        }



        holder.txt_stage.setText(list.getStage());
        holder.txt_date.setText("Date :     "+list.getCreate_dt());
        holder.txt_event.setText("Event :     "+list.getEvent());
        holder.txt_status.setText(list.getStatus());
        holder.txt_user.setText("User :     "+list.getCreate_user_id());

    }

    @Override
    public int getItemCount() {
        return data.size();
    }
}
