{#
SPDX-FileCopyrightText: 2026 Martin Kirchgessner

SPDX-License-Identifier: AGPL-3.0-or-later
#}

{% macro menu_item(target, icon_emoji, title, is_active) %}
<a href="{{ url_for(target) }}"
    class="navbar-item {{ "is-active" if is_active }}"
    {% if is_active %}
    aria-current="page"
    {% endif %}
    >
    {{ icon(icon_emoji) }} {{ title }}
</a>
{% endmacro %}

{% macro password_field(label) %}
<div class="field is-horizontal">
    <div class="field-label">
        <label for="password" class="label">{{ label }}</label>
    </div>
    <div class="field-body">
        <div class="field">
            <div class="control has-icons-right" x-data="{ show: false }">
                <input :type="show ? 'text' : 'password'" name="password" id="password" class="input">
                <span class="icon is-clickable is-right" x-text="show ? '👓' : '👁'" @click="show = !show"></span>
            </div>
        </div>
    </div>
</div>
{% endmacro %}

{% macro audio_player(src) %}
    {% if not current_user.user.can_not_audio() %}
        <audio controls
            src="{{ src }}"
            preload="none"
            >
        </audio>
        <a class="button" aria-label="Download" title="Download" href="{{ src }}">
            📥
        </a>
    {% else %}
        🔇
    {% endif%}
{% endmacro %}

{% macro cron_formula(cart) %}
    <div class="field">
        <div class="field has-addons">
            <div class="control">
                <input type="text" class="input" name="year" placeholder="year" title="year" value="{{ cart.schedule_year if cart else '' }}">
            </div>
            <div class="control">
                <input type="text" class="input" name="month" placeholder="month" title="month" value="{{ cart.schedule_month if cart else '' }}">
            </div>
            <div class="control">
                <input type="text" class="input" name="day" placeholder="day" title="day" value="{{ cart.schedule_day if cart else '' }}">
            </div>
            <div class="control">
                <input type="text" class="input" name="week" placeholder="week" title="week" value="{{ cart.schedule_week if cart else '' }}">
            </div>
            <div class="control">
                <input type="text" class="input" name="day_of_week" placeholder="weekday" title="weekday" value="{{ cart.schedule_day_of_week if cart else '' }}">
            </div>
            <div class="control">
                <input type="text" class="input" name="hour" placeholder="hour" title="hour" value="{{ cart.schedule_hour if cart else '' }}">
            </div>
            <div class="control">
                <input type="text" class="input" name="minute" placeholder="minute" title="minute" value="{{ cart.schedule_minute if cart else '' }}">
            </div>
            <div class="control">
                <input type="text" class="input" name="second" placeholder="second" title="second" value="{{ cart.schedule_second if cart else '' }}">
            </div>
        </div>
        <p class="help">
            We use <a href="https://apscheduler.readthedocs.io/en/stable/modules/triggers/cron.html#introduction" target="_blank">
                APScheduler cron expressions
            </a>. Blank fields will be interpreted as *, seconds as 0
        </p>
    </div>
{% endmacro %}
