package com.phlx.wool.ui.main;

import android.app.Application;
import android.os.Bundle;

import androidx.annotation.NonNull;


import com.phlx.wool.Configs;
import com.phlx.wool.data.Repository;
import com.phlx.wool.ui.base.MainBarVM;
import com.phlx.wool.ui.inventory.InventoryActivity;
import com.phlx.wool.ui.sync.activity.ClearActivity;
import com.phlx.wool.ui.sync.activity.DownloadActivity;
import com.phlx.wool.ui.sync.activity.UploadActivity;
import com.phlx.wool.ui.work.unit.UnitActivity;

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.SPUtils;

public class MainVM extends MainBarVM<Repository> {

    private static String unitSp;
    public SingleLiveEvent<Boolean> nullEvent = new SingleLiveEvent<>();

    public SingleLiveEvent<Boolean> drawerEvent = new SingleLiveEvent<>();

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

    }

    public void initToolbar() {
        setMainTitleText("首页");
    }

    @Override
    protected void mainOnClick() {
        super.mainOnClick();
        drawerEvent.call();
    }


    public BindingCommand OnMarkingClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            unitSp = SPUtils.getInstance().getString(Configs.SP_UNIT_NAME, "");
            if (unitSp.isEmpty()) {
                nullEvent.call();
            } else {
                Bundle mBundle = new Bundle();
                mBundle.putString("type", Configs.WORK_TYPE_M);
                startActivity(InventoryActivity.class, mBundle);
            }
        }
    });

    public BindingCommand OnQuarantineClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            unitSp = SPUtils.getInstance().getString(Configs.SP_UNIT_NAME, "");
            if (unitSp.isEmpty()) {
                nullEvent.call();
            } else {
                Bundle mBundle = new Bundle();
                mBundle.putString("type", Configs.WORK_TYPE_Q);
                startActivity(InventoryActivity.class, mBundle);
            }
        }
    });
    public BindingCommand OnHarmlessClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            unitSp = SPUtils.getInstance().getString(Configs.SP_UNIT_NAME, "");
            if (unitSp.isEmpty()) {
                nullEvent.call();
            } else {
                Bundle mBundle = new Bundle();
                mBundle.putString("type", Configs.WORK_TYPE_H);
                startActivity(InventoryActivity.class, mBundle);
            }
        }
    });


    public BindingCommand OnDownloadClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(DownloadActivity.class);
        }
    });
    public BindingCommand OnUploadClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(UploadActivity.class);
        }
    });


    public BindingCommand OnClearDataClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(ClearActivity.class);
        }
    });
    public BindingCommand OnSelectUnitClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(UnitActivity.class);
        }
    });
}
