{% extends 'layouts/master.twig' %}

{% block main %}
<section>
    <div>
        <h1>
            {% if search is not empty %}
                {{ __('general.phrase.search-results-for-variable', { '%search%': search }) }}
            {% else %}
                {{ __('general.phrase.search') }}
            {% endif %}
        </h1>
        <form action="{{ path('search') }}">
            <label for="search">Search</label>
            <input type="search" value="{% if search is defined %}{{ search|escape }}{% endif %}" placeholder="{{ __('general.phrase.search-ellipsis') }}" name="search" id="search">
            <button type="submit">{{ __('general.phrase.search') }}</button>
        </form>
    </div>
</section>

<section>
    <div>

        {% for record in records %}

            <article>
                <div>
                    <div>
                        <h2><a href="{{ record.link }}">{{ record.title }}</a></h2>

                        <p>
                            {% if record.editlink() %}
                                <span class="edit-link">
                                    <a href="{{ record.editlink() }}">Edit</a>
                                </span> &bullet;
                            {% endif %}
                            <a href="{{ record.link() }}">{{ __('general.phrase.permalink') }}</a> &bullet;
                            {{ __('general.phrase.written-by-on', {
                                '%name%': record.user.displayname|default(__('Unknown')),
                                '%date%': record.datepublish|localedatetime("%A %B %e, %Y")
                            }) }}
                        </p>

                        <p>{{ record.excerpt(300, false, search|default('')) }}</p>
                    </div>
                </div>
                {% if record.image is not empty %}
                <div>
                    <figure>
                        <img src="{{ record.image|image(480, 320, "r") }}" alt="{{ record.values.image.alt|default() }}" />
                    </figure>
                </div>
                {% endif %}
            </article>

        {% else %}

            <article>
                <p>{{ __('general.phrase.no-result-for-search-term', { '%SEARCHTERM%': search|escape }) }}</p>
            </article>

        {% endfor %}

        {{ pager(template = 'partials/_sub_pager.twig') }}

    </div>
</section>
{% endblock main %}
