from django.apps import AppConfig
from django.conf import settings

class DsgovConfig(AppConfig):
    name = "dsgov"
    verbose_name = "Design System Gov.br (Django)"

    def ready(self):
        """
        Registra automaticamente o context processor dsgov_init,
        se ainda não estiver presente.
        """
        try:
            templates = settings.TEMPLATES[0]["OPTIONS"]
            cps = templates.get("context_processors", [])
            cp = "dsgov.context_processors.dsgov_init"

            if cp not in cps:
                cps.append(cp)
        except Exception:
            # Evita travar o setup se o settings estiver incompleto
            pass