{% extends "pdf/base.twig" %}

{% block title %}{{ translate("releaseSheet") }}{% endblock %}

{% block content %}
<table class="layout-table">
    <tr>
        <td class="half">
            {{ include('blocks/company-address.twig', {
                company: company,
                showLegalNumbers: showLegalNumbers,
                showLogo: true,
            }) }}
        </td>
        <td class="half">
            <h1 class="box center spaceBottom5">
                {{ translate('releaseSheet') }}
            </h1>
            <h2 class="">
                {{ translate('event', [event['title']]) }}
            </h2>
            <h3>
                {{ translate(
                    'fromToDates',
                    [event['start_date']|format_date('short', locale=locale),
                    event['end_date']|format_date('short', locale=locale)]
                ) }}
            </h3>

            <table class="layout-table">
                <tr>
                    <td class="third">
                        <h3>{{ translate('beneficiary') }}</h3>
                    </td>
                    <td>
                        <p class="size12 spaceBottom5">
                            {{ include('blocks/beneficiary-address.twig', {
                                person: event['beneficiaries'][0]
                            }) }}
                        </p>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>

<table class="layout-table">
    <tr>
        <td class="{{ event['beneficiaries'][1] is defined ? 'third' : 'half' }} size11">
            {% if event['location'] %}
            <h3>{{ translate('location', [event['location']]) }}</h3>
            {% endif %}
            {% if event['is_confirmed'] %}
            <p class="lighter">
                {{ translate('thisEventIsConfirmed') }}
            </p>
            {% endif %}
            {% if replacementAmount %}
            <p class="lighter">
                {{ translate('eventTotalReplacementAmount', [
                    replacementAmount|format_currency(currency, formatCurrencyOptions, locale)
                ]) }}
            </p>
            {% endif %}
            <p class="lighter">
                {{ translate('printed-on-date', [date|format_date('long', locale=locale)]) }}
            </p>
        </td>
        <td class="{{ event['beneficiaries'][1] is defined ? 'third' : 'half' }}">
            {% if technicians is not empty %}
            <h3>{{ translate('technicians') }}</h3>
            <ul class="spaceBottom5">
                {% for technician in technicians %}
                <li class="spaceBottom2">
                    {{ technician['name'] }}
                    {% if technician['phone'] is not empty %}
                    <span class="lighter">- {{ technician['phone'] }}</span>
                    {% endif %}
                    {% for period in technician['periods'] %}
                    <br />
                    <span class="lighter size8">
                        {{ period['from']|format_datetime(pattern='dd MMM HH:mm', locale=locale) }} >
                        {{ period['to']|format_datetime(pattern='dd MMM HH:mm', locale=locale) }}
                    </span>
                    {% if period['position'] is not empty %}
                    <span class="lighter">- {{ period['position'] }}</span>
                    {% endif %}
                    {% endfor %}
                </li>
                {% endfor %}
            </ul>
            {% endif %}
        </td>
        {% if event['beneficiaries'][1] is defined %}
        <td class="third">
            <h3>{{ translate('otherBeneficiaries') }}</h3>
            <ul class="spaceBottom5">
                {% for otherBeneficiary in event['beneficiaries'] %}
                {% if loop.index0 > 0 %}
                <li class="spaceBottom2">
                    {{ include('blocks/beneficiary-address.twig', { person: otherBeneficiary }) }}
                </li>
                {% endif %}
                {% endfor %}
            </ul>
        </td>
        {% endif %}
    </tr>
</table>

{% if event['description'] is not empty %}
<h2>{{ translate('descriptionNotes') }}</h2>
<p>
    {{ event['description']|nl2br }}
</p>
{% endif %}

<h2 class="vspace2">{{ translate('materials') }}</h2>
<table class="size9 listing-table">
    <thead>
        <tr>
            <th>{{ translate('ref') }}</th>
            <th>{{ translate('designation') }}</th>
            <th>{{ translate('qty') }}</th>
            <th>{{ translate('replacement-value') }}</th>
            <th>{{ translate('totalReplacementValue') }}</th>
            <th>{{ translate('qtyReturned') }}</th>
        </tr>
    </thead>
    <tbody>
        {% if materialDisplayMode == 'categories' %}
        {% for category in materialList %}
            <tr>
                <td class="section-title" colspan="6">
                    {% if category['name'] is not empty %}
                    {{ category['name'] }}
                    {% else %}
                    {{ translate('otherMaterials') }}
                    {% endif %}
                </td>
            </tr>
            {% for material in category['materials'] %}
                {{ include('blocks/materials/line-summary.twig', { material: material }) }}
            {% endfor %}
        {% endfor %}
        {% elseif materialDisplayMode == 'sub-categories' %}
        {% for subCategory in materialList %}
            <tr>
                <td class="section-title" colspan="6">
                    {% if subCategory['category'] is not empty %}{{ subCategory['category'] }}{% endif %}
                    {% if subCategory['name'] is not empty %}
                    - {{ subCategory['name'] }}
                    {% else %}
                        {% if subCategory['categoryHasSubCategories'] == true %}
                        - {{ translate('otherMaterials') }}
                        {% endif %}
                    {% endif %}
                </td>
            </tr>
            {% for material in subCategory['materials'] %}
                {{ include('blocks/materials/line-summary.twig', { material: material }) }}
            {% endfor %}
        {% endfor %}
        {% elseif materialDisplayMode == 'parks' %}
        {% for park in materialList %}
            <tr>
                <td class="section-title" colspan="6">
                    {% if park['name'] is not empty %}
                        {{ park['name'] }}
                    {% else %}
                        ({{ translate('unknown-park') }})
                    {% endif %}
                </td>
            </tr>
            {% for material in park['materials'] %}
                {{ include('blocks/materials/line-summary.twig', { material: material }) }}
            {% endfor %}
        {% endfor %}
        {% else %}
            {% for material in materialList %}
                {{ include('blocks/materials/line-summary.twig', { material: material }) }}
            {% endfor %}
        {% endif %}
    </tbody>
</table>


<table class="layout-table">
    {% if customText and customText['content'] is not empty %}
    <tr>
        <td style="padding: 3mm 0;" colspan="2">
            {% if customText['title'] is not empty %}<h2>{{ customText['title'] }}</h2>{% endif %}
            <p>{{ customText['content']|nl2br }}</p>
        </td>
    </tr>
    {% endif %}
    <tr>
        <td class="half inset">
            <h3 class="center">{{ translate('output') }}</h3>
            <p class="strong">
                {{ translate('outputScheduledFor', [event['start_date']|format_date('long', locale=locale)]) }}
            </p>
            <p>{{ translate('effectiveDate') }}</p>
            <p class="strong vspace5 spaceBottom5">{{ translate('signature') }}</p>
        </td>
        <td class="inset">
            <h3 class="center">{{ translate('return') }}</h3>
            <p class="strong">
                {{ translate('returnScheduledFor', [event['end_date']|format_date('long', locale=locale)]) }}
            </p>
            <p>{{ translate('effectiveDate') }}</p>
            <p class="strong vspace5 spaceBottom5">{{ translate('signature') }}</p>
        </td>
    </tr>
</table>
{% endblock %}
