import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.text.Text;
import javafx.scene.control.CheckBox;




public class HotelApp extends Application {
    @Override
    public void start(Stage primaryStage){


        Label welcome = new Label("         Welcome to Grand Hotel!\n--- HOTEL MANAGEMENT SYSTEM ---");

        Button btbook = new Button();
        btbook.setText("1. Make a new booking");
        Button btbookDetails = new Button();
        btbookDetails.setText("2. View booking details");
        Button roomStatus = new Button();
        roomStatus.setText("3. View room status");
        Button hotelInfo = new Button("4. Hotel information");
        Button checkOut = new Button();
        checkOut.setText("5. Check Out From A Room");
        Button exitApp = new Button();
        exitApp.setText("6. Exit");


/// /////////////////////////////////////////////////
        //extra panes , variables, and needs

        HBox io1 = new HBox();
        HBox io2 = new HBox();


        Booking bookingfx = new Booking();
        Guests guestsfx = new Guests();
        Text text = new Text("V 0.231 Alpha Build");
        HBox textarea = new HBox();
        textarea.getChildren().add(text);
        textarea.setAlignment(Pos.BOTTOM_RIGHT);








        /// ///////////////////////////////////////////////////
        //SetOnActions section
        //1 make a new booking
        btbook.setOnAction(e -> {
//            bookingfx.book();

            Label ltextfield = new Label("Enter the number of guests:(min 1-max 9): ");
            TextField guestnum = new TextField();
            CheckBox discountbox = new CheckBox("Apply Discount");
            discountbox.setSelected(true);

            io1.getChildren().addAll(ltextfield,guestnum,discountbox);
            io1.setSpacing(10);
            guestnum.setOnAction(actionEvent -> {

                System.out.println("The User chose: " + guestnum.getText() +" guests!" + (discountbox.isSelected() ? " And Have Discounts":" They don't Have discounts :(" +"\n" +
                        "now i should see how many nights he will be staying"));


                guestsfx.setNumberOfGuests(Integer.parseInt(guestnum.getText()));


                io1.getChildren().removeAll();

                Label ltextfield2 = new Label("How many nights are you staying!");

                TextField nightsnum = new TextField();

                io1.getChildren().addAll(ltextfield2,nightsnum);

                nightsnum.setOnAction(actionEvent1 -> {

                    System.out.println("The User staying " + nightsnum.getText() + " nights" + "\n" +
                            "now we should give him the room options!");

                    bookingfx.nightsStayed = Integer.parseInt(nightsnum.getText());

                    //I have to sacrifice room allocation options as it is to tough to implement in UI and i don't know how to link it to UI

                    System.out.println("Due to an issue in our Hotel there is a high load on our double rooms you will transfered to "+ guestsfx.getNumberOfGuests() +" Single rooms!");

                    //now we calculate the bill

                    //single rooms *100 & nights * 35

                    int bill = (guestsfx.getNumberOfGuests() * 100) + (bookingfx.nightsStayed * 35) - (discountbox.isSelected() ? 25 : 0 );
                    String billtext = String.valueOf(bill);






                    //Now we need to show the bill

                    Text billshow = new Text("The Bill is: " + "$" + billtext + "!");
                    Button paynow = new Button("Pay NOW!");
                    paynow.setOnAction(actionEvent2 -> {
                        System.out.println("Please go to out Check-in Window");
                    primaryStage.close(); });

                    io2.setSpacing(20);


                    io2.getChildren().addAll(billshow,paynow);








                });









            });













        });

        //2 view booking details

       btbookDetails.setOnAction(e -> {
//           bookingfx.displayBookingDetails()
           text.setText("You have booked X number of Rooms");
       });
        //3 Room status

        roomStatus.setOnAction(e -> bookingfx.displayRoomStatus());

        //4 Hotel Info

        hotelInfo.setOnAction(e -> Hotel.displayInfo() );

        //5 checkout

        checkOut.setOnAction(e -> bookingfx.checkOutSpecificRoom());

        //6 exit
        exitApp.setOnAction(e -> {
            primaryStage.close();
            System.out.println("Thanks for using our App!");
        });
//
//        /// //////////////////////////////////////////////////

        HBox buttons = new HBox();
        buttons.getChildren().addAll(btbook,btbookDetails,roomStatus,hotelInfo,checkOut,exitApp);
        buttons.setSpacing(10);

        VBox startSystem = new VBox();
        startSystem.getChildren().addAll(welcome,buttons, io1,io2,textarea);
        startSystem.setSpacing(70);
        startSystem.setAlignment(Pos.TOP_CENTER);

        Scene scene = new Scene(startSystem,800,350);




        primaryStage.setScene(scene);
        primaryStage.show();


    }

    public static void main (String[] args){
        launch(args);

    }
}
