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

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

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.adapter.contract.SettingMyHomeOkrListContract;
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. 9. 18.
 */
public class SettingMyHomeOkrKeyResultViewHolder extends BaseViewHolder {
    private LinearLayout mLinearLayoutKeyResult;
    private TextView mTextViewKeyResult;
    private LinearLayout mLinearLayoutPlus;

    private MyHomeContract.OnSettingMyHomeOkrListListener mOnSettingMyHomeOkrListListener;

    public SettingMyHomeOkrKeyResultViewHolder(ViewGroup viewGroup, MyHomeContract.OnSettingMyHomeOkrListListener onSettingMyHomeOkrListListener) {
        super(viewGroup, R.layout.item_setting_my_home_okr_key_result);

        this.mOnSettingMyHomeOkrListListener = onSettingMyHomeOkrListListener;
        mLinearLayoutKeyResult = (LinearLayout) itemView.findViewById(R.id.key_result_linearLayout);
        mTextViewKeyResult = (TextView) itemView.findViewById(R.id.key_result_textView);
        mLinearLayoutPlus = (LinearLayout) itemView.findViewById(R.id.plus_linearLayout);
    }

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

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

            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());

            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);
                }
            });
        }
    }
}
