{#
/**
 * This file is part of FacturaScripts
 * Copyright (C) 2017-2024 Carlos Garcia Gomez <carlos@facturascripts.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#}

{# Muestra todos los mensajes con alguno de los niveles dados #}
{% macro message(log, levels, style) %}
    {% set messages = log.read('master', levels) | merge(log.read('database', levels)) %}
    {% if messages | length > 0 %}
        <div class="alert alert-{{ style }}" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
            {% for item in messages %}
                <div>{{ item.message | raw }}</div>
            {% endfor %}
        </div>
    {% endif %}
{% endmacro %}

{# Muestra todos los mensajes de los niveles dados, de forma que sea compatible con versiones antiguas de MiniLog #}
{% macro messageCompat(log, levels, style) %}
    {% for item in log.read() %}
        {% if item.level in levels and item.channel == 'master' %}
            <div class="alert alert-{{ style }}" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <div>{{ item.message | raw }}</div>
            </div>
        {% endif %}
    {% endfor %}
{% endmacro %}

{# Muestra los parámetros necesarios para el popover #}
{% macro popoverTitle(msg, position = 'auto') %}
    {% if msg | length > 0 %}data-toggle="popover" data-placement="{{ position }}" data-trigger="hover" data-content="{{ msg }}"{% endif %}
{% endmacro %}

{# Muestra un mensaje para registrar la instalación #}
{% macro registerInstall(link = true) %}
    <div class="card shadow-sm">
        <div class="card-body">
            <div class="h4">
                <i class="fa-solid fa-registered mr-1"></i> {{ trans('register-install-ad') }}
            </div>
            <p class="card-text">{{ trans('register-install-ad-p') }}</p>
        </div>
        {% if link %}
            <div class="card-footer p-2">
                <a href="{{ asset('Updater') }}" class="btn btn-secondary">
                    {{ trans('register') }}
                </a>
                <a href="https://facturascripts.com/patrocinar" target="_blank" class="btn btn-outline-secondary">
                    {{ trans('become-sponsor') }}
                </a>
            </div>
        {% endif %}
    </div>
{% endmacro %}

{# Muestra un mensaje para actualizar la instalación #}
{% macro updateInstall() %}
    <div class="card bg-warning shadow-sm">
        <div class="card-body">
            <div class="h3">
                <i class="fa-solid fa-cloud-download fa-beat mr-1"></i> {{ trans('updates-available') }}
            </div>
            <p class="card-text">{{ trans('updates-available-p') }}</p>
        </div>
        <div class="card-footer p-2">
            <a href="{{ asset('Updater') }}" class="btn btn-secondary">
                {{ trans('update') }}
            </a>
        </div>
    </div>
{% endmacro %}