package kr.co.hanwha.hifive.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import java.util.ArrayList;

import kr.co.hanwha.hifive.adapter.viewholder.CalendarGridViewHolder;
import kr.co.hanwha.hifive.data.model.CalendarData;

/**
 * Created by sanghoonkwon on 2018. 1. 18..
 */

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

    private ArrayList<CalendarData> mListOfCalendar;
    private OnCalendarListener onCalendarListener;

    public CalendarGridAdapter(OnCalendarListener onCalendarListener) {
        this.onCalendarListener = onCalendarListener;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new CalendarGridViewHolder(parent, onCalendarListener);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        CalendarGridViewHolder calendarGridViewHolder = (CalendarGridViewHolder) holder;
        calendarGridViewHolder.onBind(mListOfCalendar.get(position), position);
    }

    @Override
    public int getItemCount() {
        return mListOfCalendar != null ? mListOfCalendar.size() : 0;
    }

    public void addItems(ArrayList<CalendarData> items) {
        if (mListOfCalendar == null) mListOfCalendar = new ArrayList<>();
        else mListOfCalendar.clear();
        mListOfCalendar.addAll(items);

        notifyDataSetChanged();
    }

    /**************************************************
     * Listener
     **************************************************/
    public interface OnCalendarListener {
        void onClick(CalendarData data);
    }
}