package com.hmsoft.app;

import java.util.Optional;

import com.alibaba.fastjson.JSON;
import com.hmsoft.bizpanel.HisPubTab;
import com.hmsoft.bizpanel.MtzjTab;
import com.hmsoft.bizpanel.SysTab;
import com.hmsoft.common.AppConst;
import com.hmsoft.common.MsgTypeConst;
import com.hmsoft.model.request.BizRequest;
import com.hmsoft.remote.rmi.exception.RemotingException;
import com.hmsoft.remote.rmi.model.Message;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

/**
 * 征集客户端.
 * @author zq
 *
 */
public class Main extends Application {
	
	//public static AbstractClient CLIENT = null;
	public static Long LOGIN_SCHOOL_ID = null;//当前登录的学校ID,从登录获取
	public static String LOGIN_SCHOOL_NAME = null;
	public static Stage MAIN_STAGE = null;
	
	@Override
	public void start(final Stage primaryStage) {
		MAIN_STAGE = primaryStage;
		try {
			primaryStage.setTitle("命题征集客户端 1.0");
			BorderPane root = new BorderPane();
			Scene scene = new Scene(root);
			scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
			
			Rectangle2D screen = Screen.getPrimary().getVisualBounds();
			primaryStage.setX(screen.getMinX());
			primaryStage.setY(screen.getMinY());
			primaryStage.setWidth(screen.getWidth());
			primaryStage.setHeight(screen.getHeight());
			
			TabPane tabPane = new TabPane();
			
			Tab sysTab = new SysTab(primaryStage);
			tabPane.getTabs().add(sysTab);
			tabPane.setMinWidth(150);
			
			Tab mtzjTab = new MtzjTab(primaryStage);
			tabPane.getTabs().add(mtzjTab);
			tabPane.setMinWidth(150);
			
			Tab hisTab = new HisPubTab(primaryStage);
			tabPane.getTabs().add(hisTab);
			tabPane.setMinWidth(150);
			root.setCenter(tabPane);
			
			primaryStage.setResizable(false);
			//primaryStage.setAlwaysOnTop(true);//始终最上面
			primaryStage.setScene(scene);
			primaryStage.show();
			primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
				@Override
				public void handle(WindowEvent event) {
					closeHandleFunc(primaryStage, event);
				}
			});
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	protected void closeHandleFunc(Stage primaryStage, WindowEvent event) {
		Alert confirm = new Alert(Alert.AlertType.CONFIRMATION,
				"", 
				new ButtonType("否", ButtonData.NO),
                new ButtonType("是", ButtonData.YES));
		confirm.setTitle("请确认");
		confirm.setHeaderText("是否关闭？");
		confirm.initOwner(primaryStage);
		Optional<ButtonType> btnType = confirm.showAndWait();
		if (btnType.get().getButtonData().equals(ButtonData.YES)) {
			//close
		} else {
			event.consume();
		}
		
	}

}
