{% extends 'logs/entry_base.html' %}

{% block entry_icons %}
    {% if data.state == 'pending' %}
        <span class="icon-alarm semantic-text warning"
              title="{% trans %}This email is pending and will be sent soon.{% endtrans %}"
              data-qtip-style="warning"></span>
    {% elif data.state == 'sent' %}
        <span class="icon-mail semantic-text success"
              title="{% trans %}This email has been sent.{% endtrans %}"
              data-qtip-style="success"></span>
    {% elif data.state == 'failed' %}
        <span class="icon-warning semantic-text error"
              title="{% trans %}Sending this email failed.{% endtrans %}"
              data-qtip-style="danger"></span>
    {% endif %}
{% endblock %}

{% block entry_detail_rows %}
    {% if data.from %}
        <tr class="i-table content">
            <td class="i-table caption log-caption">
                {% trans %}From{% endtrans %}
            </td>
            <td class="i-table value searchable">
                {{ data.from }}
            </td>
        </tr>
    {% endif %}
    {% if data.to %}
        <tr class="i-table content">
            <td class="i-table caption log-caption">
                {% trans %}To{% endtrans %}
            </td>
            <td class="i-table value searchable">
                {{ data.to|join(', ') }}
            </td>
        </tr>
    {% endif %}
    {% if data.cc %}
        <tr class="i-table content">
            <td class="i-table caption log-caption">
                CC
            </td>
            <td class="i-table value searchable">
                {{ data.cc|join(', ') }}
            </td>
        </tr>
    {% endif %}
    {% if data.bcc %}
        <tr class="i-table content">
            <td class="i-table caption log-caption">
                BCC
            </td>
            <td class="i-table value searchable">
                {{ data.bcc|join(', ') }}
            </td>
        </tr>
    {% endif %}
    {% if data.reply_to %}
        <tr class="i-table content">
            <td class="i-table caption log-caption">
                Reply-to
            </td>
            <td class="i-table value searchable">
                {{ data.reply_to|join(', ') }}
            </td>
        </tr>
    {% endif %}
    <tr class="i-table content">
        <td class="i-table caption log-caption">
            {% trans %}Subject{% endtrans %}
        </td>
        <td class="i-table value searchable">
            <p style="white-space: pre-wrap; word-break: break-word;">{{ data.subject }}</p>
        </td>
    </tr>
    <tr class="i-table content">
        <td class="i-table caption log-caption">
            {% trans %}Attachments{% endtrans %}
        </td>
        <td class="i-table value searchable">
            {% if data.attachments %}
                {{ data.attachments|join(', ') }}
            {% else %}
                <span class="text-muted">
                    {% trans %}No attachments{% endtrans %}
                </span>
            {% endif %}
        </td>
    </tr>
    <tr class="i-table content">
        <td class="i-table caption log-caption">
            {% trans %}Body{% endtrans %}
        </td>
        <td class="i-table value email-body">
            {% if data.content_type == 'text/plain' %}
                <pre class="mono">{{ data.body }}</pre>
            {% else %}
                <div class="html">{{ data.body | safe }}</div>
            {% endif %}
        </td>
    </tr>
    <tr class="i-table content">
        <td class="i-table caption log-caption">
            {% trans %}Status{% endtrans %}
        </td>
        <td class="i-table value">
            {% if data.state == 'pending' %}
                {# i18n: Status #}
                {% trans 'status' %}Pending{% endtrans %}
            {% elif data.state == 'sent' %}
                {# i18n: Status #}
                {% trans 'status' %}Sent{% endtrans %}
            {% elif data.state == 'failed' %}
                {# i18n: Status #}
                {% trans 'status' %}Failed{% endtrans %}
            {% endif %}
        </td>
    </tr>
    {% if entry.event %}
        <tr class="i-table content">
            <td class="i-table caption log-caption">
                {% trans %}Actions{% endtrans %}
            </td>
            <td class="i-table value">
                {%- set supports_attachments = (
                    data.get('attachments', [])|length == data.get('stored_attachments', [])|length
                ) -%}
                <button type="button"
                        class="i-button {% if data.state == 'failed' %}highlight{% endif %} icon-mail"
                        data-href="{{ url_for('.resend_email', entry) }}"
                        data-title="{% trans %}Re-send email{% endtrans %}"
                        data-success-event="indico:logsRefresh"
                        data-ajax-dialog
                        {% if data.state == 'pending' or not supports_attachments %}disabled{% endif %}
                        {% if not supports_attachments %}
                            title="{%- trans -%}Re-sending emails with attachments is not supported.{%- endtrans -%}"
                        {% elif data.state == 'pending' %}
                            title="{%- trans -%}This email has not been sent yet.{%- endtrans -%}"
                        {% endif %}>
                    {% trans %}
                        Re-send email
                    {% endtrans %}
                </button>
            </td>
        </tr>
    {% endif %}
{% endblock %}
