from django.contrib.auth import get_user_model
from django.core.management import call_command
from django.test import TestCase
from django.urls import reverse


class BackofficeVisualTests(TestCase):
    @classmethod
    def setUpTestData(cls):
        cls.user = get_user_model().objects.create_superuser(
            "visual-admin", "visual@example.com", "test-password"
        )
        call_command("seed_demo_data", verbosity=0)

    def setUp(self):
        self.client.force_login(self.user)

    def test_main_changelists_use_visual_header(self):
        urls = [
            "admin:clients_client_changelist",
            "admin:services_service_changelist",
            "admin:domains_domain_changelist",
            "admin:hosting_hostingaccount_changelist",
            "admin:websites_websiteproject_changelist",
            "admin:billing_renewal_changelist",
            "admin:billing_payment_changelist",
            "admin:notifications_notificationlog_changelist",
            "admin:operations_internaltask_changelist",
            "admin:support_supportticket_changelist",
            "admin:technical_technicalasset_changelist",
            "admin:core_document_changelist",
        ]
        for url_name in urls:
            with self.subTest(url_name=url_name):
                response = self.client.get(reverse(url_name))
                self.assertEqual(response.status_code, 200)
                self.assertContains(response, "portal-admin-hero")
                self.assertContains(response, "portal-admin-stats")

    def test_add_form_uses_visual_header_and_tabs(self):
        response = self.client.get(reverse("admin:services_service_add"))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "portal-form-hero")
        self.assertContains(response, "Novo Serviço")
        self.assertContains(response, "Identificação comercial")
