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

{% block toolbar %}
    {% set request_handler %}
        {% if collector.controller.class is defined %}
            {% set link = collector.controller.file|file_link(collector.controller.line) %}
            {% if link %}<a href="{{ link }}" title="{{ collector.controller.file }}">{% else %}<span>{% endif %}

                {{ collector.controller.class|abbr_class|striptags }}

                {%- if collector.controller.method -%}
                    &nbsp;::&nbsp;{{ collector.controller.method }}
                {%- endif -%}

            {% if link %}</a>{% else %}</span>{% endif %}
        {% else %}
            <span>{{ collector.controller }}</span>
        {% endif %}
    {% endset %}

    {% set request_status_code_color = (collector.statuscode >= 400) ? 'red' : (collector.statuscode >= 300) ? 'yellow' : 'green' %}

    {% set icon %}
        <span class="sf-toolbar-status sf-toolbar-status-{{ request_status_code_color }}">{{ collector.statuscode }}</span>
        {% if collector.route %}
            <span class="sf-toolbar-label">@</span>
            <span class="sf-toolbar-value sf-toolbar-info-piece-additional">{{ collector.route }}</span>
        {% endif %}
    {% endset %}

    {% set text %}
        <div class="sf-toolbar-info-piece">
            <b>HTTP status</b>
            <span>{{ collector.statuscode }} {{ collector.statustext }}</span>
        </div>

        <div class="sf-toolbar-info-piece">
            <b>Controller</b>
            <span>{{ request_handler }}</span>
        </div>

        {% if collector.controller.class is defined %}
            <div class="sf-toolbar-info-piece">
                <b>Controller class</b>
                <span>{{ collector.controller.class }}</span>
            </div>
        {% endif %}

        <div class="sf-toolbar-info-piece">
            <b>Route name</b>
            <span>{{ collector.route|default('NONE') }}</span>
        </div>

        <div class="sf-toolbar-info-piece">
            <b>Has session</b>
            <span>{% if collector.sessionmetadata|length %}yes{% else %}no{% endif %}</span>
        </div>
    {% endset %}

    {{ include('@WebProfiler/Profiler/toolbar_item.html.twig', { link: profiler_url }) }}
{% endblock %}

{% block menu %}
    <span class="label">
        <span class="icon">{{ include('@WebProfiler/Icon/request.svg') }}</span>
        <strong>Request / Response</strong>
    </span>
{% endblock %}

{% block panel %}
    <div class="sf-tabs">
        <div class="tab">
            <h3 class="tab-title">Request</h3>

            <div class="tab-content">
                <h3>GET Parameters</h3>

                {% if collector.requestquery.all is empty %}
                    <div class="empty">
                        <p>No GET parameters</p>
                    </div>
                {% else %}
                    {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestquery }, with_context = false) }}
                {% endif %}

                <h3>POST Parameters</h3>

                {% if collector.requestrequest.all is empty %}
                    <div class="empty">
                        <p>No POST parameters</p>
                    </div>
                {% else %}
                    {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestrequest }, with_context = false) }}
                {% endif %}

                <h3>Request Attributes</h3>

                {% if collector.requestattributes.all is empty %}
                    <div class="empty">
                        <p>No attributes</p>
                    </div>
                {% else %}
                    {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestattributes }, with_context = false) }}
                {% endif %}

                <h3>Cookies</h3>

                {% if collector.requestcookies.all is empty %}
                    <div class="empty">
                        <p>No cookies</p>
                    </div>
                {% else %}
                    {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestcookies }, with_context = false) }}
                {% endif %}

                <h3>Request Headers</h3>
                {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestheaders, labels: ['Header', 'Value'] }, with_context = false) }}

                <h3>Request Content</h3>

                {% if collector.content == false %}
                    <div class="empty">
                        <p>Request content not available (it was retrieved as a resource).</p>
                    </div>
                {% elseif collector.content %}
                    <div class="card">
                        <pre class="break-long-words">{{ collector.content }}</pre>
                    </div>
                {% else %}
                    <div class="empty">
                        <p>No content</p>
                    </div>
                {% endif %}

                <h3>Server Parameters</h3>
                {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestserver }, with_context = false) }}
            </div>
        </div>

        <div class="tab">
            <h3 class="tab-title">Response</h3>

            <div class="tab-content">
                <h3>Response Headers</h3>

                {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.responseheaders, labels: ['Header', 'Value'] }, with_context = false) }}
            </div>
        </div>

        <div class="tab {{ collector.sessionmetadata is empty ? 'disabled' }}">
            <h3 class="tab-title">Session</h3>

            <div class="tab-content">
                <h3>Session Metadata</h3>

                {% if collector.sessionmetadata is empty %}
                    <div class="empty">
                        <p>No session metadata</p>
                    </div>
                {% else %}
                    {{ include('@WebProfiler/Profiler/table.html.twig', { data: collector.sessionmetadata }, with_context = false) }}
                {% endif %}

                <h3>Session Attributes</h3>

                {% if collector.sessionattributes is empty %}
                    <div class="empty">
                        <p>No session attributes</p>
                    </div>
                {% else %}
                    {{ include('@WebProfiler/Profiler/table.html.twig', { data: collector.sessionattributes, labels: ['Attribute', 'Value'] }, with_context = false) }}
                {% endif %}
            </div>
        </div>

        <div class="tab {{ collector.flashes is empty ? 'disabled' }}">
            <h3 class="tab-title">Flashes</h3>

            <div class="tab-content">
                <h3>Flashes</h3>

                {% if collector.flashes is empty %}
                    <div class="empty">
                        <p>No flash messages were created.</p>
                    </div>
                {% else %}
                    {{ include('@WebProfiler/Profiler/table.html.twig', { data: collector.flashes }, with_context = false) }}
                {% endif %}
            </div>
        </div>

        {% if profile.parent %}
        <div class="tab">
            <h3 class="tab-title">Parent Request</h3>

            <div class="tab-content">
                <h3>
                    <a href="{{ path('_profiler', { token: profile.parent.token }) }}">Return to parent request</a>
                    <small>(token = {{ profile.parent.token }})</small>
                </h3>

                {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: profile.parent.getcollector('request').requestattributes }, with_context = false) }}
            </div>
        </div>
        {% endif %}

        {% if profile.children|length %}
        <div class="tab">
            <h3 class="tab-title">Sub Requests <span class="badge">{{ profile.children|length }}</span></h3>

            <div class="tab-content">
                {% for child in profile.children %}
                    <h3>
                        <a href="{{ path('_profiler', { token: child.token }) }}">
                            {{- child.getcollector('request').requestattributes.get('_controller') -}}
                        </a>
                        <small>(token = {{ child.token }})</small>
                    </h3>

                    {{ include('@WebProfiler/Profiler/bag.html.twig', { bag: child.getcollector('request').requestattributes }, with_context = false) }}
                {% endfor %}
            </div>
        </div>
        {% endif %}
    </div>
{% endblock %}
