from unittest.mock import patch

from django.template import Context, Template
from django.test import RequestFactory, SimpleTestCase

from oxyan.themes.definitions import get_theme
from oxyan.themes.templatetags.oxyan import _render_optional_ai_assistant_widget


class OxyanThemesSmokeTests(SimpleTestCase):
    def test_theme_definition_loading(self):
        theme = get_theme("default")
        self.assertEqual(theme["primary_color"], theme["primary"])
        self.assertEqual(theme["secondary_color"], theme["secondary"])

    def test_optional_ai_assistant_widget_returns_empty_when_unavailable(self):
        request = RequestFactory().get("/")
        context = Context({"request": request})

        with patch(
            "oxyan.themes.templatetags.oxyan.import_module",
            side_effect=ImportError,
        ):
            self.assertEqual(_render_optional_ai_assistant_widget(context), "")

    def test_base_template_renders_without_ai_assistant_plugin(self):
        request = RequestFactory().get("/")
        template = Template(
            "{% load oxyan %}"
            "{% optional_ai_assistant_widget %}"
            "<div>base-smoke</div>"
        )

        with patch(
            "oxyan.themes.templatetags.oxyan.import_module",
            side_effect=ImportError,
        ):
            rendered = template.render(Context({"request": request}))

        self.assertIn("base-smoke", rendered)
