"""The ONLY place binding-specific (PySide6 / PyQt6) code lives.

Prefers **PySide6** (LGPL) and falls back to PyQt6, re-exporting a normalized
surface so the rest of the GUI never branches on the binding. ``pyqtSignal`` is
aliased to PySide's ``Signal`` under PySide6. Set ``ABAX_QT_BINDING=PyQt6`` to
force PyQt6 (e.g. for testing); the default order is PySide6 then PyQt6.

Every Qt name any GUI module needs is imported here and re-exported — no other
module may ``import PySide6``/``PyQt6`` directly, so the app runs unchanged on
either binding.
"""

from __future__ import annotations

import os

BINDING: str

_FORCE = os.environ.get("ABAX_QT_BINDING", "")

try:
    if _FORCE == "PyQt6":
        raise ImportError("ABAX_QT_BINDING=PyQt6")
    from PySide6.QtCore import (
        QAbstractTableModel,
        QEvent,
        QItemSelection,
        QItemSelectionModel,
        QModelIndex,
        QObject,
        QPoint,
        QPointF,
        QRect,
        QRectF,
        QSize,
        QStringListModel,
        Qt,
        QThread,
        QTimer,
    )
    from PySide6.QtCore import Signal as pyqtSignal  # type: ignore
    from PySide6.QtGui import (
        QAction,
        QBrush,
        QColor,
        QFont,
        QFontDatabase,
        QFontMetricsF,
        QIcon,
        QImage,
        QKeyEvent,
        QKeySequence,
        QLinearGradient,
        QPainter,
        QPainterPath,
        QPen,
        QPixmap,
    )
    from PySide6.QtWidgets import (
        QAbstractItemDelegate,
        QAbstractItemView,
        QApplication,
        QCheckBox,
        QColorDialog,
        QComboBox,
        QCompleter,
        QDialog,
        QDialogButtonBox,
        QDockWidget,
        QFileDialog,
        QFormLayout,
        QGridLayout,
        QHBoxLayout,
        QInputDialog,
        QLabel,
        QLineEdit,
        QListWidget,
        QMainWindow,
        QMenu,
        QMessageBox,
        QPlainTextEdit,
        QProgressBar,
        QPushButton,
        QSplitter,
        QStatusBar,
        QStyledItemDelegate,
        QTabBar,
        QTableView,
        QTableWidget,
        QTableWidgetItem,
        QTableWidgetSelectionRange,
        QToolTip,
        QVBoxLayout,
        QWidget,
    )

    BINDING = "PySide6"
except ImportError:  # pragma: no cover - depends on which binding is installed
    from PyQt6.QtCore import (
        QAbstractTableModel,
        QEvent,
        QItemSelection,
        QItemSelectionModel,
        QModelIndex,
        QObject,
        QPoint,
        QPointF,
        QRect,
        QRectF,
        QSize,
        QStringListModel,
        Qt,
        QThread,
        QTimer,
        pyqtSignal,  # type: ignore
    )
    from PyQt6.QtGui import (
        QAction,
        QBrush,
        QColor,
        QFont,
        QFontDatabase,
        QFontMetricsF,
        QIcon,
        QImage,
        QKeyEvent,
        QKeySequence,
        QLinearGradient,
        QPainter,
        QPainterPath,
        QPen,
        QPixmap,
    )
    from PyQt6.QtWidgets import (
        QAbstractItemDelegate,
        QAbstractItemView,
        QApplication,
        QCheckBox,
        QColorDialog,
        QComboBox,
        QCompleter,
        QDialog,
        QDialogButtonBox,
        QDockWidget,
        QFileDialog,
        QFormLayout,
        QGridLayout,
        QHBoxLayout,
        QInputDialog,
        QLabel,
        QLineEdit,
        QListWidget,
        QMainWindow,
        QMenu,
        QMessageBox,
        QPlainTextEdit,
        QProgressBar,
        QPushButton,
        QSplitter,
        QStatusBar,
        QStyledItemDelegate,
        QTabBar,
        QTableView,
        QTableWidget,
        QTableWidgetItem,
        QTableWidgetSelectionRange,
        QToolTip,
        QVBoxLayout,
        QWidget,
    )

    BINDING = "PyQt6"

__all__ = [
    "BINDING",
    "QAbstractTableModel",
    "QEvent",
    "QItemSelection",
    "QItemSelectionModel",
    "QModelIndex",
    "QObject",
    "QPoint",
    "QPointF",
    "QRect",
    "QRectF",
    "QSize",
    "Qt",
    "QStringListModel",
    "QThread",
    "QTimer",
    "pyqtSignal",
    "QAction",
    "QBrush",
    "QColor",
    "QFont",
    "QFontDatabase",
    "QFontMetricsF",
    "QIcon",
    "QImage",
    "QKeyEvent",
    "QKeySequence",
    "QLinearGradient",
    "QPainter",
    "QPainterPath",
    "QPen",
    "QPixmap",
    "QAbstractItemDelegate",
    "QAbstractItemView",
    "QSplitter",
    "QApplication",
    "QCompleter",
    "QDialog",
    "QDockWidget",
    "QFileDialog",
    "QInputDialog",
    "QLabel",
    "QLineEdit",
    "QMainWindow",
    "QMenu",
    "QMessageBox",
    "QProgressBar",
    "QStatusBar",
    "QStyledItemDelegate",
    "QTabBar",
    "QTableView",
    "QTableWidget",
    "QTableWidgetItem",
    "QTableWidgetSelectionRange",
    "QToolTip",
    "QVBoxLayout",
    "QWidget",
]
