package com.pixelnx.localhelp.ui.user;

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.model.ModelOrderListData;



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


import java.util.List;

public class AdapterHistoryOrder extends RecyclerView.Adapter<AdapterHistoryOrder.HolderDialogOrder> {
    private List<ModelOrderListData.Data> dataArrayList;
    private Context mContext;


    public AdapterHistoryOrder(Context mContext, List<ModelOrderListData.Data> dataArrayList) {
        this.dataArrayList = dataArrayList;
        this.mContext = mContext;

    }

    @NonNull
    @Override
    public HolderDialogOrder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_orderlist, viewGroup, false);
        return new HolderDialogOrder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final HolderDialogOrder holder, final int i) {
        holder.tvItemPrise.setText("Total Amount\n₹  "+dataArrayList.get(i).getTotalAmount()+"");

        holder.tvItemName.setText("Order Number : "+dataArrayList.get(i).getId()+"\nStore : "+dataArrayList.get(i).getUserName()+"\nDate :  "+dataArrayList.get(i).getSaleDate());
        holder.tvItemQty.setText("Total Item Qty\n "+dataArrayList.get(i).getItemTotal());
        if(dataArrayList.get(i).getPaymentType().isEmpty()){
            holder.tvType.setText("Payment mode\n - ");
        }else{
            holder.tvType.setText("Payment mode\n"+dataArrayList.get(i).getPaymentType());}
        holder.tvAddToCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, OrderHistoryDetails.class);

                intent.putExtra("data",dataArrayList.get(i));
                mContext.startActivity(intent);

            }
        });



    }

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

    public static class HolderDialogOrder extends RecyclerView.ViewHolder {
       ImageView tvAddToCart;

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

        ImageView ivImage;

        public HolderDialogOrder(@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);
        }
    }
}
