{% extends 'events/management/base.html' %}

{% from 'message_box.html' import message_box %}

{% set pending_reminders = reminders|rejectattr('is_sent')|list %}
{% set sent_reminders = reminders|selectattr('is_sent')|list %}
{% set tzinfo = event.tzinfo %}

{% block title %}
    {% trans %}Reminders{% endtrans %}
{% endblock %}

{% macro render_reminders(reminders) %}
    <ul class="group-list with-buttons no-content-before">
        {% for reminder in reminders %}
            <li>
                <strong>
                    <a data-href="{{ url_for('.edit', reminder) }}"
                       data-title="{{ _("Reminder details") if reminder.is_sent else _("Edit reminder")}}"
                       data-ajax-dialog
                       data-reload-after>
                        {%- if reminder.is_start_time_relative -%}
                            {{ reminder.event_start_delta|format_human_timedelta('hours') }} before the event
                        {%- elif reminder.is_end_time_relative -%}
                            {{ reminder.event_end_delta|format_human_timedelta('hours') }} after the event
                        {%- else -%}
                            {{ reminder.scheduled_dt|format_datetime(timezone=tzinfo) }} <small>({{ tzinfo }})</small>
                        {%- endif -%}
                    </a>
                    {% if reminder.is_relative %}
                        <i class="icon-alarm" title="{{ reminder.scheduled_dt|format_datetime(timezone=tzinfo) }} ({{ tzinfo }})"></i>
                    {% endif %}
                </strong>
                {% if not reminder.is_sent %}
                    <span class="right hide-if-locked">
                        <button class="i-button"
                                data-method="POST" data-href="{{ url_for('.delete', reminder) }}"
                                data-title="{% trans %}Delete reminder{% endtrans %}"
                                data-confirm="{% trans %}Do you really want to delete this reminder?{% endtrans %}">
                            {%- trans %}Delete{% endtrans -%}
                        </button>
                    </span>
                {% endif %}
            </li>
        {% endfor %}
    </ul>
{% endmacro %}

{% block content %}
    {% if event.is_not_happening %}
        {% call message_box('info') %}
            {% trans label=event.get_label_markup() %}
                Since this event has the {{ label }} label, no reminders will be sent for it.
            {% endtrans %}
        {% endcall %}
    {% endif %}

    <div class="i-box-group vert fixed-width reminders">
        <div class="i-box">
            <div class="i-box-header">
                <div class="i-box-title">{%- trans %}Pending reminders{% endtrans -%}</div>
                <div class="i-box-buttons toolbar right hide-if-locked">
                    <div class="group">
                        <button class="i-button icon-plus"
                                data-href="{{ url_for('.add', event, reminder_type='custom') }}"
                                data-title="{%- trans %}Add custom reminder{% endtrans -%}"
                                data-ajax-dialog
                                data-reload-after>
                            {%- trans %}Add custom reminder{% endtrans -%}
                        </button>
                    </div>
                    <div class="group">
                        <button class="i-button icon-plus"
                                data-href="{{ url_for('.add', event, reminder_type='standard') }}"
                                data-title="{%- trans %}Add standard reminder{% endtrans -%}"
                                data-ajax-dialog
                                data-reload-after>
                            {%- trans %}Add standard reminder{% endtrans -%}
                        </button>
                    </div>
                </div>
            </div>
            <div class="i-box-content">
                {% if pending_reminders %}
                    {{ render_reminders(pending_reminders) }}
                {% else %}
                    <span class="empty">{% trans %}There are no pending reminders.{% endtrans %}</span>
                {% endif %}
            </div>
        </div>
        {% if sent_reminders %}
            <div class="i-box">
                <div class="i-box-header">
                    <div class="i-box-title">{%- trans %}Sent reminders{% endtrans -%}</div>
                </div>
                <div class="i-box-content">
                    {{ render_reminders(sent_reminders) }}
                </div>
            </div>
        {% endif %}
    </div>
{% endblock %}
