{% extends 'admin_panel/base.html' %}

{% import 'macros/autoform.html' as autoform %}
{% import 'macros/form.html' as form %}

{% block breadcrumb_content %}
    <li>{% link_for _("Global settings"), named_route='mailcraft.config' %}</li>
{% endblock breadcrumb_content %}

{% block ap_content %}
    <h1>{{ _("Mailcraft configuration") }}</h1>

    <form method="POST">
        {% for _, config in configs.items() %}
            {% if config.type == "select" %}
                {{ form.select(config.key, label=config.label, options=config.options, selected=data[config.key] | int if data else config.value, error=errors[config.key]) }}
            {% elif config.type in ("text", "number") %}
                {{ form.input(config.key, label=config.label, value=data[config.key] if data else config.value, error=errors[config.key], type=config.type) }}
            {% else %}
                {{ form.textarea(config.key, label=config.label, value=data[config.key] if data else config.value, error=errors[config.key]) }}
            {% endif %}
        {% endfor %}

        <button type="submit" class="btn btn-primary">{{ _('Update') }}</button>
    </form>
{% endblock ap_content %}
