"""
Settings-driven configuration for the Zima theme's templates.

The theme is delivered almost entirely as static assets and template
overrides, so the few operator-tunable strings (Open Graph copy, optional
links) have nowhere to live but the templates. This tag exposes an
``AA_THEME_ZIMA`` settings dict to those templates so an installation can
override the defaults from its own ``local.py`` without forking the
theme's templates.

The tag is named ``zima_theme_var`` (not the generic ``theme_var``) so it never
collides with another installed theme's settings tag or with Alliance
Auth's own template-tag namespace.
"""

from __future__ import annotations

from django import template
from django.conf import settings

register = template.Library()


@register.simple_tag
def zima_theme_var(key: str, default: str = "") -> str:
    """
    Return ``AA_THEME_ZIMA[key]`` from settings, or ``default`` if unset.

    Usage (inline or assigned)::

        content="{% zima_theme_var 'OG_TITLE' SITE_NAME %}"

        {% zima_theme_var "SUPPORT_URL" as support_url %}
        {% if support_url %}<a href="{{ support_url }}">Support</a>{% endif %}

    The settings dict is optional: a deployment that never defines
    ``AA_THEME_ZIMA`` always receives the call's ``default``, so the
    theme's shipped templates render identically out of the box.
    """
    config = getattr(settings, "AA_THEME_ZIMA", {})
    return config.get(key, default)
