{% extends "_base.html" %}
{% load i18n %}
{% block content %}
    {% load static %}
    {% load widget_tweaks %}
    <form method="post" data-unsaved-warning>
        {% csrf_token %}
        <div class="flex justify-between mb-4">
            <h1 class="heading">
                {% if form.initial %}
                    {% with form.name.value as offer_template_name %}
                        {% blocktranslate trimmed %}
                            Edit offer template "{{ offer_template_name }}"
                        {% endblocktranslate %}
                    {% endwith %}
                {% else %}
                    {% translate "Create new offer template" %}
                {% endif %}
            </h1>
            {% if perms.cms.change_offertemplate %}
                {% if form.initial %}
                    <button class="btn">
                        {% translate "Save" %}
                    </button>
                {% else %}
                    <button class="btn">
                        {% translate "Create" %}
                    </button>
                {% endif %}
            {% endif %}
        </div>
        <div class="grid xl:grid-cols-2 gap-4">
            <div class="mb-4 rounded border border-solid border-blue-500 shadow-2xl bg-white">
                <div class="p-4 rounded bg-water-500">
                    <h3 class="heading font-bold text-black">
                        <i icon-name="star" class="mr-2"></i> {% translate "General Settings" %}
                    </h3>
                </div>
                <div class="px-4 pb-4 divide-y divide-gray-200 space-y-4">
                    <div>
                        <!-- General Options for offer_template management -->
                        <label for="{{ form.name.id_for_label }}">
                            {{ form.name.label }}
                        </label>
                        {% render_field form.name %}
                    </div>
                    <div>
                        <label for="{{ form.slug.id_for_label }}">
                            {{ form.slug.label }}
                        </label>
                        <div class="help-text">
                            {{ form.slug.help_text }}
                        </div>
                        {% render_field form.slug %}
                    </div>
                    <div>
                        <label for="{{ form.url.id_for_label }}">
                            {{ form.url.label }}
                        </label>
                        <div class="help-text">
                            {{ form.url.help_text }}
                        </div>
                        {% render_field form.url %}
                    </div>
                    <div>
                        <label for="{{ form.thumbnail.id_for_label }}">
                            {{ form.thumbnail.label }}
                        </label>
                        <div class="mb-2 text-s text-gray-600">
                            {{ form.thumbnail.help_text }}
                        </div>
                        {% render_field form.thumbnail %}
                    </div>
                    <div>
                        <label for="{{ form.supported_by_app_in_content.id_for_label }}"
                               class="flex items-center">
                            {% render_field form.supported_by_app_in_content %}
                            {{ form.supported_by_app_in_content.label }}
                        </label>
                        <div class="mb-2 text-s text-gray-600">
                            {{ form.supported_by_app_in_content.help_text }}
                        </div>
                    </div>
                    <div>
                        <label for="{{ form.is_zammad_form.id_for_label }}"
                               class="flex items-center">
                            {% render_field form.is_zammad_form %}
                            {{ form.is_zammad_form.label }}
                        </label>
                        <div class="mb-2 text-s text-gray-600">
                            {{ form.is_zammad_form.help_text }}
                        </div>
                    </div>
                </div>
            </div>
            <div class="mb-4 rounded border border-solid border-blue-500 shadow-2xl bg-white">
                <div class="p-4 rounded bg-water-500">
                    <h3 class="heading font-bold text-black">
                        <i icon-name="settings" class="mr-2"></i> {% translate "Extended Settings" %}
                    </h3>
                </div>
                <div class="px-4 pb-4 divide-y divide-gray-200 space-y-4">
                    <div>
                        <label for="{{ form.post_data.id_for_label }}">
                            {{ form.post_data.label }}
                        </label>
                        <div class="help-text">
                            {{ form.post_data.help_text }}
                        </div>
                        {% if form.post_data.value == "null" %}
                            {% render_field form.post_data value="{}" %}
                        {% else %}
                            {% render_field form.post_data %}
                        {% endif %}
                    </div>
                    <div>
                        <label for="{{ form.use_postal_code.id_for_label }}">
                            {{ form.use_postal_code.label }}
                        </label>
                        <div class="help-text">
                            {{ form.use_postal_code.help_text }}
                        </div>
                        {% render_field form.use_postal_code %}
                    </div>
                </div>
            </div>
        </div>
        {% if form.instance.id and perms.cms.delete_offertemplate %}
            {% if form.instance.regions.exists %}
                <button title="{% translate "This offer template cannot be deleted because it is used in at least one region." %}"
                        class="btn"
                        disabled>
                    <i icon-name="trash-2"></i>
                    {% translate "Delete this offer templates" %}
                </button>
            {% else %}
                <button title="{% translate "Delete language" %}"
                        class="btn confirmation-button btn-red"
                        data-confirmation-title="{{ delete_dialog_title }}"
                        data-confirmation-text="{{ delete_dialog_text }}"
                        data-confirmation-subject="{{ form.instance.name }}"
                        data-action="{% url 'delete_offertemplate' slug=form.instance.slug %}">
                    <i icon-name="trash-2"></i>
                    {% translate "Delete this offer templates" %}
                </button>
            {% endif %}
        {% endif %}
    </form>
    {% include "../generic_confirmation_dialog.html" %}
{% endblock content %}
