package com.example;

import java.io.IOException;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;

public class RegisterController {

    @FXML
    private Label mainTitle;

    @FXML
    private Button cartBtn;

    @FXML
    private Button loginBtn;

    @FXML
    private TextField nameInput;

    @FXML
    private TextField surnameInput;

    @FXML
    private TextField emailInput;

    @FXML
    private TextField phoneInput;

    @FXML
    private TextField streetInput;

    @FXML
    private TextField cityInput;

    @FXML
    private TextField cityCodeInput;

    @FXML
    private Button createAccountButton;

    @FXML
    private Label footerCopyText;

    @FXML
    private void handleCartButton() throws IOException {
        App.setRoot("cart");
    }

    @FXML
    private void handleLoginButton() throws IOException {
        App.setRoot("login");
    }

    @FXML
    private void handleCreateAccountButtonClick(MouseEvent event) {
        String name = nameInput.getText();
        String surname = surnameInput.getText();
        String email = emailInput.getText();
        String phone = phoneInput.getText();
        String street = streetInput.getText();
        String city = cityInput.getText();
        String cityCode = cityCodeInput.getText();

        if (validateForm(name, surname, email, phone, street, city, cityCode)) {
            System.out.println("Account created successfully!");
            System.out.println("Name: " + name + " " + surname);
            System.out.println("Email: " + email);
            System.out.println("Phone: " + phone);
            System.out.println("Address: " + street + ", " + city + " - " + cityCode);
            // Add logic to save user data or navigate to a new page
        } else {
            System.out.println("Please fill in all the fields correctly.");
        }
    }

    private boolean validateForm(String name, String surname, String email, String phone, String street, String city,
            String cityCode) {
        // Basic validation to ensure no fields are empty
        return !(name.isEmpty() || surname.isEmpty() || email.isEmpty() || phone.isEmpty() || street.isEmpty()
                || city.isEmpty() || cityCode.isEmpty());
    }
}
