{#
/**
 * This file is part of FacturaScripts
 * Copyright (C) 2017-2026 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-dismissible alert-{{ style }}" role="alert">
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            {% for item in messages %}
                <div>{{ item.message }}</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-dismissible alert-{{ style }}" role="alert">
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                <div>{{ item.message }}</div>
            </div>
        {% endif %}
    {% endfor %}
{% endmacro %}

{# Muestra los parámetros necesarios para el popover #}
{% macro popoverTitle(msg, position = 'auto') %}
    {% if msg | length > 0 %}data-bs-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 me-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>
        {% else %}
            <div class="card-footer p-2">
                <button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-target="#modalTelemetry">
                    {{ trans('register') }}
                </button>
            </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 me-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 %}