"""
Theme registration for Alliance Auth 5.

Alliance Auth 5 delivers themes through registered ``ThemeHook`` objects, not
through load-order template overrides: the authenticated shell
``allianceauth/base-bs5.html`` emits ``{% theme_css %}`` / ``{% theme_js %}``,
which render the assets of the theme the user picked in their profile. AA core
ships no Bootstrap itself, so each theme is a self-contained Bootstrap 5 build.

This module registers two complete themes, ``Zima Dark`` and ``Zima Light``;
the user selects one from the theme dropdown. Both serve the same compiled
Bootstrap 5 stylesheet from the package's own static files (via
``css_template``, so the URL goes through ``{% static %}``) and differ only by
the ``data-bs-theme`` set on the ``<html>`` tag: Bootstrap 5.3 emits both the
light (default) and dark (``[data-bs-theme="dark"]``) colour variables in one
build, so the attribute alone flips the mode. This mirrors Alliance Auth's own
built-in ``Bootstrap`` / ``Bootstrap Dark`` pair, which likewise share one
stylesheet. The dark/light split AA4 expressed through the ``NIGHT_MODE`` flag
is now two independent hooks.
"""

from allianceauth import hooks
from allianceauth.theme.hooks import ThemeHook

# Bootstrap 5 runtime JS (the ``bootstrap.bundle`` build already includes
# Popper) is theme-agnostic, so both Zima themes share it. It is served from
# the package's own static files via ``js_template`` — nothing is pulled from a
# CDN, keeping the theme fully self-contained and offline-capable.
ZIMA_JS_TEMPLATE = "aa_theme_zima/bundles/theme-js.html"


class ZimaDarkThemeHook(ThemeHook):
    """
    Zima theme, dark colour mode.

    Loads the dark Bootstrap-5 build from package static files and flags
    Bootstrap's dark mode via ``data-bs-theme``.
    """

    def __init__(self) -> None:
        """Register the dark variant with AA's theme machinery."""
        super().__init__(
            "Zima Dark",
            "Zima Corp theme (dark)",
            css=[],
            js=[],
            css_template="aa_theme_zima/bundles/theme-css.html",
            js_template=ZIMA_JS_TEMPLATE,
            html_tags={"data-theme": "zima-dark", "data-bs-theme": "dark"},
        )


class ZimaLightThemeHook(ThemeHook):
    """
    Zima theme, light colour mode.

    Loads the light Bootstrap-5 build from package static files and flags
    Bootstrap's light mode via ``data-bs-theme``.
    """

    def __init__(self) -> None:
        """Register the light variant with AA's theme machinery."""
        super().__init__(
            "Zima Light",
            "Zima Corp theme (light)",
            css=[],
            js=[],
            css_template="aa_theme_zima/bundles/theme-css.html",
            js_template=ZIMA_JS_TEMPLATE,
            html_tags={"data-theme": "zima-light", "data-bs-theme": "light"},
        )


# ``hooks.register`` is annotated as returning ``Optional``/untyped in
# Alliance Auth, so the type checker reads the decorator as a possible
# ``None`` call; the registration is the documented AA idiom and works at
# runtime, so the two reports are suppressed by code (not blanket-ignored).
@hooks.register("theme_hook")  # pyright: ignore[reportOptionalCall, reportUntypedFunctionDecorator]
def register_zima_dark_hook() -> ZimaDarkThemeHook:
    """Expose the dark Zima theme to AA's theme selector."""
    return ZimaDarkThemeHook()


@hooks.register("theme_hook")  # pyright: ignore[reportOptionalCall, reportUntypedFunctionDecorator]
def register_zima_light_hook() -> ZimaLightThemeHook:
    """Expose the light Zima theme to AA's theme selector."""
    return ZimaLightThemeHook()
