package kr.co.hanwha.hifive.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.data.model.ProjectInfoData;

public class HFSettingMenuUnitView extends LinearLayout {
    private View mViewTopLine;
    private TextView mTextViewName;

    private ProjectInfoData mData;

    public HFSettingMenuUnitView(Context context) {
        super(context);
        initialize(context, null);
    }

    public HFSettingMenuUnitView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initialize(context, attrs);
    }

    public HFSettingMenuUnitView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initialize(context, attrs);
    }

    private void initialize(Context context, @Nullable AttributeSet attrs) {
        if (isInEditMode()) return;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.view_hf_setting_menu_unit, this, true);

        mViewTopLine = (View) findViewById(R.id.topLine_view);
        mTextViewName = (TextView) findViewById(R.id.name_textView);
    }

    public void setProjectInfoData(@NonNull ProjectInfoData data, boolean isFirstItem) {
        mData = data;
        if (data == null) return;

        mViewTopLine.setVisibility(isFirstItem ? View.GONE : View.VISIBLE);

        mTextViewName.setText(data.getProject_name());
    }

    public int getProjectId() {
        return mData != null ? mData.getProject_id() : 0;
    }
}