{% extends 'partials/base.html.twig' %}

{% block content %}
<h1 class="trips-heading">Past Trips</h1>
{% set trips = page.children.published()|sort((a, b) => a.date < b.date ? 1 : -1) %}
{% if trips|length == 0 %}
<p class="feed-empty">No trips yet.</p>
{% else %}
<div class="trips-list">
{% for trip in trips %}
    {% set dailies_page = grav.pages.find(trip.route ~ '/dailies') %}
    {% set stories_page = grav.pages.find(trip.route ~ '/stories') %}
    {% set journal_count = dailies_page ? dailies_page.children.published()|length : 0 %}
    {% set story_count = stories_page ? stories_page.children.published()|length : 0 %}
    <a class="trip-card" href="{{ trip.url }}">
        <div class="trip-card-title">{{ trip.title }}</div>
        <div class="trip-card-meta">
            {% if trip.header.date_start %}
            <span class="trip-card-dates">
                {{ trip.header.date_start|date('M Y') }}
                {% if trip.header.date_end %} — {{ trip.header.date_end|date('M Y') }}{% else %} — Ongoing{% endif %}
            </span>
            {% endif %}
            <span class="trip-card-counts">
                {{ journal_count }} journal {{ journal_count == 1 ? 'entry' : 'entries' }}
                {% if story_count > 0 %} · {{ story_count }} {{ story_count == 1 ? 'story' : 'stories' }}{% endif %}
            </span>
        </div>
    </a>
{% endfor %}
</div>
{% endif %}
{% endblock %}
