package com.example;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;

public class CheckOutController {

    @FXML
    private Label mainTitle;

    @FXML
    private Button cartBtn;

    @FXML
    private Button loginBtn;

    @FXML
    private Label checkoutHeader;

    @FXML
    private Label paymentTitle;

    @FXML
    private Label paymentSubtitle;

    @FXML
    private Button creditCard;

    @FXML
    private Button bill;

    @FXML
    private Button paypal;

    @FXML
    private TextField fullNameField;

    @FXML
    private TextField addressField;

    @FXML
    private TextField cityField;

    @FXML
    private TextField zipField;

    @FXML
    private ComboBox<String> countryComboBox;

    @FXML
    private TextField cardNumberField;

    @FXML
    private TextField cardHolderNameField;

    @FXML
    private TextField expiryDateField;

    @FXML
    private PasswordField cvvField;

    @FXML
    private Button submitButton;

    public void initialize() {
        // Initialize the country combo box with some values
        countryComboBox.getItems().addAll("United States", "Canada", "United Kingdom", "Germany", "Australia");
        countryComboBox.getSelectionModel().selectFirst();
    }

    @FXML
    private void handleCartButton(ActionEvent event) {
        System.out.println("Cart button clicked.");
        // Logic to navigate to the cart page
    }

    @FXML
    private void handleLoginButton(ActionEvent event) {
        System.out.println("Login button clicked.");
        // Logic to navigate to the login page
    }

    @FXML
    private void handlePaymentMethod(ActionEvent event) {
        Button clickedButton = (Button) event.getSource();
        System.out.println("Selected payment method: " + clickedButton.getId());
        // Highlight the selected payment method or save the selection
    }

    @FXML
    private void handleSubmit(ActionEvent event) {
        System.out.println("Submit button clicked.");

        String fullName = fullNameField.getText();
        String address = addressField.getText();
        String city = cityField.getText();
        String zip = zipField.getText();
        String country = countryComboBox.getValue();
        String cardNumber = cardNumberField.getText();
        String cardHolderName = cardHolderNameField.getText();
        String expiryDate = expiryDateField.getText();
        String cvv = cvvField.getText();

        // Validate the input fields
        if (fullName.isEmpty() || address.isEmpty() || city.isEmpty() || zip.isEmpty() || cardNumber.isEmpty()
                || cardHolderName.isEmpty() || expiryDate.isEmpty() || cvv.isEmpty()) {
            System.out.println("Please fill out all fields.");
        } else {
            System.out.println("Form submitted successfully.");
            System.out.printf("Billing Info: %s, %s, %s, %s, %s\n", fullName, address, city, zip, country);
            System.out.printf("Credit Card Info: %s, %s, %s, CVV: %s\n", cardNumber, cardHolderName, expiryDate, cvv);
        }
    }
}
