package com.phlx.anchorcollect_p.ui.main;

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

import androidx.annotation.NonNull;


import com.phlx.anchorcollect_p.Configs;
import com.phlx.anchorcollect_p.data.Repository;
import com.phlx.anchorcollect_p.db.DbUtil;
import com.phlx.anchorcollect_p.entity.DictEntity;
import com.phlx.anchorcollect_p.ui.base.MainBarVM;

import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;
import me.goldze.mvvmhabit.utils.ToastUtils;

public class MainVM extends MainBarVM<Repository> {

    public SingleLiveEvent<Integer> onTabClickEvent = new SingleLiveEvent<>();


    public MainVM(@NonNull Application application, Repository model) {
        super(application, model);
    }

    public void init() {

        Configs.dictList = DbUtil.getInstance().queryAll(DictEntity.class);

    }

    public void initToolbar(String title) {
        setBackTitleText(title);
        setBackRightTextVisible(View.VISIBLE);
        setBackTitleText(title);

    }


    //基础信息
    public BindingCommand OnBaseArchivesClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            onTabClickEvent.setValue(0);
        }
    });

    //性能测定
    public BindingCommand OnSignMeasureClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            if (Configs.tempUnid == null) {
                ToastUtils.showShort("请先扫描耳标");
                return;
            }
            onTabClickEvent.setValue(1);
        }
    });

    //称重管理
    public BindingCommand OnWeightingManageClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
//            if(StringUtils.isEmpty(Configs.tempUnid)){
//                ToastUtils.showShort("请先扫描耳标");
//                return;
//            }
//            onTabClickEvent.setValue(2);
        }
    });

    //诊疗记录
    public BindingCommand OnMedicalRecordClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            if (Configs.tempUnid == null) {
                ToastUtils.showShort("请先扫描耳标");
                return;
            }
            onTabClickEvent.setValue(3);
        }
    });

    //免疫记录
    public BindingCommand OnImmunRecordClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
//            if(StringUtils.isEmpty(Configs.tempUnid)){
//                ToastUtils.showShort("请先扫描耳标");
//                return;
//            }
            onTabClickEvent.setValue(4);
        }
    });

    //配种记录
    public BindingCommand OnBreedingRecordClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            if (Configs.tempUnid == null) {
                ToastUtils.showShort("请先扫描耳标");
                return;
            }
            onTabClickEvent.setValue(5);
        }
    });

}
