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.SearchTaskListContract;
import kr.co.hanwha.hifive.base.BaseViewHolder;
import kr.co.hanwha.hifive.data.model.TaskListData;
import kr.co.hanwha.hifive.util.GlideUtil;
import kr.co.hanwha.hifive.util.HFDateUtil;

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

public class SearchTaskListViewHolder extends BaseViewHolder {
    private ImageView mImageViewAuthor;
    private TextView mTextViewAuthor;
    private TextView mTextViewDate;
    private TextView mTextViewTitle;
    private TextView mTextViewQuest;
    private TextView mTextViewDday;
//    private CustomProgressBar mViewProgressBar;

    private SearchTaskListContract.OnSearchListListener mOnSearchListListener;

    public SearchTaskListViewHolder(@NonNull ViewGroup viewGroup,
                                    SearchTaskListContract.OnSearchListListener onSearchListListener) {

        super(viewGroup, R.layout.item_search_task_list);

        mOnSearchListListener = onSearchListListener;

        mImageViewAuthor = (ImageView) itemView.findViewById(R.id.author_imageView);
        mTextViewAuthor = (TextView) itemView.findViewById(R.id.author_textView);
        mTextViewDate = (TextView) itemView.findViewById(R.id.date_textView);
        mTextViewTitle = (TextView) itemView.findViewById(R.id.title_textView);
        mTextViewQuest = (TextView) itemView.findViewById(R.id.quest_textView);
        mTextViewDday = (TextView) itemView.findViewById(R.id.dday_textView);
//        mViewProgressBar = (CustomProgressBar) itemView.findViewById(R.id.viewProgressbar);

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

//        mViewProgressBar.setProgress(0);
    }


    @Override
    public void onBind(Object object, final int index) {
        super.onBind(object, index);
//        final TaskListData data = (object instanceof TaskListViewHolderData) ? ((TaskListViewHolderData) object).getData() : (TaskListData) object;
        final TaskListData data = (TaskListData) object;
        if (data != null) {
            mTextViewAuthor.setText(data.getMember_name());

            GlideUtil.getInstance().loadImageCircle(getContext(), data.getMember_profile_url(), mImageViewAuthor);
            mTextViewAuthor.setText(data.getMember_name());

            if (TextUtils.isEmpty(data.getMember_profile_url()))
                GlideUtil.getInstance().loadImageCircle(getContext(), R.mipmap.temp_img_df_profile, mImageViewAuthor);
            else
                GlideUtil.getInstance().loadImageCircle(getContext(), data.getMember_profile_url(), mImageViewAuthor);

            String date = HFDateUtil.getChangeDateFormat(data.getTask_created_at(), HFDateUtil.FORMAT_COMMON_SERVER, HFDateUtil.FORMAT_YYYY_MM_DD);
            mTextViewDate.setText(date);

            mTextViewTitle.setText(data.getTask_name());

            if (TextUtils.isEmpty(data.getProject_name()) == false)
                mTextViewQuest.setText(data.getProject_name());
            else mTextViewQuest.setText("");

//            int progressColor = HFTaskUtil.getProgressColor(getContext(), data.getEvaluation());
//            mViewProgressBar.setProgressColor(progressColor);

//            int period = GWTaskUtil.getProgressPeriod(data.getDue_to(), data.getTask_created_at());
//            String dDay = HFTaskUtil.getDisplayDDay(getContext(), data.getDue_to(), data.getServer_time());
//            final int progress = GWTaskUtil.getProgress(period, data.getDue_to(), data.getServer_time());

//            mViewProgressBar.setMax(period);
//            mTextViewDday.setText(dDay);
//            mViewProgressBar.setProgress(progress);
        }

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