from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QHBoxLayout
from typing import final
import sys

from Movie import movies
from MovieView import MovieView
from MovieButton import MovieButton

# Main Window
@final
class MainWindow(QMainWindow):
    """
    The main window for Max's movie tickets application.
    Usage:
        window = MainWindow()
        window.show()
    """

    currentMovie: MovieView | None = None

    def __init__(self):
        super().__init__()

        self.setWindowTitle("Cinema Tickets")

        # Create the layout for all the movies
        layout = QHBoxLayout()

        # Create the buttons for each movie
        self.spiderman = MovieButton(movies["spiderman"], self.buySpiderman)
        layout.addWidget(self.spiderman)
        self.cars = MovieButton(movies["cars2"], self.buyCars)
        layout.addWidget(self.cars)
        self.leo = MovieButton(movies["leo"], self.buyLeo)
        layout.addWidget(self.leo)
        self.hairypotty = MovieButton(movies["hairypotty"], self.buyHairyPotty)
        layout.addWidget(self.hairypotty)

        centralWidget = QWidget()
        centralWidget.setLayout(layout)
        self.setCentralWidget(centralWidget)

    # Callback functions to set the movie
    def buySpiderman(self):
        self.currentMovie = MovieView(movies["spiderman"])
        self.currentMovie.show()

    def buyLeo(self):
        self.currentMovie = MovieView(movies["leo"])
        self.currentMovie.show()

    def buyCars(self):
        self.currentMovie = MovieView(movies["cars2"])
        self.currentMovie.show()

    def buyHairyPotty(self):
        self.currentMovie = MovieView(movies["hairypotty"])
        self.currentMovie.show()
        

app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())
