package com.hikapro.backpack.presenter.adapters;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.hikapro.backpack.R;
import com.hikapro.backpack.model.entities.Item;
import com.hikapro.backpack.presenter.Presenter;
import com.hikapro.backpack.view.recycler.AddItemViewHolder;
import com.hikapro.backpack.view.recycler.ItemViewHolder;

/**
 * Created by tariel on 18/05/16.
 */
public class AddListAdapter extends RecyclerView.Adapter<AddItemViewHolder> {

    private Presenter.Add   presenter;

    public AddListAdapter(Presenter.Add presenter) {
        this.presenter = presenter;
    }

    @Override
    public int getItemCount() {
        return presenter.getModel().getItemsCount();
    }

    @Override
    public void onBindViewHolder(AddItemViewHolder holder, int position) {
        final Item item = presenter.getModel().getItemByPosition(position);
        holder.name.setText(item.getName());
        holder.category.setText(presenter.getModel().getCategoryById(item.getCategory()).getName());
        holder.alreadyInList.setVisibility(item.InList ? View.VISIBLE : View.GONE);
        holder.item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                presenter.onAddItemClick(item);
            }
        });
    }

    @Override
    public AddItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        AddItemViewHolder viewHolder;
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_add,
                parent, false);
        viewHolder = new AddItemViewHolder(v);
        return viewHolder;
    }
}
