#! python3  # noqa: E265

"""Authentication dialog logic."""

# standard
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING

# PyQGIS
from qgis.PyQt import uic
from qgis.PyQt.QtGui import QIcon

# Plugin
from oslandia.__about__ import DIR_PLUGIN_ROOT
from oslandia.gui.stylesheet import DialogStyleSheet


# only for type checking
if TYPE_CHECKING:
    from qgis.PyQt.QtWidgets import QWidget


class AuthenticationDialog(DialogStyleSheet):
    def __init__(self, parent: QWidget | None = None):
        """Dialog to define current connection as authentication config.

        :param parent: parent widget, defaults to None
        :type parent: QObject, optional
        """
        # init module and ui
        super().__init__(parent)
        uic.loadUi(Path(__file__).parent / f"{Path(__file__).stem}.ui", self)
        self.setWindowIcon(
            QIcon(str(DIR_PLUGIN_ROOT / "resources/images/connect.png")),
        )
        # When user is connected -> accept
        self.wdg_authent.user_connected.connect(self.accept)
