{#
/**
 * Copyright (C) 2023 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 "connector-form-edit.twig" %}
{% import "forms.twig" as forms %}

{% block connectorFormFields %}
    <h3>Open Weather Map</h3>
    <p>Weather forecasts, nowcasts and history in a fast and elegant way</p>
    <p>Weather data provided by <a href="https://openweathermap.org/" target="_blank">OpenWeather</a> is provided under
        <a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank">CC-BY-SA 4.0</a>
        and <a href="http://opendatacommons.org/licenses/odbl/" target="_blank">ODbl</a>.</p>

    {% if interface.isProviderSetting("owmApiKey") %}
        <p>{{ "Your platform provider has configured this connector for you."|trans }}</p>
    {% else %}
        {% set title %}
            OpenWeather Map has added a new 'One Call API 3.0' option to their suite of products. New users must enter
            credit card details to use a free number of API calls (which resets each day) or opt for a paid subscription.
            Older API keys are not compatible with the new API.
        {% endset %}
        {{ forms.alert(title, "info") }}

        {% set title %}
            OpenWeather retired One Call API version 2.5 in June 2024. For continued weather data access, please migrate
            or subscribe to One Call API version 3.0, which is now the only supported version for free tier users.
        {% endset %}
        {{ forms.alert(title, "info") }}
        
        {% set title %}{% trans "Open Weather Map API Key" %}{% endset %}
        {% set helpText %}{% trans "Enter your API Key from Open Weather Map." %}{% endset %}
        {{ forms.input("owmApiKey", title, interface.getSetting("owmApiKey"), helpText) }}

        {% set title %}{% trans "Paid plan?" %}{% endset %}
        {% set helpText %}{% trans "Is the above key on an Open Weather Map paid plan? Do NOT tick this if you have subscribed to One Call API 3.0." %}{% endset %}
        {{ forms.checkbox("owmIsPaidPlan", title, interface.getSetting("owmIsPaidPlan"), helpText) }}

        {% set title %}{% trans "Cache Period" %}{% endset %}
        {% set helpText %}{% trans "This module uses 3rd party data. Please enter the number of seconds you would like to cache results." %}{% endset %}
        {{ forms.input("cachePeriod", title, interface.getSetting("cachePeriod", 3600), helpText) }}

        {% set title %}{% trans "Schedule Criteria Cache Period" %}{% endset %}
        {% set helpText %}{% trans "If a player has weather based schedule criteria, how many hours should this connector cache that weather data for?" %}{% endset %}
        {{ forms.input("xmdsCachePeriod", title, interface.getSetting("xmdsCachePeriod", 4), helpText) }}
    {% endif %}
{% endblock %}