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 java.util.ArrayList;

import kr.co.hanwha.hifive.R;
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.view.HFTagContainerView;

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

public class ModuleTaskViewHolder extends BaseViewHolder {
    private ImageView mImageViewProfile;
    private TextView mTextViewName;
    private TextView mTextViewTitle;
    private TextView mTextViewDescription;
    private HFTagContainerView mTagContainerView;

    public ModuleTaskViewHolder(@NonNull ViewGroup viewGroup) {
        super(viewGroup, R.layout.temp_item_main_task_request_list);

        mImageViewProfile = (ImageView) itemView.findViewById(R.id.profile_imageView);
        mTextViewName = (TextView) itemView.findViewById(R.id.name_textView);
        mTextViewTitle = (TextView) itemView.findViewById(R.id.title_textView);
        mTextViewDescription = (TextView) itemView.findViewById(R.id.description_textView);
        mTagContainerView = (HFTagContainerView) itemView.findViewById(R.id.tagContainerView);

        GlideUtil.getInstance().loadImageRoundedCorners(getContext(), R.mipmap.temp_img_df_profile, mImageViewProfile);
    }

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

        final TaskListData data = (TaskListData) object;
//        mViewUnderline.setVisibility(holderData.isLastData() ? View.INVISIBLE : View.VISIBLE);

        if (data != null) {
            if (TextUtils.isEmpty(data.getMember_profile_url()))
                GlideUtil.getInstance().loadImageRoundedCorners(getContext(), R.mipmap.temp_img_df_profile, mImageViewProfile);
            else
                GlideUtil.getInstance().loadImageRoundedCorners(getContext(), data.getMember_profile_url(), mImageViewProfile);

            mTextViewName.setText(data.getMember_name());

            mTextViewTitle.setText(data.getTask_name());

            mTextViewDescription.setText(data.getDescription());

            ArrayList<String> listOfTags = new ArrayList<>();
            listOfTags.add(data.getProject_name());
            mTagContainerView.setTagList(listOfTags);

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

//            int progressColor = GWTaskUtil.getProgressColor(getContext(), data.getEvaluation());
//            mViewProgressbar.setProgressColor(progressColor);
//
//            int period = GWTaskUtil.getProgressPeriod(data.getDue_to(), data.getTask_created_at());
//            String dDay = GWTaskUtil.getDisplayDDay(getContext(), data.getDue_to(), data.getServer_time());
//            int progress = GWTaskUtil.getProgress(period, data.getDue_to(), data.getServer_time());
//
//            mViewProgressbar.setMax(period);
//            mTextViewDate.setText(dDay);
//            mViewProgressbar.setProgress(progress);

//            int colorProject = GWTaskUtil.getFontColorRequestProject(getContext(), data.getStatus());
//            int colorText = GWTaskUtil.getFontColorRequestText(getContext(), data.getStatus());
//            int colorStatus = GWTaskUtil.getFontColorRequestStatus(getContext(), data.getStatus());
//            String status = GWStringUtil.getDisplayRequestStatus(getContext(), data.getStatus(), data.getEvaluation());

//            int ddayColor = GWTaskUtil.getDDayColor(getContext(), data);
//            mTextViewDate.setTextColor(ddayColor);//mTextViewDate.setTextColor(colorText);
//            mTextViewTitle.setTextColor(colorText);
//            mTextViewProject.setTextColor(colorProject);
//            mTextViewStatus.setTextColor(colorStatus);
//            mTextViewStatus.setText(status);

//            if (data.getStatus() == TaskStatusType.CLOSED.getCode()) {
//                mTextViewTitle.setBackground(getContext().getDrawable(R.drawable.text_bg_stroke_through));
//            } else {
            mTextViewTitle.setBackground(null);
//            }
        }

        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
    }
}