{% extends "pretixcontrol/event/base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load humanize %}
{% block title %}{% trans "Send out emails" %}{% endblock %}
{% block content %}
    <h1>
        {% trans "Send out emails" %}
        <small>{{ view_title }}</small>
    </h1>
    {% block inner %}
        <form class="form-horizontal" method="post" action="" enctype="multipart/form-data">
            {% csrf_token %}
            {% if is_preview %}
                {% for k, l in request.POST.lists %}
                    {% if k != "action" %}
                        {% for v in l %}
                            <input type="hidden" name="{{ k }}" value="{{ v }}">
                        {% endfor %}
                    {% endif %}
                {% endfor %}
            {% endif %}
            {% bootstrap_form_errors form %}
            <fieldset>
                <legend>{% trans "Recipients" %}</legend>
                {% include form_fragment_name with form=form %}
            </fieldset>
            <fieldset {% if is_preview %}class="hidden"{% endif %}>
                <legend>{% trans "Content" %}</legend>
                {% bootstrap_field form.subject layout='horizontal' %}
                {% bootstrap_field form.message layout='horizontal' %}
                {% bootstrap_field form.attachment layout='horizontal' %}
                {% if form.attach_tickets %}
                    {% bootstrap_field form.attach_tickets layout='horizontal' %}
                {% endif %}
                {% if form.attach_ical %}
                    {% bootstrap_field form.attach_ical layout='horizontal' %}
                {% endif %}
            </fieldset>
            {% if is_preview %}
            <fieldset>
                <legend>{% trans "E-mail preview" %}</legend>
                <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 }}
                            {% if out.attachment %}
                                <p>
                                    <a href="{% url 'cachedfile.download' id=out.attachment.id %}" class="btn btn-default"
                                            target="_blank">
                                        <span class="fa fa-file" aria-hidden="true"></span>
                                        {{ out.attachment.filename }}
                                    </a>
                                </p>
                            {% endif %}
                            {% if form.cleaned_data.attach_tickets %}
                                <p>
                                    <span class="fa fa-file" aria-hidden="true"></span>
                                    {% trans "Tickets" %}
                                </p>
                            {% endif %}
                            {% if form.cleaned_data.attach_ical %}
                                <p>
                                    <span class="fa fa-file" aria-hidden="true"></span>
                                    {% trans "Attach calendar files" %}
                                </p>
                            {% endif %}
                        </div>
                    {% endfor %}
                </div>
            </fieldset>
            {% endif %}
            <div class="form-group submit-group">
                {% if not is_preview %}
                    {% trans "You need to preview your email before you can send it." %}
                    &nbsp;&nbsp;
                    <button type="submit" class="btn btn-default btn-save" name="action" value="preview">
                        {% trans "Preview email" %}
                    </button>
                {% else %}
                    <button type="submit" class="btn btn-default btn-save pull-left" name="action" value="edit">
                        <span class="fa fa-edit" aria-hidden="true"></span>
                        {% trans "Edit" %}
                    </button>
                    <button type="submit" class="btn btn-danger btn-save" name="action" value="send">
                        <span class="fa fa-send" aria-hidden="true"></span>
                        {% trans "Send" %} ({{ match_size }})
                    </button>
                {% endif %}
            </div>
        </form>
    {% endblock %}
{% endblock %}
