{#
/**
 * Copyright (C) 2022 Xibo Signage Ltd
 *
 * Xibo - Digital Signage - http://www.xibo.org.uk
 *
 * This file is part of Xibo.
 *
 * Xibo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * Xibo 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
 */
#}

{% extends "form-base.twig" %}
{% import "forms.twig" as forms %}

{% block formTitle %}
    {% set name = module.name %}
    {% trans %}Audio for {{ name }}{% endtrans %}
{% endblock %}

{% block formButtons %}
    {% trans "Cancel" %}, XiboDialogClose()
    {% trans "Save" %}, $("#widgetAudioForm").submit()
{% endblock %}

{% block formHtml %}

    {% if widget.countAudio > 0 %}
        {% set audio = widget.audio[0] %}
        {% set mediaId = audio.mediaId %}
        {% set volume = audio.volume %}
        {% set loop = audio.loop %}
    {% else %}
        {% set mediaId = 0 %}
        {% set volume = 100 %}
        {% set loop = 0 %}
    {% endif %}

    <div class="row">
        <div class="col-md-12">
            <form id="widgetAudioForm" class="XiboForm form-horizontal" method="put" action="{{ url_for("module.widget.audio", {id: widget.widgetId}) }}">

                {% set title %}{% trans "Audio Media" %}{% endset %}
                {% set helpText %}{% trans "Select the audio file that should be played when this Widget starts." %}{% endset %}
                {{ forms.dropdown("mediaId", "single", title, mediaId, [{mediaId: 0, name: ""}]|merge(media), "mediaId", "name", helpText) }}

                {% if not isAudioAvailable %}
                    {% set message %}{% trans "The currently selected audio has been retired, please select a new item or cancel to keep the current one." %}{% endset %}
                    {{ forms.message(message, "alert alert-danger") }}
                {% endif %}

                {% set title %}{% trans "Volume" %}{% endset %}
                {% set helpText %}{% trans "Enter the volume percentage for this audio to play at." %}{% endset %}
                {{ forms.number("volume", title, volume, helpText) }}

                {% set title %}{% trans "Loop?" %}{% endset %}
                {% set helpText %}{% trans "Should the audio loop if it finishes before the widget has finished?" %}{% endset %}
                {{ forms.checkbox("loop", title, loop, helpText, "loop-fields") }}
            </form>
        </div>
    </div>
{% endblock %}