"""Tests for helper functions."""
import pytest
from openslides import Brand, base_html, base_styles, clearbit_logo


class TestBaseHtml:
    """Test base_html helper."""

    def test_returns_doctype(self):
        """base_html starts with DOCTYPE."""
        brand = Brand()
        html = base_html(brand)
        assert html.startswith("<!DOCTYPE html>")

    def test_includes_google_fonts(self):
        """base_html includes Google Fonts link."""
        brand = Brand(font_headline="Syne", font_body="Inter")
        html = base_html(brand)
        assert "fonts.googleapis.com" in html
        assert "Syne" in html

    def test_sets_viewport(self):
        """base_html sets 1920x1080 viewport."""
        brand = Brand()
        html = base_html(brand)
        assert "1920px" in html
        assert "1080px" in html

    def test_sets_font_family(self):
        """base_html sets body font-family."""
        brand = Brand(font_body="Inter")
        html = base_html(brand)
        assert "Inter" in html

    def test_ends_before_body(self):
        """base_html ends with </head> (no body tag)."""
        brand = Brand()
        html = base_html(brand)
        assert html.strip().endswith("</head>")
        assert "<body" not in html


class TestBaseStyles:
    """Test base_styles helper."""

    def test_includes_headline_class(self):
        """base_styles includes .headline class."""
        brand = Brand(font_headline="Syne", text="#191919")
        styles = base_styles(brand)
        assert ".headline" in styles
        assert "Syne" in styles

    def test_includes_body_text_class(self):
        """base_styles includes .body-text class."""
        brand = Brand(font_body="Inter")
        styles = base_styles(brand)
        assert ".body-text" in styles
        assert "Inter" in styles

    def test_includes_accent_class(self):
        """base_styles includes .accent class with primary color."""
        brand = Brand(primary="#054dfe")
        styles = base_styles(brand)
        assert ".accent" in styles
        assert "#054dfe" in styles

    def test_includes_muted_class(self):
        """base_styles includes .muted class."""
        brand = Brand(muted="#6b6b6b")
        styles = base_styles(brand)
        assert ".muted" in styles
        assert "#6b6b6b" in styles

    def test_includes_card_class(self):
        """base_styles includes .card class with surface color."""
        brand = Brand(surface="#f8f8f8")
        styles = base_styles(brand)
        assert ".card" in styles
        assert "#f8f8f8" in styles

    def test_includes_btn_class(self):
        """base_styles includes .btn class with primary color."""
        brand = Brand(primary="#054dfe")
        styles = base_styles(brand)
        assert ".btn" in styles
        assert "#054dfe" in styles


class TestClearbitLogo:
    """Test clearbit_logo helper."""

    def test_generates_img_tag(self):
        """clearbit_logo returns img tag."""
        img = clearbit_logo("stripe.com")
        assert "<img" in img
        assert "logo.clearbit.com/stripe.com" in img

    def test_respects_size(self):
        """clearbit_logo applies size parameter."""
        img = clearbit_logo("stripe.com", size=64)
        assert "height:64px" in img

    def test_strips_www(self):
        """clearbit_logo strips www prefix."""
        img = clearbit_logo("www.stripe.com")
        assert "logo.clearbit.com/stripe.com" in img
        assert "www" not in img
