package com.kaviz.heal_pharmacy;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.kaviz.heal_pharmacy.databinding.OrderListDesignBinding;

import java.util.List;

public class OrderAdapter extends RecyclerView.Adapter<OrderAdapter.OrderViewHolder> {

    private List<Order>orderList;
    private Context context;

    public OrderAdapter(List<Order> orderList, Context context) {
        this.orderList = orderList;
        this.context = context;
    }

    @NonNull
    @Override
    public OrderViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new OrderViewHolder(LayoutInflater.from(context).inflate(R.layout.order_list_design, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull OrderViewHolder holder, int position) {

        Order order = orderList.get(position);

        String clientName = "Client Name : "+order.getClientName();
        String phoneNumber = "Phone Number : "+order.getPhoneNumber();
        String medicines = "Medicines : "+order.getMedicines();

        holder.binding.clientNameName.setText(clientName);
        holder.binding.phoneNumberText.setText(phoneNumber);
        holder.binding.medicinesText.setText(medicines);

    }

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

    static class OrderViewHolder extends RecyclerView.ViewHolder {

        OrderListDesignBinding binding;

        public OrderViewHolder(@NonNull View itemView) {
            super(itemView);

            binding = OrderListDesignBinding.bind(itemView);

        }
    }

}
