package kr.co.hanwha.hifive.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
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.util.HFCommonUtil;

/**
 * Created by sanghoonkwon on 2018. 1. 18..
 */

public class HFTabView extends LinearLayout {
    private TextView mTextViewTitle;
    private View mViewUnderline;

    public String mTitle;
    public boolean mVisibleCount;

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

    public HFTabView(Context context, String title, boolean visibleCount) {
        super(context);
        mTitle = title;
        mVisibleCount = visibleCount;
        initialize(context, null);
    }

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

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

    private void initialize(Context context, @Nullable AttributeSet attrs) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.view_hf_tab, this, true);

        mTextViewTitle = (TextView) findViewById(R.id.title_textView);
        mViewUnderline = (View) findViewById(R.id.underline_view);

        if (TextUtils.isEmpty(mTitle) == false)
            mTextViewTitle.setText(mTitle);
    }

    public void setText(@Nullable String text) {
        mTitle = text;
        if (TextUtils.isEmpty(mTitle) == false)
            mTextViewTitle.setText(mTitle);
    }

    public void setSelect(boolean select) {
        if (select) {
            mViewUnderline.setVisibility(View.VISIBLE);
            mTextViewTitle.setTextColor(HFCommonUtil.getColor(getContext(), R.color.black));
        } else {
            mViewUnderline.setVisibility(View.INVISIBLE);
            mTextViewTitle.setTextColor(HFCommonUtil.getColor(getContext(), R.color.gray_99));
        }
    }
}