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

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

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.adapter.contract.AddTaskSelectCampaignListContract;
import kr.co.hanwha.hifive.adapter.model.OkrListViewHolderData;
import kr.co.hanwha.hifive.base.BaseViewHolder;
import kr.co.hanwha.hifive.data.model.CampaignData;
import kr.co.hanwha.hifive.screen.main.setting.myhome.contract.MyHomeContract;

/**
 * Created by aaron on 2018. 10. 8.
 */
public class SelectCampaignListKeyResultViewHolder extends BaseViewHolder {
    private LinearLayout mLinearLayoutBody;
    private TextView mTextViewKeyResult;
    private ImageButton mImageButtonCheck;

    private AddTaskSelectCampaignListContract.OnSelectCampaignListListener mOnSelectCampaignListListener;

    private String mSelectedCampaignKey;

    public SelectCampaignListKeyResultViewHolder(ViewGroup viewGroup, AddTaskSelectCampaignListContract.OnSelectCampaignListListener onSelectCampaignListListener) {
        super(viewGroup, R.layout.item_select_campaign_list_key_result);

        this.mOnSelectCampaignListListener = onSelectCampaignListListener;
        mLinearLayoutBody = (LinearLayout) itemView.findViewById(R.id.body_linearLayout);
        mTextViewKeyResult = (TextView) itemView.findViewById(R.id.key_result_textView);
        mImageButtonCheck = (ImageButton) itemView.findViewById(R.id.check_imageButton);
    }

    public void setSelectedCampaignKey(String selectedCampaignKey) {
        this.mSelectedCampaignKey = selectedCampaignKey;
    }

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

        if (object instanceof OkrListViewHolderData) {
            final OkrListViewHolderData data = (OkrListViewHolderData) object;

            mImageButtonCheck.setSelected((mSelectedCampaignKey != null && mSelectedCampaignKey.equals(data.getKey())));

//            if (data.getLast()) {
//                mLinearLayoutKeyResult.setBackgroundResource(R.drawable.box_rounded_project_task_bg_bottom);
//            } else {
//                mLinearLayoutKeyResult.setBackgroundResource(R.drawable.box_rounded_project_task_bg_middle);
//            }

            mTextViewKeyResult.setText(data.getDesc());

            if (mOnSelectCampaignListListener != null) {
                mImageButtonCheck.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mOnSelectCampaignListListener.onItemClicked(data, index);
                    }
                });
                mLinearLayoutBody.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        mOnSelectCampaignListListener.onItemClicked(data, index);
                    }
                });
            }

//            mLinearLayoutPlus.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    CampaignData campaignData = new CampaignData(data.getId(), data.getDesc(), data.getProjectId(), data.getProjectName());
//                    mOnSettingMyHomeOkrListListener.onPlusClicked(campaignData);
//                }
//            });
        }
    }
}
