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.LinearLayout;
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.enums.ProjectAchievementType;

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

    private LinearLayout mLinearLayoutBody;
    private ImageView mImageViewStatus;
    private TextView mTextViewProject;
    private TextView mTextViewUnit;
    private TextView mTextViewMember;

    private OnSearchListListener onSearchListListener;

    public SearchUnitListViewHolder(ViewGroup viewGroup, OnSearchListListener onSearchListListener) {
        super(viewGroup, R.layout.item_search_unit_list);
        this.onSearchListListener = onSearchListListener;
        initLayout();
    }

    private void initLayout() {
        mLinearLayoutBody = (LinearLayout) itemView.findViewById(R.id.body_linearLayout);
        mImageViewStatus = (ImageView) itemView.findViewById(R.id.status_imageView);
        mTextViewProject = (TextView) itemView.findViewById(R.id.project_textView);
        mTextViewUnit = (TextView) itemView.findViewById(R.id.unit_textView);
        mTextViewMember = (TextView) itemView.findViewById(R.id.member_textView);
    }

    @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) {
                ProjectAchievementType achieveType = ProjectAchievementType.valueOf(data.getAchievement());
                switch (achieveType) {
                    case GREEN:
                        mImageViewStatus.setBackground(getContext().getResources().getDrawable(R.mipmap.ic_unit_g));
                        break;
                    case RED:
                        mImageViewStatus.setBackground(getContext().getResources().getDrawable(R.mipmap.ic_unit_r));
                        break;
                    case YELLOW:
                        mImageViewStatus.setBackground(getContext().getResources().getDrawable(R.mipmap.ic_unit_y));
                        break;
                    case ORANGE:
                        mImageViewStatus.setBackground(getContext().getResources().getDrawable(R.mipmap.ic_unit_o));
                        break;
                    default:
                        mImageViewStatus.setBackground(getContext().getResources().getDrawable(R.mipmap.ic_unit_g));
                }
                mTextViewProject.setText(data.getProjectName());
                mTextViewUnit.setText(data.getTrackName());
                mTextViewMember.setText(data.getMemberName());
                mLinearLayoutBody.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        onSearchListListener.onItemClicked(data);
                    }
                });
            }
        }
    }
}
