{% extends 'rb/emails/base_email.html' %}


{% block header_recipient %}{% trans name=user.first_name %}Dear {{ name }},{% endtrans %}{% endblock %}
{% block subject %}{% trans %}Reservation reminder{% endtrans %}{% endblock %}


{% block body -%}
    {%- if occurrences | length == 1 -%}
        {% trans %}This is a reminder about a booking under your name:{% endtrans %}<br>
    {%- else -%}
        {% trans %}This is a reminder about bookings under your name:{% endtrans %}<br>
    {%- endif %}
    <ul>
        {% for occurrence in occurrences %}
            <li style="{{ 'margin-top: 2em;' if not loop.first }}">
                {{ _render_occurrence(occurrence) }}
            </li>
        {%- endfor -%}
    </ul>
{%- endblock %}


{% macro _render_time(occurrence) -%}
    {{ format_interval(occurrence.start_dt, occurrence.end_dt, 'Hm') }}
{%- endmacro %}


{% macro _render_occurrence(occurrence) -%}
    {% set reservation = occurrence.reservation -%}

    <strong>{{ occurrence.start_dt | format_date('EEEE dd/MM/yyyy') }}</strong> (<strong>{{ _render_time(occurrence) }}</strong>)<br>
    {% trans %}Room:{% endtrans %} <strong>{{ reservation.room.full_name }}</strong><br>
    {% trans %}Reason:{% endtrans %} <strong>{{ reservation.booking_reason }}</strong><br>
    <br>
    {%- if reservation.repeat_frequency.name == 'NEVER' -%}
        {% trans link='<a href="%s">'|format(reservation.external_details_url)|safe, endlink='</a>'|safe %}
            If you do not need to use the room, please
            {{ link }}cancel the reservation in Indico{{ endlink }}.
        {%- endtrans -%}
    {%- else -%}
        {% trans link='<a href="%s">'|format(occurrence.external_cancellation_url)|safe, endlink='</a>'|safe %}
            If you do not need to use the room, please
            {{ link }}cancel the occurrence in Indico{{ endlink }}.
        {%- endtrans -%}
    {%- endif -%}
{%- endmacro %}
