# Copyright (C) 2026 Linuxfabrik <info@linuxfabrik.ch>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# On Debian systems, the complete text of the GNU General Public License
# version 2 can be found in /usr/share/common-licenses/GPL-2.
#
# SPDX-License-Identifier: GPL-2.0-or-later

"""About dialog showing version and license information."""

from pathlib import Path

from PySide6.QtWidgets import QDialog

from firewallfabrik import __version__
from firewallfabrik.gui.ui_loader import FWFUiLoader


class AboutDialog(QDialog):
    def __init__(self, parent=None):
        super().__init__(parent)

        ui_path = Path(__file__).resolve().parent / 'ui' / 'aboutdialog_q.ui'
        loader = FWFUiLoader(self)
        loader.load(str(ui_path))

        # Fill in version info (mirrors C++ FWBAboutDialog.cpp)
        title_text = self.titleLbl.text().replace('%1', __version__)
        self.titleLbl.setText(title_text)

        self.adjustSize()

        if parent is not None:
            parent_center = parent.geometry().center()
            self.move(
                parent_center.x() - self.width() // 2,
                parent_center.y() - self.height() // 2,
            )
