package w.soulofpluto.posstock;

/*
 Create by Ramesh Babu
 
 */

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class DeliverySlipAdapter extends RecyclerView.Adapter<DeliverySlipAdapter.ViewHolder> {
    public List<CreateResponse.Datum> arrayList;
    public Context context;
    
    public DeliverySlipAdapter(Context context, List<CreateResponse.Datum> list){
     this.context   = context;
     this.arrayList = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        View listItem = layoutInflater.inflate(R.layout.delivery_list_item, parent, false);
        DeliverySlipAdapter.ViewHolder viewHolder = new DeliverySlipAdapter.ViewHolder(listItem);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        CreateResponse.Datum datum = arrayList.get(position);
        if(TextUtils.isEmpty(datum.getItemLevelPromoName())){
          holder.item_level_promotion.setVisibility(View.GONE);
        }else{
          holder.item_level_promotion.setVisibility(View.VISIBLE);
          holder.item_level_promotion.setText(datum.getItemLevelPromoName());
        }
        holder.create_barcode.setText(Html.fromHtml(Constants.getBarcode(datum.getBarcode())));
        holder.create_empid.setText(Html.fromHtml(Constants.getEmpId(datum.getEmpId())));
        holder.create_dis.setText(Html.fromHtml(Constants.getCode(Constants.IndianRupeesFormat(String.valueOf(datum.getPromoDisc())))));
        holder.create_mrp.setText(Html.fromHtml(Constants.getMRP(Constants.IndianRupeesFormat(datum.getItemRsp()))));
        holder.create_netpay.setText(Html.fromHtml(Constants.getNetPayable(Constants.IndianRupeesFormat(datum.getNetPayable().toString()))));
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder{
        public TextView create_barcode,create_empid,create_mrp,create_dis,create_netpay,item_level_promotion;
        public ViewHolder(View itemView){
            super(itemView);
            create_barcode        = itemView.findViewById(R.id.create_barcode);
            create_empid          = itemView.findViewById(R.id.create_empid);
            create_mrp            = itemView.findViewById(R.id.create_mrp);
            create_dis            = itemView.findViewById(R.id.create_dis);
            create_netpay         = itemView.findViewById(R.id.create_netpay);
            item_level_promotion  = itemView.findViewById(R.id.item_level_promotion);
        }
    }
}
