from PyQt6.QtWidgets import QMessageBox

from app.exceptions import CustomBaseError


class ErrorBox(QMessageBox):
    """
    Box for displaying an error.
    """

    def __init__(self, exception: CustomBaseError, traceback) -> None:
        super().__init__()
        self.exception = exception
        self.traceback = traceback
        self._init_error_box()

    def _init_error_box(self) -> None:
        self.setIcon(QMessageBox.Icon.Critical)
        self.setWindowTitle("Chyba")
        self.setText(
            self.exception.title if hasattr(self.exception, "title") else "Chyba"
        )
        self.setInformativeText(
            self.exception.message if hasattr(self.exception, "message") else ""
        )
        self.setDetailedText(self.traceback)
