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

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

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.admin.admin.adapter.AdminMemberDetailAdapter;
import kr.co.hanwha.hifive.admin.network.model.AdminMemberDetailHrInfo;
import kr.co.hanwha.hifive.base.BaseViewHolder;
import kr.co.hanwha.hifive.util.GlideUtil;

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

public class AdminMemberDetailHeaderViewHolder extends BaseViewHolder {
    private ImageView mImageViewDot;
    private ImageView mImageViewSender;
    private TextView mTextViewTitle;
    private TextView mTextViewMessage;
    private TextView mTextViewPhone;
    private TextView mTextViewAuthcode;
    private Button mButtonTaskList;
    private Button mButtonResetPassword;
    private Button mButtonResetSimplePassword;

    private AdminMemberDetailAdapter.OnAdminMemberDetailListener mOnAdminMemberDetailListener;

    public AdminMemberDetailHeaderViewHolder(@NonNull ViewGroup viewGroup, @Nullable AdminMemberDetailAdapter.OnAdminMemberDetailListener onAdminMemberDetailListener) {
        super(viewGroup, R.layout.item_admin_member_detail_header);

        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);
        mTextViewPhone = (TextView) itemView.findViewById(R.id.phone_textView);
        mTextViewAuthcode = (TextView) itemView.findViewById(R.id.authcode_textView);
        mButtonTaskList = (Button) itemView.findViewById(R.id.taskList_button);
        mButtonResetPassword = (Button) itemView.findViewById(R.id.resetPassword_button);
        mButtonResetSimplePassword = (Button) itemView.findViewById(R.id.resetSimplePassword_button);

        mOnAdminMemberDetailListener = onAdminMemberDetailListener;

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

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

        if (object != null && object instanceof AdminMemberDetailHrInfo) {
            final AdminMemberDetailHrInfo data = (AdminMemberDetailHrInfo) object;
//            if (TextUtils.isEmpty(data.getProfile_url()))
            GlideUtil.getInstance().loadImageCircle(getContext(), R.mipmap.ic_avatar, mImageViewSender);

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

            mTextViewTitle.setText(TextUtils.isEmpty(data.getLogin()) ? "" : data.getLogin());

            String message = (TextUtils.isEmpty(data.getRank()) ? "" : data.getRank()) + " | " + (TextUtils.isEmpty(data.getPosition()) ? "" : data.getPosition());
            mTextViewMessage.setText(message);

            mTextViewPhone.setText(TextUtils.isEmpty(data.getPhone_mobile()) ? "" : data.getPhone_mobile());

            mTextViewAuthcode.setText(data.isIs_null_authcode() ? "미설정" : "설정");

            if (mOnAdminMemberDetailListener != null) {
                mButtonTaskList.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mOnAdminMemberDetailListener.onTaskListClicked();
                    }
                });
                mButtonResetPassword.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mOnAdminMemberDetailListener.onResetPasswordClicked();
                    }
                });
                mButtonResetSimplePassword.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mOnAdminMemberDetailListener.onResetSimplePasswordClicked();
                    }
                });
            }
        }
    }
/*
    "login": "kookhee.lee@hanwha.com",
    "is_null_authcode": false,
    "rank": "부장",
    "position": "부장",
    "phone_mobile": "010-4864-4312"
*/
}