package kr.co.hanwha.hifive.adapter.viewholder;

import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.adapter.CalendarGridAdapter;
import kr.co.hanwha.hifive.base.BaseViewHolder;
import kr.co.hanwha.hifive.data.model.CalendarData;
import kr.co.hanwha.hifive.util.HFCommonUtil;

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

public class CalendarGridViewHolder extends BaseViewHolder {
    private TextView mTextViewDay;


    private CalendarGridAdapter.OnCalendarListener onCalendarListener;

    public CalendarGridViewHolder(@NonNull ViewGroup viewGroup, CalendarGridAdapter.OnCalendarListener onCalendarListener) {
        super(viewGroup, R.layout.item_calendar_grid);

        this.onCalendarListener = onCalendarListener;

        mTextViewDay = (TextView) itemView.findViewById(R.id.day_textView);
    }

    @Override
    public void onBind(@NonNull Object object, @NonNull final int position) {
        super.onBind(object, position);

        final CalendarData data = (CalendarData) object;
        if (data != null) {
            mTextViewDay.setText(Integer.toString(data.getDay()));
            int color = 0;
            if (data.isEnable()) {
                if (data.isSelected())
                    color = HFCommonUtil.getColor(getContext(), R.color.white);
                else
                    color = HFCommonUtil.getColor(getContext(), R.drawable.button_circle_calendar_text);
            } else {
                color = HFCommonUtil.getColor(getContext(), R.color.gray_c8);
            }


            mTextViewDay.setSelected(data.isSelected());

            mTextViewDay.setTextColor(color);

            mTextViewDay.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (onCalendarListener != null) {
                        onCalendarListener.onClick(data);
                    }
                }
            });
        }
    }
}