package dev.bytevibe.hyperpoint;



import dev.bytevibe.hyperpoint.Utils.MyAlert;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.image.Image;
import javafx.stage.Stage;

public class Main extends Application {
    @Override
    public void start(Stage stage) throws Exception {
        try {
            Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));
            Scene scene = new Scene(root, 1300, 700);
            stage.setScene(scene);

            Image icon = new Image(getClass().getResourceAsStream("icon.png"));
            stage.setTitle("Hyperpoint");
            stage.getIcons().add(icon);
            stage.show();

            stage.setOnCloseRequest(event -> {this.logout(stage);});
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 窗口退出键对应的action
    public void logout(Stage stage) {

        MyAlert alert = new MyAlert(Alert.AlertType.CONFIRMATION);
        alert.setTitle("退出登录");
        alert.setHeaderText("您确定要退出登录吗？");
        alert.setContentText("点击确定退出登录，点击取消返回。");

        if (alert.showAndWait().orElse(null) == MyAlert.isOK()) {
            stage.close();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}