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

import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;

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.ViewHolderSearchType;

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

    private OnSearchListListener onSearchListListener;

    private View mViewTopMargin;
    private View mViewTopLine;
    private View mViewBottomLine;

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

        initLayout();
    }

    private void initLayout() {
        mViewTopMargin = itemView.findViewById(R.id.topMargin_view);
        mViewTopLine = itemView.findViewById(R.id.topLine_view);
        mViewBottomLine = itemView.findViewById(R.id.bottomLine_view);
    }

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

        SearchListViewHolderData data = (SearchListViewHolderData) object;
        final ViewHolderSearchType type = ViewHolderSearchType.valueOf(typeCode);

        switch (type) {
            case MEMBER:
                mViewTopMargin.setVisibility(View.VISIBLE);
                mViewTopLine.setVisibility(View.VISIBLE);
                itemView.setBackgroundColor(getContext().getResources().getColor(R.color.white));
                break;
            case TODO:
                mViewTopMargin.setVisibility(View.GONE);
                mViewTopLine.setVisibility(View.GONE);
                itemView.setBackgroundResource(0);
                break;
            case UNIT:
                mViewTopMargin.setVisibility(View.GONE);
                mViewTopLine.setVisibility(View.GONE);
                itemView.setBackgroundResource(0);
                break;
        }

        if (data.isLast()) {
            mViewBottomLine.setVisibility(View.GONE);
        } else {
            mViewBottomLine.setVisibility(View.VISIBLE);
        }

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