{#
/**
 * Copyright (C) 2020 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 %}
    {% trans "Edit World Clock" %}
{% endblock %}

{% block extra %}{{ module.getExtra()|json_encode|raw }}{% endblock %}

{% block formHtml %}
    <div class="row">
        <ul class="nav nav-tabs" role="tablist">
            <li class="nav-item"><a class="nav-link active" href="#generalTab" role="tab" data-toggle="tab"><span>{% trans "General" %}</span></a></li>
            <li class="nav-item"><a class="nav-link" href="#configurationTab" role="tab" data-toggle="tab"><span>{% trans "Configuration" %}</span></a></li>
            <li class="dropdown digital-control-group">
                <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
                    {% trans "Templates" %}<span class="caret"></span>
                </a>
                <div class="dropdown-menu">
                    <a class="dropdown-item" href="#templatePreset" role="tab" data-toggle="tab"><span>{% trans "Preset" %}</span></a>
                    <a class="dropdown-item template-override-controls" href="#mainTemplateTab"  role="tab" data-toggle="tab"><span>{% trans "Main" %}</span></a>
                    <a class="dropdown-item template-override-controls" href="#optionalStylesheetTab"  role="tab" data-toggle="tab"><span>{% trans "Optional Stylesheet" %}</span></a>
                </div>
            </li>
            <li class="nav-item"><a class="nav-link" href="#analogueSettingsTab" role="tab" class="analogue-control-group" data-toggle="tab"><span>{% trans "Analogue Settings" %}</span></a></li>
        </ul>
        <div class="col-md-12">
            <form id="clockFormEdit" class="XiboForm form-horizontal" method="put" action="{{ url_for("module.widget.edit", {id: module.widget.widgetId}) }}">
                <div class="tab-content">
                    <div class="tab-pane active" id="generalTab">
                        {% set title %}{% trans "Name" %}{% endset %}
                        {% set helpText %}{% trans "An optional name for this widget" %}{% endset %}
                        {{ forms.input("name", title, module.getOption("name"), helpText) }}

                        {% set title %}{% trans "Set a duration?" %}{% endset %}
                        {% set helpText %}{% trans "Select to provide a specific duration for this Widget" %}{% endset %}
                        {{ forms.checkbox("useDuration", title, module.getUseDuration(), helpText) }}

                        {% set title %}{% trans "Duration" %}{% endset %}
                        {% set helpText %}{% trans "The duration in seconds this should be displayed" %}{% endset %}
                        {{ forms.number("duration", title, module.getDuration(), helpText, "duration-fields", "required") }}

                        {% set title %}{% trans "Enable Stats Collection?" %}{% endset %}
                        {% set helpText %}{% trans "Enable the collection of Proof of Play statistics for this Widget. Ensure that ‘Enable Stats Collection’ is set to ‘On’ in the Display Settings." %}{% endset %}

                        {% set offOption %}{% trans "Off" %}{% endset %}
                        {% set onOption %}{% trans "On" %}{% endset %}
                        {% set inheritOption %}{% trans "Inherit" %}{% endset %}
                        {% set options = [
                            { id: "Off", value: offOption },
                            { id: "On", value: onOption },
                            { id: "Inherit", value: inheritOption }
                        ] %}
                        {{ forms.dropdown("enableStat", "single", title, module.getOption("enableStat", theme.getSetting("WIDGET_STATS_ENABLED_DEFAULT")), options, "id", "value", helpText) }}
                    </div>

                    <div class="tab-pane" id="configurationTab">
                        <div class="row">
                            <div class="col-sm-12">
                                <h4>{% trans "Clocks" %}&nbsp;<span class="clockCount"></span></h4>
                            </div>
                        </div>

                        <div id="worldClocksContainer" class="form-group d-block px-3"></div>
                        
                        {% set title %}{% trans "Clock Type" %}{% endset %}
                        {% set helpText %}{% trans "Please select the type of clock to display." %}{% endset %}
                        {% set analog %}{% trans "Analog" %}{% endset %}
                        {% set digital %}{% trans "Digital" %}{% endset %}
                        {% set options = [
                            { id: 1, value: digital },
                            { id: 2, value: analog }
                        ] %}
                        {{ forms.dropdown("clockType", "single", title, module.getOption("clockType"), options, "id", "value", helpText) }}

                        {% set title %}{% trans "Clock Columns" %}{% endset %}
                        {% set helpText %}{% trans "Number of columns to display" %}{% endset %}
                        {{ forms.number("clockCols", title, module.getOption("clockCols", 1), helpText, "", "required") }}

                        {% set title %}{% trans "Clock Rows" %}{% endset %}
                        {% set helpText %}{% trans "Number of rows to display" %}{% endset %}
                        {{ forms.number("clockRows", title, module.getOption("clockRows", 1), helpText, "", "required") }}
                    </div>

                    <div class="tab-pane" id="analogueSettingsTab">
                        <div class="col-sm-12">
                            <h4>{% trans "Analogue Clock Settings" %}</span></h4>
                        </div>

                        {% set title %}{% trans "Background colour" %}{% endset %}
                        {% set helpText %}{% trans "Use the colour picker to select the background colour" %}{% endset %}
                        {{ forms.input("bgColor", title, module.getOption("bgColor", "#f9f9f9"), helpText, "clock-color-input") }}
                        
                        {% set title %}{% trans "Case colour" %}{% endset %}
                        {% set helpText %}{% trans "Use the colour picker to select the case colour" %}{% endset %}
                        {{ forms.input("caseColor", title, module.getOption("caseColor", "#222"), helpText, "clock-color-input") }}

                        {% set title %}{% trans "Hour hand colour" %}{% endset %}
                        {% set helpText %}{% trans "Use the colour picker to select the hour hand colour" %}{% endset %}
                        {{ forms.input("hourHandColor", title, module.getOption("hourHandColor", "#333"), helpText, "clock-color-input") }}

                        {% set title %}{% trans "Minute hand colour" %}{% endset %}
                        {% set helpText %}{% trans "Use the colour picker to select the minute hand colour" %}{% endset %}
                        {{ forms.input("minuteHandColor", title, module.getOption("minuteHandColor", "#333"), helpText, "clock-color-input") }}

                        {% set title %}{% trans "Show seconds hand?" %}{% endset %}
                        {% set helpText %}{% trans "Tick if you would like to show the seconds hand." %}{% endset %}
                        {{ forms.checkbox("showSecondsHand", title, module.getOption("showSecondsHand", 1), helpText) }}

                        {% set title %}{% trans "Seconds hand colour" %}{% endset %}
                        {% set helpText %}{% trans "Use the colour picker to select the seconds hand colour" %}{% endset %}
                        {{ forms.input("secondsHandColor", title, module.getOption("secondsHandColor", "#aa0202"), helpText, "clock-color-input seconds-fields") }}
                        <hr class="seconds-fields">

                        {% set title %}{% trans "Dial centre colour" %}{% endset %}
                        {% set helpText %}{% trans "Use the colour picker to select the dial centre colour" %}{% endset %}
                        {{ forms.input("dialColor", title, module.getOption("dialColor", "#222"), helpText, "clock-color-input") }}

                        {% set title %}{% trans "Show steps?" %}{% endset %}
                        {% set helpText %}{% trans "Tick if you would like to show the clock steps." %}{% endset %}
                        {{ forms.checkbox("showSteps", title, module.getOption("showSteps", 1), helpText) }}

                        {% set title %}{% trans "Steps colour" %}{% endset %}
                        {% set helpText %}{% trans "Use the colour picker to select the steps colour" %}{% endset %}
                        {{ forms.input("stepsColor", title, module.getOption("stepsColor", "#333"), helpText, "clock-color-input steps-fields") }}

                        {% set title %}{% trans "Secondary steps colour" %}{% endset %}
                        {% set helpText %}{% trans "Use the colour picker to select the secondary steps colour" %}{% endset %}
                        {{ forms.input("secondaryStepsColor", title, module.getOption("secondaryStepsColor", "#333"), helpText, "clock-color-input steps-fields") }}
                        <hr class="steps-fields">

                        {% set title %}{% trans "Detailed look?" %}{% endset %}
                        {% set helpText %}{% trans "Tick if you would like to show a more detailed look for the clock ( using shadows and 3D effects )." %}{% endset %}
                        {{ forms.checkbox("showDetailed", title, module.getOption("showDetailed", 1), helpText) }}

                        {% set title %}{% trans "Show inner digital clock?" %}{% endset %}
                        {% set helpText %}{% trans "Tick if you would like to show a small inner digital clock." %}{% endset %}
                        {{ forms.checkbox("showMiniDigitalClock", title, module.getOption("showMiniDigitalClock", 1), helpText) }}

                        {% set title %}{% trans "Digital clock text colour" %}{% endset %}
                        {% set helpText %}{% trans "Use the colour picker to select the digital clock text colour" %}{% endset %}
                        {{ forms.input("digitalClockTextColor", title, module.getOption("digitalClockTextColor", "#3b3b3b"), helpText, "clock-color-input inner-digital-fields") }}

                        {% set title %}{% trans "Digital clock background colour" %}{% endset %}
                        {% set helpText %}{% trans "Use the colour picker to select the digital clock background colour" %}{% endset %}
                        {{ forms.input("digitalClockBgColor", title, module.getOption("digitalClockBgColor", "#e6e6e6"), helpText, "clock-color-input inner-digital-fields") }}
                        <hr class="inner-digital-fields">

                        {% set title %}{% trans "Show label?" %}{% endset %}
                        {% set helpText %}{% trans "Tick if you would like to show the timezone label." %}{% endset %}
                        {{ forms.checkbox("showLabel", title, module.getOption("showLabel", 1), helpText) }}

                        {% set title %}{% trans "Label text colour" %}{% endset %}
                        {% set helpText %}{% trans "Use the colour picker to select the label text colour" %}{% endset %}
                        {{ forms.input("labelTextColor", title, module.getOption("labelTextColor", "#f9f9f9"), helpText, "clock-color-input label-fields") }}
                        
                        {% set title %}{% trans "Label background colour" %}{% endset %}
                        {% set helpBg %}{% trans "Use the colour picker to select the label background colour" %}{% endset %}
                        {{ forms.input("labelBgColor", title, module.getOption("labelBgColor", "#222"), helpText, "clock-color-input label-fields") }}
                        <hr class="label-fields">
                    </div>

                    <div class="tab-pane" id="templatePreset">
                        {% set title %}{% trans "Template" %}{% endset %}
                        {% set helpText %}{% trans "Select the template you would like to apply. This can be overridden using the check box below." %}{% endset %}
                        {{ forms.dropdown("templateId", "single", title, module.getOption("templateId"), templatesAvailable, "id", "value", helptext, "template-selector-control selectPicker selectPickerWithImage", null, null, null, [{ name: "data-minimum-results-for-search", value: "Infinity" },{ name: "data-width", value: "100%" }], null, "image") }}

                        {% set title %}{% trans "Override the template?" %}{% endset %}
                        {% set helpText %}{% trans "Tick if you would like to override the template." %}{% endset %}
                        {{ forms.checkbox("overrideTemplate", title, module.getOption("overrideTemplate", 0), helpText) }}

                        {% set useTemplatesMessage %}
                            {% trans "With Override the Template selected enter your own text, html and css by using the Templates drop down menu in the tab header above." %}                     
                        {% endset %}
                        {{ forms.message(useTemplatesMessage, 'template-override-controls') }}

                        {% set title %}{% trans "Original Width" %}{% endset %}
                        {% set helpText %}{% trans "This is the intended width of the template and is used to scale the Widget within its region when the template is applied." %}{% endset %}
                        {{ forms.number("widgetOriginalWidth", title, module.getOption("widgetOriginalWidth", undefined), helpText, "template-override-controls", "", "number") }}

                        {% set title %}{% trans "Original Height" %}{% endset %}
                        {% set helpText %}{% trans "This is the intended height of the template and is used to scale the Widget within its region when the template is applied." %}{% endset %}
                        {{ forms.number("widgetOriginalHeight", title, module.getOption("widgetOriginalHeight", undefined), helpText, "template-override-controls", "", "number") }}
                    </div>

                    <div class="tab-pane" id="mainTemplateTab">
                        <div class="editor-messages">
                            {% set message %}{% trans "Enter a format for the World Clock. See the manual for more information." %}{% endset %}
                            {{ forms.message(message, "") }}

                            {% set simpleTextEditorMessage %}
                                {% trans "Enter text or HTML in the box below." %}<br>
                            {% endset %}
                            {{ forms.message(simpleTextEditorMessage, 'mainTemplate-advanced-editor-hide inline-editor-hide') }}

                            {{ forms.message(playlistEditorMessage, 'playlist-editor-message mainTemplate-advanced-editor-show') }}
                        </div>

                        <div class="ckeditor_controls inline-editor-hide row" data-linked-to="mainTemplate">
                            <div class="offset-sm-4 col-sm-8">
                                <div class="form-group row">
                                    <label class="col-sm-4 control-label" for="ckeditor_snippets_select">{% trans "Snippets" %}</label>
                                    <div class="col-sm-8 ckeditor_select_container">
                                        <select id="ckeditor_snippets_select" 
                                            class="ckeditor_snippets_select form-control"
                                            data-linked-to="mainTemplate">
                                            <option value=""></option>
                                            <option value="DD MMMM, YYYY">Date</option>
                                            <option value="HH:mm:ss">Time</option>
                                            <option value="ss">Seconds</option>
                                            <option value="mm">Minutes</option>
                                            <option value="HH">Hours (0-23)</option>
                                            <option value="hh">Hours (0-12)</option>
                                            <option value="A">AM/PM</option>
                                            <option value="DD">Days</option>
                                            <option value="MM">Month</option>
                                            <option value="MMM">Month Short Name</option>
                                            <option value="MMMM">Month Long Name</option>
                                            <option value="YY">~Year Short</option>
                                            <option value="YYYY">~Year Long</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>

                        {{ forms.textarea("mainTemplate", "", module.getRawNode("mainTemplate"), "", "inline-editor-hide", "", 10) }}
                    </div>

                    <div class="tab-pane" id="optionalStylesheetTab"> 
                        <div class="form-content-title">
                            <h4>{% trans "Optional Stylesheet" %}</h4>
                        </div>

                        {{ forms.textarea("styleSheet", "", module.getRawNode("styleSheet"), "", "", "", 10) }}
                    </div>

                </div>
            </form>
        </div>
    </div>
{% endblock %}