package com.cooleshow.teacher.widgets;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.cooleshow.teacher.R;

/**
 * @author dengqw
 * @time 2022/6/30 18:37
 * @describe：
 **/
public class CourseSearchView extends FrameLayout {

    private TextView mTvAgency;
    private EditText mSearchEdit;
    private TextView mSearchBtn;
    private String mLeftSearchText;
    private String mSearchHintText;
    private String mSearchBtnText;

    public CourseSearchView(@NonNull Context context) {
        this(context, null);
    }

    public CourseSearchView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, -1);
    }

    public CourseSearchView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.course_search_style);
        mLeftSearchText = array.getString(R.styleable.course_search_style_left_search_text);
        mSearchHintText = array.getString(R.styleable.course_search_style_search_edit_hint);
        mSearchBtnText = array.getString(R.styleable.course_search_style_search_btn_text);
        array.recycle();

        initView();
    }

    private void initView() {
        View view = View.inflate(getContext(), R.layout.course_search_view, this);
        mTvAgency = view.findViewById(R.id.tv_agency);
        mSearchEdit = view.findViewById(R.id.search_edit);
        mSearchBtn = view.findViewById(R.id.search_btn);

        setLeftText(mLeftSearchText);
        setSearchHint(mSearchHintText);
        setBtnText(mSearchBtnText);
    }

    public void setLeftText(String text) {
        mTvAgency.setText(text);
    }

    public void setSearchHint(String hintText) {
        mSearchEdit.setHint(hintText);
    }

    public void setBtnText(String btnText) {
        mSearchBtn.setHint(btnText);
    }

    public TextView getLeftText() {
        return mTvAgency;
    }

    public EditText getSearchEdit() {
        return mSearchEdit;
    }

    public TextView getSearchBtn() {
        return mSearchBtn;
    }

    public void setOnSearchListener(View.OnClickListener listener) {
        mSearchBtn.setOnClickListener(listener);
    }

    public void setOnLeftClickListener(View.OnClickListener listener) {
        mTvAgency.setOnClickListener(listener);
    }
}
