"""Tests for dashboard skins."""

from __future__ import annotations

from orxaq.experiences.skins.alpha import ALPHA_SKIN
from orxaq.experiences.skins.base import get_skin, list_skins
from orxaq.experiences.skins.beta import BETA_SKIN
from orxaq.experiences.skins.gamma import GAMMA_SKIN
from orxaq.experiences.skins.renderer import render_skin


class TestSkinRegistry:
    def test_three_skins_registered(self):
        skins = list_skins()
        assert len(skins) == 3

    def test_get_gamma(self):
        skin = get_skin("gamma")
        assert skin is not None
        assert skin.name == "gamma"

    def test_get_beta(self):
        skin = get_skin("beta")
        assert skin is not None
        assert skin.name == "beta"

    def test_get_alpha(self):
        skin = get_skin("alpha")
        assert skin is not None
        assert skin.name == "alpha"

    def test_get_nonexistent(self):
        assert get_skin("nonexistent") is None


class TestSkinProperties:
    def test_gamma_has_css_variables(self):
        assert "--bg-primary" in GAMMA_SKIN.css_variables
        assert "--text-primary" in GAMMA_SKIN.css_variables

    def test_beta_is_monospace(self):
        assert "monospace" in BETA_SKIN.css_variables["--font-family"]

    def test_beta_no_border_radius(self):
        assert BETA_SKIN.css_variables["--border-radius"] == "0px"

    def test_alpha_has_glass_blur(self):
        assert "--glass-blur" in ALPHA_SKIN.css_variables

    def test_all_skins_have_template(self):
        for skin in [GAMMA_SKIN, BETA_SKIN, ALPHA_SKIN]:
            assert skin.template_file.endswith(".html")

    def test_all_skins_have_display_name(self):
        for skin in [GAMMA_SKIN, BETA_SKIN, ALPHA_SKIN]:
            assert len(skin.display_name) > 0

    def test_skin_is_frozen(self):
        try:
            GAMMA_SKIN.name = "modified"
            assert False, "Should be frozen"
        except AttributeError:
            pass


class TestSkinRenderer:
    def test_render_gamma_returns_html(self):
        html = render_skin(GAMMA_SKIN)
        assert "<!DOCTYPE html>" in html
        assert "Gamma Observatory" in html

    def test_render_beta_has_overrides(self):
        html = render_skin(BETA_SKIN)
        assert "Command Engine" in html
        assert "monospace" in html

    def test_render_alpha_has_overrides(self):
        html = render_skin(ALPHA_SKIN)
        assert "Glass Cathedral" in html
        assert "backdrop-filter" in html

    def test_render_injects_css_variables(self):
        html = render_skin(BETA_SKIN)
        assert "--bg-primary" in html
        assert "#0a0a0a" in html

    def test_render_preserves_d3(self):
        html = render_skin(ALPHA_SKIN)
        assert "d3js.org" in html or "d3" in html.lower()
