package com.cpm.lorealbaautomation.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.cpm.lorealbaautomation.R;
import com.cpm.lorealbaautomation.gsonGetterSetter.inwordDetail.ReportCounterInwardStockDetail;

import java.util.List;

public class InwardStkDetailAdapter extends RecyclerView.Adapter<InwardStkDetailAdapter.MyViewHolder> {
    LayoutInflater inflator;
    List<ReportCounterInwardStockDetail> data;

    public InwardStkDetailAdapter(Context context, List<ReportCounterInwardStockDetail> data) {
        inflator = LayoutInflater.from(context);
        this.data = data;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
        View view = inflator.inflate(R.layout.row_counter_inward_details, parent, false);
        return new MyViewHolder(view);
    }

    @SuppressLint({"SetTextI18n", "DefaultLocale"})
    @Override
    public void onBindViewHolder(@NonNull final MyViewHolder holder, final int position) {
        final ReportCounterInwardStockDetail current = data.get(position);
        setText(holder.tvParamCode, position, current.getParamCode(), inflator.getContext());
        setText(holder.tvParamName, position, current.getParamName(), inflator.getContext());

        setText(holder.tvInvoiceQty, position, current.getInvoiceQty() != null ? current.getInvoiceQty().toString() : "0", inflator.getContext());
        setText(holder.tvActualQty, position, current.getActualQty() != null ? current.getActualQty().toString() : "0", inflator.getContext());
        setText(holder.tvDamageQty, position, current.getDamageQty() != null ? current.getDamageQty().toString() : "0", inflator.getContext());
        setText(holder.tvMissedQty, position, current.getMissedQty() != null ? current.getMissedQty().toString() : "0", inflator.getContext());
    }

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

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView tvInvoiceQty, tvActualQty, tvDamageQty,tvMissedQty, tvParamCode, tvParamName;

        public MyViewHolder(View itemView) {
            super(itemView);
            tvMissedQty = (TextView) itemView.findViewById(R.id.tvMissedQty);
            tvInvoiceQty = (TextView) itemView.findViewById(R.id.tvInvoiceQty);
            tvActualQty = (TextView) itemView.findViewById(R.id.tvActualQty);
            tvDamageQty = (TextView) itemView.findViewById(R.id.tvDamageQty);
            tvParamCode = (TextView) itemView.findViewById(R.id.tvParamCode);
            tvParamName = (TextView) itemView.findViewById(R.id.tvParamName);
        }
    }

    @SuppressLint("DefaultLocale")
    private void setText(TextView tv, int pos, String value, Context context) {
        tv.setTextColor(ContextCompat.getColor(context, R.color.black));
        tv.setText(value);
        tv.setId(pos);
    }
}
