{#
/**
 * Copyright © 2003-2024 The Galette Team
 *
 * This file is part of Galette (https://galette.eu).
 *
 * Galette is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Galette is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
 */
#}
{# Let's see if there are loginfault messages to show #}
{% set loginfaults = flash.getMessage('loginfault') %}
{% if loginfault_detected is defined and loginfault_detected is iterable %}
    {% for l in loginfault_detected %}
        {% set loginfaults = loginfaults|merge([l]) %}
    {% endfor %}
{% endif %}

{# Let's see if there are error messages to show #}
{% set errors = flash.getMessage('error_detected') ?? [] %}
{% set errors = errors|merge(flash.getMessage('error') ?? []) %}
{% set errors = errors|merge(loginfaults ?? []) %}
{% if error_detected is defined and error_detected is iterable %}
    {% for e in error_detected %}
        {% set errors = errors|merge([e]) %}
    {% endfor %}
{% endif %}
{% if errors is iterable and errors|length > 0 %}
    <noscript>
        <div class="ui error icon message">
            <i class="exclamation circle icon" aria-hidden="true"></i>
            <div class="content">
                <div class="header">{{ _T("- ERROR -") }}</div>
                {% if errors|length > 1 %}
                    <ul class="list">
                    {% for error in errors %}
                        <li>{{ error|raw }}</li>
                    {% endfor %}
                    </ul>
                {% else %}
                    {% for error in errors %}
                        <p>{{ error|raw }}</p>
                    {% endfor %}
                {% endif %}
            </div>
        </div>
    </noscript>
{% endif %}

{# Let's see if there are warning messages to show #}
{% set warnings = flash.getMessage('warning_detected') ?? [] %}
{% set warnings = warnings|merge(flash.getMessage('warning') ?? []) %}
{% if warning_detected is defined and warning_detected is iterable %}
    {% for w in warning_detected %}
        {% set warnings = warnings|merge([w]) %}
    {% endfor %}
{% endif %}
{% if warnings is iterable and warnings|length > 0 %}
    <noscript>
        <div class="ui warning icon message">
            <i class="exclamation triangle icon" aria-hidden="true"></i>
            <div class="content">
                <div class="header">{{ _T("- WARNING -") }}</div>
                {% if warnings|length > 1 %}
                    <ul class="list">
                    {% for warning in warnings %}
                        <li>{{ warning|raw }}</li>
                    {% endfor %}
                    </ul>
                {% else %}
                    {% for warning in warnings %}
                        <p>{{ warning|raw }}</p>
                    {% endfor %}
                {% endif %}
            </div>
        </div>
    </noscript>
{% endif %}

{# Let's see if there are success messages to show #}
{% set success = flash.getMessage('success_detected') ?? [] %}
{% set success = success|merge(flash.getMessage('success') ?? []) %}
{% if success_detected is defined and success_detected is iterable %}
    {% for entry in success_detected %}
        {% set success = success|merge([entry]) %}
    {% endfor %}
{% endif %}
{% if success is iterable and success|length > 0 %}
    <noscript>
        <div class="ui success icon message">
            <i class="check circle outline icon" aria-hidden="true"></i>
            <i class="window close outline icon" aria-hidden="true"></i>
            <div class="content">
            {% if success|length > 1 %}
                <ul class="list">
                {% for entry in success %}
                    <li>{{ entry|raw }}</li>
                {% endfor %}
                </ul>
            {% else %}
                {% for entry in success %}
                    <p>{{ entry|raw }}</p>
                {% endfor %}
            {% endif %}
            </div>
        </div>
    </noscript>
{% endif %}

{# Let's see if there are info messages to show #}
{% set info = flash.getMessage('info_detected') ?? [] %}
{% set info = info|merge(flash.getMessage('info') ?? []) %}
{% if info_detected is defined and info_detected is iterable %}
    {% for i in info_detected %}
        {% set info = info|merge([i]) %}
    {% endfor %}
{% endif %}
{% if info is iterable and info|length > 0 %}
    <noscript>
        <div class="ui info icon message">
            <i class="info icon" aria-hidden="true"></i>
            <div class="content">
                {% if info|length > 1 %}
                    <ul class="list">
                        {% for i in info %}
                            <li>{{ i|raw }}</li>
                        {% endfor %}
                    </ul>
                {% else %}
                    {% for entry in info %}
                        {% set info_title = '' %}
                        {% set info_message = entry %}
                        {% if entry is iterable %}
                            {% set info_title = entry.title %}
                            <p class="header">{{ info_title }}</p>
                            {% set info_message = entry.message %}
                        {% endif %}
                        <p>{{ info_message|raw }}</p>
                    {% endfor %}
                {% endif %}
            </div>
        </div>
    </noscript>
{% endif %}

{# Renew telemetry #}
{% if renew_telemetry is defined and renew_telemetry %}
    {% include "modals/telemetry.html.twig" with {part: "dialog"} %}
    <noscript>
        <div class="ui info icon message" id="renewbox">
            <i class="info icon" aria-hidden="true"></i>
            <div class="content">
                <div class="header">{{ _T("Your telemetry data are more than one year old.") }}</div>
                <p>{{ _T("Do you want to send it again?") }}</p>
                <a href="#" id="telemetry" class="ui large green button">{{ _T("Yes") }}</a>
                <a href="#" id="norenew" class="ui large red button">{{ _T("No") }}</a>
                <a href="#" id="renewlater" class="ui large blue button">{{ _T("Later") }}</a>
            </div>
        </div>
    </noscript>
{% endif %}
