package com.phlx.anchorcollect.ui.base;

import android.app.Application;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableInt;


import com.phlx.anchorcollect.Configs;

import me.goldze.mvvmhabit.base.BaseModel;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.utils.SPUtils;
import me.goldze.mvvmhabit.utils.StringUtils;

/**
 * Create Date：2019/06/03
 */

public class MainBarVM<M extends BaseModel> extends BaseViewModel<M> {
    //标题文字设置
    public ObservableField<String> backTitle = new ObservableField<>("");
    //右边文字设置
    public ObservableField<String> backRightText = new ObservableField<>("");
    //返回按钮的观察者
    public ObservableInt backIconVisibleObservable = new ObservableInt(View.VISIBLE);
    //右边设置按钮的观察者
    public ObservableInt settingVisibleObservable = new ObservableInt(View.GONE);
    public ObservableInt searchVisibleObservable = new ObservableInt(View.GONE);
    public ObservableInt addVisibleObservable = new ObservableInt(View.GONE);
    //右边文字的观察者
    public ObservableInt backRightTextVisibleObservable = new ObservableInt(View.GONE);

    public MainBarVM mainBarVM;

    public MainBarVM(@NonNull Application application) {
        this(application, null);
        mainBarVM = this;
    }

    public MainBarVM(@NonNull Application application, M model) {
        super(application, model);
        mainBarVM = this;
    }

    /**
     * 设置标题
     *
     * @param text 标题文字
     */
    public void setBackTitleText(String text) {
        backTitle.set(text);
    }


    /**
     * 设置返回按钮的显示和隐藏
     *
     * @param visibility
     */
    public void setBackIconVisibleObservable(int visibility) {
        backIconVisibleObservable.set(visibility);
    }

    /**
     * 设置右边文字
     *
     * @param text 右边文字
     */
    public void setBackRightText(String text) {
        backRightText.set(text);
    }

    /**
     * 设置右边文字的显示和隐藏
     *
     * @param visibility
     */
    public void setBackRightTextVisible(int visibility) {
        backRightTextVisibleObservable.set(visibility);
    }

    /**
     * 添加按钮的显示和隐藏
     *
     * @param visibility
     */
    public void setAddVisibleObservable(int visibility) {
        addVisibleObservable.set(visibility);
    }

    /**
     * 设置按钮的显示和隐藏
     *
     * @param visibility
     */
    public void setSettingVisibleObservable(int visibility) {
        settingVisibleObservable.set(visibility);
    }
    /**
     * 搜索按钮的显示和隐藏
     *
     * @param visibility
     */
    public void setSearchVisibleObservable(int visibility) {
        searchVisibleObservable.set(visibility);
    }


    /**
     * 返回按钮的点击事件
     */
    public final BindingCommand backOnClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            backIconOnClick();
        }
    });

    /**
     * 添加按钮的点击事件
     */
    public BindingCommand addOnClick = new BindingCommand(this::addOnClick);


    /**
     * 设置按钮的点击事件
     */
    public BindingCommand settingOnClick = new BindingCommand(this::settingOnClick);

    /**
     * 文字的点击事件
     */
    public BindingCommand backRightTextOnClick = new BindingCommand(this::backRightTextOnClick);
    /**
     * 搜索按钮的点击事件
     */
    public BindingCommand searchOnClick = new BindingCommand(this::backSearchOnClick);


    /**
     * 搜索按钮点击事件，子类可重写
     */
    protected void backSearchOnClick() {
    }


    /**
     * 中间添加按钮点击事件，子类可重写
     */
    private void addOnClick() {
        //TODO
//        startActivity(SettingActivity.class);
    }
    /**
     * 右边设置按钮点击事件，子类可重写
     */
    private void settingOnClick() {
        //TODO
//        startActivity(SettingActivity.class);
    }

    /**
     * 文字的点击事件，子类可重写
     */
    protected void backRightTextOnClick() {

    }

    protected void backIconOnClick() {
        MainBarVM.this.finish();
    }


}
