{#

This file is part of the Sonata package.

(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{% set collapse = collapse|default(1) %}

{% for type in sonata_flashmessages_types() %}
    {% set messages = sonata_flashmessages_get(type) %}
    {% if messages|length > collapse and collapse > 0 %}
        <div class="alert alert-{{ sonata_flashmessages_class(type, 'default') }} alert-dismissible collapsed-box">
            <button
                    type="button"
                    class="close"
                    data-dismiss="alert"
                    aria-hidden="true"
                    aria-label="{{ 'message_close'|trans({}, 'SonataTwigBundle') }}">
                &times;
            </button>
            <input type="checkbox" class="read-more-state" id="toggle-more-{{ loop.index }}" />
            <div class="read-more-wrap">
                {% for message in messages %}
                    {% if loop.index > collapse %}
                        <span class="read-more-target">{{ message|raw }}</span>
                    {% else %}
                        {{ message|raw }}
                    {% endif %}
                {% endfor %}
            </div>

            <label for="toggle-more-{{ loop.index }}" class="read-more-trigger">
                <span class="more">{{ 'more'|trans({}, 'SonataTwigBundle') }} &#9660;</span>
                <span class="less hide">{{ 'less'|trans({}, 'SonataTwigBundle') }} &#9650;</span>
                <span class="badge badge-default">{{ messages|length }}</span>
            </label>
        </div>
    {% elseif messages|length > 0 %}
        {% for message in messages %}
            <div class="alert alert-{{ sonata_flashmessages_class(type, 'default') }} alert-dismissable">
                <button
                    type="button"
                    class="close"
                    data-dismiss="alert"
                    aria-hidden="true"
                    aria-label="{{ 'message_close'|trans({}, 'SonataTwigBundle') }}">
                    &times;
                </button>
                {{ message|raw }}
            </div>
        {% endfor %}
    {% endif %}
{% endfor %}
