package com.zhangmeng.online.exam.ui.admin;

import com.zhangmeng.online.exam.ui.components.ExamButtonComponent;
import com.zhangmeng.online.exam.ui.components.ExamComponent;
import com.zhangmeng.online.exam.ui.components.ShortAnswerComponent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.stage.Window;

/**
 * @author zm
 * @date 2025/3/4 17:45
 * @version: 1.0
 */
public class LoginPage extends AnchorPane {

    /**
     * <columnConstraints>
     * <ColumnConstraints hgrow="SOMETIMES" maxWidth="229.0" minWidth="10.0" prefWidth="38.0" />
     * <ColumnConstraints hgrow="SOMETIMES" maxWidth="423.0" minWidth="10.0" prefWidth="248.0" />
     * </columnConstraints>
     * <rowConstraints>
     * <RowConstraints maxHeight="174.0" minHeight="10.0" prefHeight="60.0" vgrow="SOMETIMES" />
     * <RowConstraints maxHeight="206.0" minHeight="10.0" prefHeight="47.0" vgrow="SOMETIMES" />
     * <RowConstraints maxHeight="238.0" minHeight="10.0" prefHeight="52.0" vgrow="SOMETIMES" />
     * </rowConstraints>
     * <children>
     * <Label text="账号" />
     * <Label text="密码" GridPane.rowIndex="1" />
     * <TextField GridPane.columnIndex="1" />
     * <Button mnemonicParsing="false" prefHeight="23.0" prefWidth="178.0" text="登录" GridPane.columnIndex="1" GridPane.rowIndex="2" />
     * <PasswordField GridPane.columnIndex="1" GridPane.rowIndex="1" />
     * </children>
     */
    public LoginPage() {

        ColumnConstraints column1 = new ColumnConstraints();
        column1.setHgrow(Priority.SOMETIMES);
        column1.setMaxWidth(229.0);
        column1.setMinWidth(10.0);
        column1.setPrefWidth(38.0);

        ColumnConstraints column2 = new ColumnConstraints();
        column2.setHgrow(Priority.SOMETIMES);
        column2.setMaxWidth(423.0);
        column2.setMinWidth(10.0);
        column2.setPrefWidth(248.0);

        RowConstraints row1 = new RowConstraints();
        row1.setMaxHeight(174.0);
        row1.setMinHeight(10.0);
        row1.setPrefHeight(60.0);
        row1.setVgrow(Priority.SOMETIMES);

        RowConstraints row2 = new RowConstraints();
        row2.setMaxHeight(206.0);
        row2.setMinHeight(10.0);
        row2.setPrefHeight(47.0);
        row2.setVgrow(Priority.SOMETIMES);

        RowConstraints row3 = new RowConstraints();
        row3.setMaxHeight(238.0);
        row3.setMinHeight(10.0);
        row3.setPrefHeight(52.0);
        row3.setVgrow(Priority.SOMETIMES);

        //        <GridPane layoutX="485.0" layoutY="59.0" prefHeight="159.0" prefWidth="275.0" AnchorPane.bottomAnchor="97.0" AnchorPane.leftAnchor="125.0" AnchorPane.rightAnchor="127.0" AnchorPane.topAnchor="59.0">
        GridPane gridPane = new GridPane();
        gridPane.getColumnConstraints().addAll(column1, column2);
        gridPane.getRowConstraints().addAll(row1, row2, row3);
        gridPane.setLayoutX(485.0);
        gridPane.setLayoutY(59.0);
        gridPane.setPrefHeight(159.0);
        gridPane.setPrefWidth(275.0);
        AnchorPane.setBottomAnchor(gridPane, 97.0);
        AnchorPane.setLeftAnchor(gridPane, 125.0);
        AnchorPane.setRightAnchor(gridPane, 127.0);
        AnchorPane.setTopAnchor(gridPane, 59.0);

        Label label1 = new Label("账号");
        Label label2 = new Label("密码");
        TextField textField1 = new TextField();
        PasswordField passwordField1 = new PasswordField();
        Button button1 = new Button("登录");
        button1.setMnemonicParsing(false);
        button1.setPrefHeight(23.0);
        button1.setPrefWidth(178.0);

        gridPane.add(label1, 0, 0);
        gridPane.add(label2, 0, 1);
        gridPane.add(textField1, 1, 0);
        gridPane.add(passwordField1, 1, 1);
        gridPane.add(button1, 1, 2);

        getChildren().add(gridPane);

        button1.setOnAction(event -> {

            Scene scene = button1.getScene();
            Stage window = (Stage) scene.getWindow();
            window.close();

            Stage stage = new Stage();
//            IndexPage shortAnswerComponent = new IndexPage();

            PaperPage paperPage = new PaperPage();
            scene = new Scene(paperPage, 1280, 720);
            stage.setScene(scene);
            stage.setTitle("在线考试系统");
            stage.show();


        });

    }


}
