"""Theme registry for managing available themes."""

from unfamiliar.tui.themes.base import ThemeConfig


class ThemeRegistry:
    """Registry for theme configurations

    Created at app startup and passed to components that need themes.
    Each test can create its own isolated registry
    """

    def __init__(self) -> None:
        self._themes: dict[str, ThemeConfig] = {}

    def register(self, theme: ThemeConfig) -> None:
        """Register a theme. Raises ValueError if theme name is
        already in use.
        """
        if theme.name in self._themes:
            raise ValueError(f"Theme '{theme.name}' already registered")
        self._themes[theme.name] = theme

    def get(self, name: str) -> ThemeConfig:
        """Get a theme by name. Raises ValueError if not found"""
        if name not in self._themes:
            available = ", ".join(sorted(self._themes.keys())) or "none"
            raise ValueError(f"Unknown theme: '{name}'. Available: {available}")
        return self._themes[name]

    def list(self) -> list[str]:
        """Get a list of available theme names"""
        return sorted(self._themes.keys())
