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

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

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.adapter.contract.AlarmListContract;
import kr.co.hanwha.hifive.base.BaseViewHolder;
import kr.co.hanwha.hifive.data.model.AlarmData;
import kr.co.hanwha.hifive.util.GlideUtil;
import kr.co.hanwha.hifive.util.HFDateUtil;

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

public class AlarmListViewHolder extends BaseViewHolder {
    private ImageView mImageViewDot;
    private ImageView mImageViewSender;
    private TextView mTextViewTitle;
    private TextView mTextViewMessage;
    private TextView mTextViewDate;
    private View mViewUnderline;

    private AlarmListContract.OnAlarmListListener mOnAlarmListListener;

    public AlarmListViewHolder(@NonNull ViewGroup viewGroup, AlarmListContract.OnAlarmListListener onAlarmListListener) {
        super(viewGroup, R.layout.item_alarm_list);

        mOnAlarmListListener = onAlarmListListener;

        mImageViewDot = (ImageView) itemView.findViewById(R.id.dot_imageView);
        mImageViewSender = (ImageView) itemView.findViewById(R.id.sender_imageView);
        mTextViewTitle = (TextView) itemView.findViewById(R.id.title_textView);
        mTextViewMessage = (TextView) itemView.findViewById(R.id.message_textView);
        mTextViewDate = (TextView) itemView.findViewById(R.id.date_textView);

        mViewUnderline = (View) itemView.findViewById(R.id.underline_view);

        GlideUtil.getInstance().loadImageCircle(getContext(), R.mipmap.temp_img_df_profile, mImageViewSender);
    }

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

        final AlarmData data = (AlarmData) object;

        if (data != null) {
            if (TextUtils.isEmpty(data.getProfile_url()))
                GlideUtil.getInstance().loadImageCircle(getContext(), R.mipmap.temp_img_df_profile, mImageViewSender);
            else
                GlideUtil.getInstance().loadImageCircle(getContext(), data.getProfile_url(), mImageViewSender);

            mImageViewDot.setVisibility(data.is_opened() ? View.INVISIBLE : View.VISIBLE);

            mTextViewTitle.setText(data.getTitle());

            mTextViewMessage.setText(data.getMessage());

            mTextViewDate.setText(HFDateUtil.getDateFormatCommon(getContext(), data.getCreated_at()));
        }

        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnAlarmListListener != null) {
                    mOnAlarmListListener.onItemClicked(index, data);
                }
            }
        });
    }
}
