package com.imyeyu.fx.ui.examples.ctrl;

import com.imyeyu.fx.inject.FXTimiInject;
import com.imyeyu.fx.ui.components.TrayFX;
import com.imyeyu.fx.ui.examples.TimiFXExamples;
import com.imyeyu.fx.ui.examples.component.sidebar.Sidebar;
import com.imyeyu.fx.ui.examples.component.sidebar.SidebarItem;
import com.imyeyu.fx.ui.examples.service.PageService;
import com.imyeyu.fx.ui.examples.view.ViewMain;
import com.imyeyu.inject.annotation.Inject;
import javafx.stage.Stage;

import java.awt.SplashScreen;

/**
 * 主控
 *
 * @author 夜雨
 * @since 2022-05-03 15:43
 */
public class Main extends ViewMain {

	@Inject
	private TrayFX trayFX;

	@Inject
	private Sidebar sidebar;

	@Inject
	private PageService pageService;

	private Stage stage;

	@Override
	public void start(Stage stage) {
		this.stage = stage;

		TimiFXExamples.inject = FXTimiInject.run(TimiFXExamples.class, this, stage);
		super.start(stage);

		sidebar.setSelected(SidebarItem.WELCOME);

		// 主窗体尺寸
		config.getWidth().bind(stage.widthProperty());
		config.getHeight().bind(stage.heightProperty());

		if (SplashScreen.getSplashScreen() != null) {
			SplashScreen.getSplashScreen().close();
		}
	}

	@Override
	public void stop() {
		TimiFXExamples.getConfigLoader().dump();
		trayFX.remove();
		stage.close();
	}
}
