package com.pixelnx.localhelp.ui.order;

import android.content.Context;
import android.content.Intent;

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.pixelnx.localhelp.R;

import com.pixelnx.localhelp.utils.widgets.CustomTextMedium;


import java.util.List;

public class AdapterOrderList extends RecyclerView.Adapter<AdapterOrderList.HolderSearchAdapter> {
    List<ModelNewOrderData.Data> subCatData;
    Context mContext;

    String d="";


    public AdapterOrderList(Context mContext, List<ModelNewOrderData.Data> subCatData, String d) {

        this.subCatData = subCatData;
        this.mContext = mContext;
        this.d=d;

    }

    @NonNull
    @Override
    public HolderSearchAdapter onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_orderlist, viewGroup, false);
        return new HolderSearchAdapter(view);

    }

    @Override
    public void onBindViewHolder(@NonNull final HolderSearchAdapter holder, final int i) {

holder.tvItemName.setText("Order Number : "+subCatData.get(i).getId()+"\nCustomer : "+subCatData.get(i).getPartyName()+"\nDate : "+subCatData.get(i).getSaleDate());
holder.tvItemPrise.setText("Total Amount \n ₹"+subCatData.get(i).getTotalAmount()+"");

if(subCatData.get(i).getPaymentType().isEmpty()){
    holder.tvType.setText("Payment mode\n - ");
}else{
        holder.tvType.setText("Payment mode\n"+subCatData.get(i).getPaymentType());}
holder.tvItemQty.setText("Total Items Qty\n "+subCatData.get(i).getOrdersTotal());

if(d.equalsIgnoreCase("D")){
    holder.tvItemName.setText("Order Number : "+subCatData.get(i).getId()+"\nOrder Date :  "+subCatData.get(i).getSaleDate()+"\nDelivery On : "+subCatData.get(i).getDeliveryDate());
}


holder.tvAddToCart.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent=new Intent(mContext,OrderDetails.class);
        intent.putExtra("tag",d);
        intent.putExtra("data",subCatData.get(i));
        mContext.startActivity(intent);

    }
});

    }

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

    public static class HolderSearchAdapter extends RecyclerView.ViewHolder {

        ImageView tvAddToCart;

        CustomTextMedium tvItemName;
        CustomTextMedium  tvItemPrise;
        CustomTextMedium  tvItemQty;
        CustomTextMedium tvType;

        ImageView ivImage;

        public HolderSearchAdapter(@NonNull View itemView) {
            super(itemView);
            tvAddToCart = itemView.findViewById(R.id.tvAddToCart);

            ivImage = itemView.findViewById(R.id.ivImage);

            tvItemName = itemView.findViewById(R.id.tvItemName);
            tvItemPrise = itemView.findViewById(R.id.tvItemPrise);
            tvItemQty = itemView.findViewById(R.id.tvItemQty);
            tvType = itemView.findViewById(R.id.tvtype);


        }
    }

}
