package com.yono.messeripos.adapter;

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

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

import com.yono.messeripos.R;
import com.yono.messeripos.databinding.ItemPendingBinding;
import com.yono.messeripos.models.PaymentPending;
import com.yono.messeripos.models.PaymentsModels;
import com.yono.messeripos.utils.Utils;

import java.util.ArrayList;

public class PendingAdapter extends RecyclerView.Adapter<PendingAdapter.MyViewHolder> {
    private ArrayList<PaymentPending> paymentPendings = new ArrayList<>();
    Context context;
    Utils utils = new Utils();

    public void setPendingAdapter(Context context, ArrayList<PaymentPending> paymentPending){
        this.paymentPendings = paymentPending;
        this.context = context;
    }

    @NonNull
    @Override
    public PendingAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemPendingBinding itemPendingBinding = DataBindingUtil.inflate(
                LayoutInflater.from(parent.getContext()),
                R.layout.item_pending,
                parent,
                false
        );
        return new MyViewHolder(itemPendingBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull PendingAdapter.MyViewHolder holder, int position) {
        holder.binData(paymentPendings.get(position));
    }

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

    public class MyViewHolder extends RecyclerView.ViewHolder {
        ItemPendingBinding binding;
        public MyViewHolder(@NonNull ItemPendingBinding itemView) {
            super(itemView.getRoot());
            binding = itemView;
        }

        public void binData(PaymentPending paymentPending) {
            binding.setTransaction(paymentPending);
            binding.setDate(paymentPending.getTransaction_time());
            binding.setGrossAmount(utils.convertPrice("Rp. ", paymentPending.getGross_amount()));
        }
    }
}
