{% extends '@WebProfiler/Profiler/layout.html.twig' %}

{% macro profile_search_filter(request, result, property) %}
    {%- if request.hasSession -%}
        <a href="{{ path('_profiler_search_results', request.query.all|merge({token: result.token})|merge({ (property): result[property] })) }}" title="Search"><span title="Search" class="sf-icon sf-search">{{ source('@WebProfiler/Icon/search.svg') }}</span></a>
    {%- endif -%}
{% endmacro %}

{% import _self as helper %}

{% block summary %}
    <div class="status">
        <h2>Profile Search</h2>
    </div>
{% endblock %}

{% block sidebar_search_css_class %}{% endblock %}
{% block sidebar_shortcuts_links %}{% endblock %}

{% block panel %}
    <h2>{{ tokens ? tokens|length : 'No' }} results found</h2>

    {% if tokens %}
        <table id="search-results">
            <thead>
                <tr>
                    <th scope="col" class="text-center">Status</th>
                    <th scope="col">IP</th>
                    <th scope="col">Method</th>
                    <th scope="col">URL</th>
                    <th scope="col">Time</th>
                    <th scope="col">Token</th>
                </tr>
            </thead>
            <tbody>
                {% for result in tokens %}
                    {% set css_class = result.status_code|default(0) > 399 ? 'status-error' : result.status_code|default(0) > 299 ? 'status-warning' : 'status-success' %}

                    <tr>
                        <td class="text-center">
                            <span class="label {{ css_class }}">{{ result.status_code|default('n/a') }}</span>
                        </td>
                        <td>
                            <span class="nowrap">{{ result.ip }} {{ helper.profile_search_filter(request, result, 'ip') }}</span>
                        </td>
                        <td>
                            <span class="nowrap">{{ result.method }} {{ helper.profile_search_filter(request, result, 'method') }}</span>
                        </td>
                        <td class="break-long-words">
                            {{ result.url }}
                            {{ helper.profile_search_filter(request, result, 'url') }}
                        </td>
                        <td class="text-small">
                            <span class="nowrap">{{ result.time|date('d-M-Y') }}</span>
                            <span class="nowrap newline">{{ result.time|date('H:i:s') }}</span>
                        </td>
                        <td class="nowrap"><a href="{{ path('_profiler', { token: result.token }) }}">{{ result.token }}</a></td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <div class="empty empty-panel">
            <p>The query returned no result.</p>
        </div>
    {% endif %}

{% endblock %}
