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

import android.support.annotation.NonNull;
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.OnSearchListListener;
import kr.co.hanwha.hifive.adapter.model.SearchListViewHolderData;
import kr.co.hanwha.hifive.base.BaseViewHolder;
import kr.co.hanwha.hifive.util.GlideUtil;

/**
 * Created by aaron on 23/10/2018
 */
public class SearchMemberListViewHolder extends BaseViewHolder {

    private ImageView mImageViewProfile;
    private TextView mTextViewName;
    private TextView mTextViewPosition;
    private TextView mTextViewProject;
    private View mViewBottomMargin;
    private View mViewTopMargin;

    private OnSearchListListener onSearchListListener;

    public SearchMemberListViewHolder(ViewGroup viewGroup, OnSearchListListener onSearchListListener) {
        super(viewGroup, R.layout.item_search_member_list);
        this.onSearchListListener = onSearchListListener;

        initLayout();
    }

    private void initLayout() {
        mImageViewProfile = (ImageView) itemView.findViewById(R.id.profile_imageView);
        mTextViewName = (TextView) itemView.findViewById(R.id.name_textView);
        mTextViewPosition = (TextView) itemView.findViewById(R.id.position_textView);
        mTextViewProject = (TextView) itemView.findViewById(R.id.project_textView);
        mViewBottomMargin = itemView.findViewById(R.id.bottomMargin_view);
        mViewTopMargin = itemView.findViewById(R.id.topMargin_view);
    }

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

        if (object instanceof SearchListViewHolderData) {
            final SearchListViewHolderData data = (SearchListViewHolderData) object;
            if (data != null) {
                GlideUtil.getInstance().loadImageCircle(getContext(), R.mipmap.ic_avatar, mImageViewProfile);
                mTextViewName.setText(data.getMemberName());
                mTextViewPosition.setText(data.getRankTitle());
                mTextViewProject.setText(data.getDepartment());
                mViewTopMargin.setVisibility(data.isFirst() ? View.VISIBLE : View.GONE);
                mViewBottomMargin.setVisibility(data.isLast() ? View.VISIBLE : View.GONE);

                itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        onSearchListListener.onItemClicked(data);
                    }
                });
            }
        }
    }
}
