{% extends get_base_template() %}

{% block body %}
    <section class="clearfix">
        <div class="content-copy">

            <h1>
                {% if travel_programs is empty %}
                    Für Ihre Auswahl wurden keine Reisetermine gefunden.
                {% else %}
                    Reisen mit passendem Termin gefunden: {{ travel_programs|length }}
                    Reiseprogramm{% if travel_programs|length > 1 %}e{% endif %}
                {% endif %}
            </h1>

            <div class="result-wrapper">

                {% for travel_program in travel_programs if travel_program.travelDates is not empty %}
                    <div class="result">
                        <div class="row">
                            <div class="image col-md-3">
                                <img src="/{{ travel_program.images.empty
                                        ? 'images/icons/no-picture.png'
                                        : ('uploads/travel_program/' ~ travel_program.images.first.fileNameWithExtension)
                                    }}" class="img-responsive"
                                >
                            </div>
                            <div class="description col-md-9">
                                <span class="pull-right">
                                    <a href="{{ travel_program.page.urlPath }}/pdf" class="btn btn-default btn-sm border-radius">
                                        <i class="fa fa-file-pdf-o"></i> Druckversion
                                    </a>
                                </span>
                                <div class="title clearfix">{{ travel_program.title }}</div>

                                <div class="subtitle">{{ travel_program.subtitle }}</div>
                                <div class="dates-count">
                                    {{ travel_program.travelDates|length }} passende{% if travel_program.travelDates|length > 1 %} Termine{% else %}r Termin{% endif %}
                                </div>
                                <div class="price pull-left"><span class="small">p.P.</span> ab {{ travel_program.lowestPrice|number_format }} €</div>

                                <div class="pull-right">
                                    <a href="{{ travel_program.page.urlPath }}"
                                       class="btn btn-primary btn-sm border-radius"
                                       target="_blank"
                                    >
                                        Angebot aufrufen
                                    </a>
                                </div>

                            </div>
                            <div class="clearfix"></div>
                        </div>

                    </div>
                    <div class="table-responsive no-more-tables" id="">
                        <table class="table">
                            <thead>
                            <tr>
                                <th>Termin-Nr.</th>
                                <th>Beginn</th>
                                <th>Ende</th>
                                <th>Preis p.P im Doppelzimmer</th>
                                <th>Preis p.P im Einzelzimmer</th>
                                <th></th>
                                <th></th>
                                <th></th>
                            </tr>
                            </thead>
                            <tbody>
                                {% set travel_program_loop = loop %}
                                {% for travel_date in travel_program.travelDates if travel_date.status > 0 %}
                                    {# @var travel_date \AppBundle\Entity\TravelDate  #}
                                    <tr>
                                        <td data-title="Termin-Nr."><strong>{{ travel_date.name }}</strong></td>
                                        <td data-title="Beginn">{{ travel_date.start|date }}</td>
                                        <td data-title="Ende">{{ travel_date.end|date }}</td>
                                        <td data-title="Preis p.P im Doppelzimmer">ab {{ travel_date.prices[3].effectivePrice|number_format }} €</td>
                                        <td data-title="Preis p.P im Einzelzimmer">ab {{ travel_date.prices[1].effectivePrice|number_format }} €</td>

                                        <td data-title="Abflugorte / Zuschläge">
                                            <a href="#" class="color-brand" data-toggle="modal"
                                               data-target="#st-departures-modal-{{ travel_program_loop.index0 }}-{{ loop.index0 }}"
                                            >
                                                Flughäfen
                                            </a>

                                            {% include 'default/components/departuresModal.html.twig' with {
                                                'departures': travel_date.departures,
                                                'id': travel_program_loop.index0 ~ '-' ~ loop.index0
                                            } %}
                                        </td>

                                        <td data-title="Verfügbarkeit">
                                            <img src="/images/icons/available-{{ travel_date.effectiveStatus }}.png"
                                                 alt="Verfügbarkeit">
                                        </td>

                                        <td data-title="">
                                            {# #TODO Bad performance #}
                                            <a href="{{ travel_program.page.urlPath }}#travel-dates-content-tab" class="btn btn-primary">Details</a>
                                        </td>
                                    </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>

                {% endfor %}

            </div>
        </div>

    </section>

{% endblock body %}