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

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

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.admin.admin.adapter.AdminMemberTaskListAdapter;
import kr.co.hanwha.hifive.admin.network.model.AdminMemberTaskData;
import kr.co.hanwha.hifive.base.BaseViewHolder;
import kr.co.hanwha.hifive.util.HFDateUtil;

/**
 * Created by sanghoonkwon on 2018. 3. 21..
 */

public class AdminMemberTaskListViewHolder extends BaseViewHolder {
    private LinearLayout mLayoutContainer;

    private TextView mTextViewDueDate;
    private TextView mTextViewStatus;

    private TextView mTextViewAuthorName;
    private TextView mTextViewReceiverName;
    private TextView mTextViewTitle;
    private TextView mTextViewEval;
    private TextView mTextViewTaskId;

    private String mReceiverName;

    private AdminMemberTaskListAdapter.OnAdminTaskListListener mOnAdminTaskListListener;

    public AdminMemberTaskListViewHolder(@NonNull ViewGroup viewGroup,
                                         AdminMemberTaskListAdapter.OnAdminTaskListListener onAdminTaskListListener) {

        super(viewGroup, R.layout.item_admin_member_task_list);

        mOnAdminTaskListListener = onAdminTaskListListener;

        mLayoutContainer = (LinearLayout) itemView.findViewById(R.id.container_linearLayout);

        mTextViewDueDate = (TextView) itemView.findViewById(R.id.dueDate_textView);
        mTextViewStatus = (TextView) itemView.findViewById(R.id.status_textView);
        mTextViewTitle = (TextView) itemView.findViewById(R.id.title_textView);
        mTextViewEval = (TextView) itemView.findViewById(R.id.eval_textView);
        mTextViewTaskId = (TextView) itemView.findViewById(R.id.taskId_textView);

        mTextViewAuthorName = (TextView) itemView.findViewById(R.id.authorName_textView);
        mTextViewReceiverName = (TextView) itemView.findViewById(R.id.receiverName_textView);
    }

    public void setReceiverName(String receiverName) {
        this.mReceiverName = receiverName;
    }

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

        if (object != null && object instanceof AdminMemberTaskData) {
            final AdminMemberTaskData data = (AdminMemberTaskData) object;
            try {
                mTextViewDueDate.setText(HFDateUtil.getChangeDateFormat(data.getLocal_due_to(), HFDateUtil.FORMAT_COMMON_SERVER, HFDateUtil.FORMAT_YYYY_MM_DD));

                mTextViewStatus.setText(data.getStatus() + "(" + data.getStatus_code() + ")");

                mTextViewTitle.setText(data.getTask_name());

                mTextViewAuthorName.setText(data.getAuthor_name());

                mTextViewReceiverName.setText(mReceiverName);

                mTextViewEval.setText(data.getEvaluation());

                mTextViewTaskId.setText("(" + data.getTask_id() + ")");
            } catch (Exception e) {
                e.printStackTrace();
            }

            if (mOnAdminTaskListListener != null) {
                mLayoutContainer.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mOnAdminTaskListListener.onTaskClicked(data);
                    }
                });
            }
        }
    }
/*
{
    "name": "메인 목록 - 3. Module함 목록 조회 신규 API 적용",
    "author": "권상훈iOS",
    "local_due_to": "2017-11-17",
    "status_code": 40,
    "status": "Rejected-request",
    "eval": "평가전",
    "local_created_at": "2017-12-12 18:55:05.0",
    "local_updated_at": "2018-02-06 11:29:58.0"
 }
*/
}
