{% extends "orga/mails/base.html" %}
{% load bootstrap4 %}
{% load i18n %}

{% block mail_content %}
    <form method="post">
        {% csrf_token %}
        <h2>{% translate "Mail Editor" %}</h2>
        {% bootstrap_form_errors form %}
        {% bootstrap_field form.recipients layout='event' %}
        {% if form.tracks %}{% bootstrap_field form.tracks layout='event' %}{% endif %}
        {% bootstrap_field form.submission_types layout='event' %}
        {% bootstrap_field form.submissions layout='event' %}
        {% bootstrap_field form.reply_to layout='event' %}
        {% bootstrap_field form.bcc layout='event' %}
        {% bootstrap_field form.subject layout='event' %}
        {% bootstrap_field form.text layout='event' %}
        {% if request.method == "POST" %}
            <fieldset class="mt-4">
                <legend>{% translate "E-mail preview" %}</legend>
                <div class="alert alert-info">
                    {% blocktranslate trimmed with count=mail_count %}
                        Roughly {{ count }} emails will be generated.
                    {% endblocktranslate %}
                </div>
                {% if form.warnings %}
                    <div class="alert alert-warning">
                        <span>
                            {% blocktranslate trimmed %}
                                You have placeholders in your email that are either not valid or not valid for every email!
                            {% endblocktranslate %}
                            <ul>{% for w in form.warnings %}<li>&#123;{{w}}}</li>{% endfor %}</ul>
                            {% blocktranslate trimmed %}
                                Emails where placeholders are invalid will <b>not</b> be created!
                                For example, if you are using {session_room}, but some proposals don't have a room yet, only emails for proposals with a scheduled room will be created.
                            {% endblocktranslate %}
                        </span>
                    </div>
                {% endif %}
                {% if output_warnings %}
                    <div class="alert alert-warning">
                        <span>
                            {% for key, value in output_warnings.items %}
                                {% if key == "empty_link" %}
                                    {% blocktranslate trimmed with titled=value %}
                                        You have an empty link in your email, labeled “{{ value }}”!
                                    {% endblocktranslate %}
                                {% endif %}
                            {% endfor %}
                        </span>
                    </div>
                {% endif %}
                <div class="tab-pane mail-preview-group">
                    {% for locale, out in output.items %}
                        <div lang="{{ locale }}" class="mail-preview">
                            <strong>{{ out.subject|safe }}</strong><br><br>
                            {{ out.html|safe }}
                        </div>
                    {% endfor %}
                </div>
            </fieldset>
        {% endif %}
        <div class="submit-group mt-3"><span></span>
            <span>
                <button type="submit" class="btn btn-lg btn-outline-info btn-save mr-2" name="action" value="preview">
                    {% translate "Preview email" %}
                </button>
                {% if request.method == "POST" %}
                    <button type="submit" class="btn btn-lg btn-success">{% translate "Send to outbox" %}</button>
                {% endif %}
            </span>
        </div>
    </form>
{% endblock %}
