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

import android.support.annotation.NonNull;
import android.text.TextUtils;
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.base.BaseViewHolder;
import kr.co.hanwha.hifive.data.model.ProjectCampaignsInfo;
import kr.co.hanwha.hifive.util.HFDateUtil;

/**
 * Created by sanghoonkwon on 2018. 2. 20..
 */

public class MainProjectCampaignHeaderViewHolder extends BaseViewHolder {
    private LinearLayout mLayoutContainer;
    private TextView mTextViewGoalNumber;
    private TextView mTextViewTitle;
    private TextView mTextViewDueDate;
    private View mViewUnderline;
    private View mViewBottomMargin;

    public MainProjectCampaignHeaderViewHolder(@NonNull ViewGroup viewGroup) {
        super(viewGroup, R.layout.item_main_project_campaign_header);

        mLayoutContainer = (LinearLayout) itemView.findViewById(R.id.container_linearLayout);
        mTextViewGoalNumber = (TextView) itemView.findViewById(R.id.goalNumber_textView);
        mTextViewTitle = (TextView) itemView.findViewById(R.id.title_textView);
        mTextViewDueDate = (TextView) itemView.findViewById(R.id.dueDate_textView);
        mViewUnderline = (View) itemView.findViewById(R.id.underline_view);
        mViewBottomMargin = (View) itemView.findViewById(R.id.bottomMargin_view);
    }

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

        if (object != null && object instanceof ProjectCampaignsInfo) {
            ProjectCampaignsInfo data = (ProjectCampaignsInfo) object;
            mTextViewTitle.setText(data.getDesc());

            mTextViewGoalNumber.setText(Integer.toString(data.getNumber()));

            String duedate = HFDateUtil.getChangeDateFormat(data.getDue_to(), HFDateUtil.FORMAT_COMMON_SERVER, HFDateUtil.FORMAT_YYYY_MM_DD);
            mTextViewDueDate.setText(TextUtils.isEmpty(duedate) ? getContext().getString(R.string.main_project_campaign_unschduled) : duedate);


            if (taskCount > 0) {
                mLayoutContainer.setBackground(getContext().getResources().getDrawable(R.drawable.box_rounded_project_campaign_bg));
                mViewUnderline.setVisibility(View.VISIBLE);
                mViewBottomMargin.setVisibility(View.GONE);
            } else {
                mLayoutContainer.setBackground(getContext().getResources().getDrawable(R.drawable.box_rounded_project_campaign_bg_single));
                mViewUnderline.setVisibility(View.GONE);
                mViewBottomMargin.setVisibility(View.VISIBLE);
            }
        }
    }
}