"""Top-level conveniences for the ESRF ID11 Status GUI."""

from __future__ import annotations

from typing import TYPE_CHECKING, Any

from .version import VERSION, VERSION_SHORT

__all__ = [
    "VERSION",
    "VERSION_SHORT",
    "__version__",
    "DatasetSelectionTab",
    "main",
    "statusGUI",
    "describe",
    "get_visitor_root",
    "set_visitor_root",
]
__version__ = VERSION

if TYPE_CHECKING:
    from esrf_statusgui.file_utils.paths import (
        describe,
        get_visitor_root,
        set_visitor_root,
    )
    from esrf_statusgui.visualization.statusGUI import DatasetSelectionTab, main

    statusGUI = main


def __getattr__(name: str) -> Any:
    """Lazily expose the public API to avoid importing heavy GUI modules on start-up."""
    if name in {"DatasetSelectionTab", "main", "statusGUI"}:
        from esrf_statusgui.visualization.statusGUI import DatasetSelectionTab, main

        globals().update(
            {
                "DatasetSelectionTab": DatasetSelectionTab,
                "main": main,
                "statusGUI": main,  # Backwards-compatible alias
            }
        )
        return globals()[name]

    if name in {"describe", "get_visitor_root", "set_visitor_root"}:
        from esrf_statusgui.file_utils.paths import (
            describe,
            get_visitor_root,
            set_visitor_root,
        )

        globals().update(
            {
                "describe": describe,
                "get_visitor_root": get_visitor_root,
                "set_visitor_root": set_visitor_root,
            }
        )
        return globals()[name]

    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


def __dir__() -> list[str]:
    return sorted(set(__all__))
