"""CSS template system for Nhandu HTML output."""

from __future__ import annotations

from dataclasses import dataclass


@dataclass(frozen=True)
class Template:
    """A CSS-only HTML template for Nhandu reports."""

    name: str
    description: str
    css: str


# Global registry: name -> Template
_registry: dict[str, Template] = {}


def register(template: Template) -> None:
    """Register a template in the global registry."""
    _registry[template.name] = template


def get_template(name: str) -> Template:
    """Look up a template by name.

    @param name: Template name to look up.
    @return: The matching Template.
    @raise ValueError: If template name is not found.
    """
    if name not in _registry:
        available = ", ".join(sorted(_registry.keys()))
        raise ValueError(f"Unknown template '{name}'. Available templates: {available}")
    return _registry[name]


def list_templates() -> list[Template]:
    """Return all registered templates, sorted by name."""
    return [_registry[name] for name in sorted(_registry.keys())]


# Import template modules to trigger registration
from nhandu.templates import academic as _academic  # noqa: E402, F401
from nhandu.templates import corporate as _corporate  # noqa: E402, F401
from nhandu.templates import default as _default  # noqa: E402, F401
