package com.tomas.ckd_system.Adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
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.Staging_list_pc;
import com.tomas.ckd_system.R;
import com.tomas.ckd_system.Staging_Detail_Activity;
import com.tomas.ckd_system.lib.Settings;

import java.util.List;

public class Staging_Adapter_PC extends RecyclerView.Adapter<Staging_Adapter_PC.ViewHolder> {
    private List<Staging_list_pc>data;
    public Context context;
    String outer_plan_date, status_position;
    int Request = 2002;

    public Staging_Adapter_PC(List<Staging_list_pc> data, Context context, String outer_plan_date, String status_position) {
        this.data = data;
        this.context = context;
        this.outer_plan_date = outer_plan_date;
        this.status_position = status_position;
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        public LinearLayout layout;
        public TextView txt_id, txt_dest, txt_model, txt_type, txt_pc_no, txt_control, txt_case_no, txt_line_no;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            layout = (LinearLayout) itemView.findViewById(R.id.row_staging_pc);
            txt_id = (TextView) itemView.findViewById(R.id.txt_id);
            txt_dest = (TextView) itemView.findViewById(R.id.txt_dest);
            txt_model = (TextView) itemView.findViewById(R.id.txt_model);
            txt_type = (TextView) itemView.findViewById(R.id.txt_type);
            txt_pc_no = (TextView) itemView.findViewById(R.id.txt_pc_no);
            txt_control = (TextView) itemView.findViewById(R.id.txt_control);
            txt_case_no = (TextView) itemView.findViewById(R.id.txt_item_no);
            txt_line_no = (TextView) itemView.findViewById(R.id.txt_line_no);
        }
    }

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

    @Override
    public void onBindViewHolder(@NonNull Staging_Adapter_PC.ViewHolder holder, int position) {
        final Staging_list_pc list = data.get(position);
        holder.txt_id.setText(list.getId());
        holder.txt_dest.setText(list.getDist());
        holder.txt_model.setText(list.getModel_no());
        holder.txt_type.setText(list.getModel_type());
        holder.txt_pc_no.setText(list.getPc_no());
        holder.txt_control.setText(list.getControl_no());
        holder.txt_case_no.setText(list.getCase_no());
        holder.txt_line_no.setText(list.getLine_no());

        holder.layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(context.getApplicationContext(), Staging_Detail_Activity.class);
                i.putExtra("pc_no", list.getPc_no().trim());
                i.putExtra("control_no", list.getControl_no());
                i.putExtra("outer_plan_date", outer_plan_date);
                i.putExtra("dist", list.getDist().trim());
                i.putExtra("model_no", list.getModel_no().trim());
                i.putExtra("model_type", list.getModel_type().trim());
                i.putExtra("line_no", list.getLine_no());
                i.putExtra("status", status_position);
                i.putExtra("case_no", list.getCase_no());

//                context.startActivity(i);
                ((Activity) context).startActivityForResult(i,300);
            }
        });
    }

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