package ch.pizzalemon.android.view;

import android.content.Context;
import android.content.res.TypedArray;
import androidx.core.content.ContextCompat;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import ch.pizzalemon.android.R;
import ch.pizzalemon.android.activity.BaseActivity;

/**
 * Created by cimenmus on 26.10.2017.
 */

public class AppDropdownView extends LinearLayout {

    private View rootView;
    private TextView hintTextView;
    private TextView textview;
    private RelativeLayout bottomLineLayout;
    private String hint;
    private String dropdownTheme;

    public AppDropdownView(Context context) {
        super(context);
        init(context);
    }

    public AppDropdownView(Context context, AttributeSet attrs) {
        super(context, attrs);

        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AppDropdownView, 0, 0);
        try {
            hint = a.getString(R.styleable.AppDropdownView_dropdownHintView);
            dropdownTheme = a.getString(R.styleable.AppDropdownView_dropdownTheme);
        } finally {
            a.recycle();
        }

        init(context);
    }

    private void init(Context context) {
        rootView = (View) inflate(context, R.layout.layout_pizzalink_drowdown_view, this);
        hintTextView = (TextView) rootView.findViewById(R.id.hintTextView);
        textview = (TextView) rootView.findViewById(R.id.textview);
        bottomLineLayout = (RelativeLayout) rootView.findViewById(R.id.bottomLineLayout);
        hintTextView.setText(hint);
        if(dropdownTheme != null && dropdownTheme.equals("navy")){
            int navyColor = ContextCompat.getColor(BaseActivity.currentActivity, R.color.navigation_drawer_background);
            hintTextView.setTextColor(navyColor);
            textview.setTextColor(navyColor);
            bottomLineLayout.setBackgroundColor(navyColor);
        }
    }

    public boolean isEmpty(){
        return hintTextView.getText().toString().isEmpty();
    }

    public String getText(){
        return hintTextView.getText().toString();
    }

    public void setText(String text){
        textview.setText(text);
    }
}
