package com.example;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

public class CartController {

    @FXML
    private Button cartBtn;

    @FXML
    private Button loginBtn;

    @FXML
    private Button btnCheckOut;

    @FXML
    private TableView<Item> cartContent;

    @FXML
    private TableColumn<Item, String> nameColumn;

    @FXML
    private TableColumn<Item, String> descriptionColumn;

    @FXML
    private TableColumn<Item, Integer> quantityColumn;

    @FXML
    private TableColumn<Item, Double> priceColumn;

    @FXML
    private Label cartTitle;

    @FXML
    private Label mainTitle;

    // Initialize method to set up the TableView
    @FXML
    public void initialize() {
        nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
        descriptionColumn.setCellValueFactory(new PropertyValueFactory<>("description"));
        quantityColumn.setCellValueFactory(new PropertyValueFactory<>("quantity"));
        priceColumn.setCellValueFactory(new PropertyValueFactory<>("price"));

        // Populate the table with some sample data (replace with actual logic later)
        cartContent.getItems().addAll(
                new Item("Book A", "A fascinating fantasy novel.", 1, 12.99),
                new Item("Book B", "A thrilling sequel.", 2, 10.50));
    }

    @FXML
    private void handleCartButton(ActionEvent event) {
        System.out.println("Cart button clicked!");
        // Add logic to navigate to the cart view or perform related actions
    }

    @FXML
    private void handleLoginButton(ActionEvent event) {
        System.out.println("Login button clicked!");
        // Add logic to open the login page or dialog
    }

    @FXML
    private void handleCheckOutButton(ActionEvent event) {
        System.out.println("Checkout button clicked!");
        // Add logic to proceed to checkout
    }

    // Inner class to represent items in the cart
    public static class Item {
        private String name;
        private String description;
        private int quantity;
        private double price;

        public Item(String name, String description, int quantity, double price) {
            this.name = name;
            this.description = description;
            this.quantity = quantity;
            this.price = price;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public int getQuantity() {
            return quantity;
        }

        public void setQuantity(int quantity) {
            this.quantity = quantity;
        }

        public double getPrice() {
            return price;
        }

        public void setPrice(double price) {
            this.price = price;
        }
    }
}
