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

{% block toolbar %}
    {% set profiler_markup_version = profiler_markup_version|default(1) %}

    {% set callCount = collector.calls|length %}
    {% set errorCount = collector.errors|length %}

    {% if callCount == 0 %}
        {% set color_code = '' %}
    {% elseif errorCount > 0 %}
        {% set color_code = 'red' %}
    {% else %}
        {% set color_code = 'green' %}
    {% endif %}

    {% set icon %}
        {% if profiler_markup_version == 1 %}
            {{ include('@CsaGuzzle/Icon/guzzle.svg', { height: 28, color: '#3F3F3F' }) }}
            <span class="sf-toolbar-status sf-toolbar-status-{{ color_code }}">{{ callCount }}</span>
        {% else %}
            {{ include('@CsaGuzzle/Icon/guzzle.svg') }}
            <span class="sf-toolbar-value">{{ callCount }}</span>
        {% endif %}
    {% endset %}

    {% set text %}
        <div class="sf-toolbar-info-piece">
            <b>Success</b>
            <span class="sf-toolbar-status sf-toolbar-status-green">{{ callCount - errorCount }}</span>
        </div>
        <div class="sf-toolbar-info-piece">
            <b>Errors</b>
            <span class="sf-toolbar-status sf-toolbar-status-red">{{ errorCount }}</span>
        </div>
    {% endset %}

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

{% block head %}
    {{ parent() }}
    <link rel="stylesheet" href="{{ asset('bundles/csaguzzle/css/screen.min.css') }}">
    <script src="{{ asset('bundles/csaguzzle/js/guzzle.min.js') }}"></script>
    {% set profiler_markup_version = profiler_markup_version|default(1) %}
    {% if profiler_markup_version == 1 %}
        <link rel="stylesheet" href="{{ asset('bundles/csaguzzle/css/legacy.min.css') }}">
        <script src="{{ asset('bundles/csaguzzle/js/legacy.min.js') }}"></script>
        <script type="text/javascript">window.addEventListener('load', Guzzle.createTabs, false);</script>
    {% endif %}
{% endblock %}

{% block menu %}
    <span class="label {% if collector.errors|length > 0 %}label-status-error{% endif %}">
        <span class="icon">
            {% set profiler_markup_version = profiler_markup_version|default(1) %}
            {% if profiler_markup_version == 1 %}
                {{ include('@CsaGuzzle/Icon/guzzle.svg', { height: 30, color: '#3F3F3F' }) }}
            {% else %}
                {{ include('@CsaGuzzle/Icon/guzzle.svg')}}
            {% endif %}

        </span>
        <strong>{{ collector.name|capitalize|default('HTTP calls') }}</strong>
        <span class="count">
            {% if collector.calls is not empty %}
                <span>{{ collector.calls|length }}</span>
            {% endif %}
        </span>
    </span>
{% endblock %}

{% block panel %}
    <h2>{{ (collector.name|capitalize)|default('HTTP calls') }}</h2>
    {{  include('@CsaGuzzle/Calls/list.html.twig', { calls: collector.calls }) }}
{% endblock %}
