package ch.pizzalemon.android.adapter.recycler;

import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import ch.pizzalemon.android.R;
import ch.pizzalemon.android.activity.BaseActivity;
import ch.pizzalemon.android.model.cart.CartTotalModel;

public class OrderPriceRecyclerAdapter extends RecyclerView.Adapter<OrderPriceRecyclerAdapter.ViewHolder> {

    private ArrayList<CartTotalModel> cartTotalList;

    public static class ViewHolder extends RecyclerView.ViewHolder{

        @BindView(R.id.totalNameTextView) TextView totalNameTextView;
        @BindView(R.id.totalPriceTextView) TextView totalPriceTextView;

        public ViewHolder(final View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    public OrderPriceRecyclerAdapter(ArrayList<CartTotalModel> cartTotalList){
        this.cartTotalList = cartTotalList;
    }

    @Override
    public OrderPriceRecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View root = LayoutInflater.from(BaseActivity.currentActivity).inflate(R.layout.row_price_total, viewGroup, false);
        return new OrderPriceRecyclerAdapter.ViewHolder(root);
    }

    @Override
    public void onBindViewHolder(OrderPriceRecyclerAdapter.ViewHolder holder, int position) {
        holder.totalNameTextView.setText(cartTotalList.get(position).getTitle());
        holder.totalPriceTextView.setText(cartTotalList.get(position).getText());
    }

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

}