{#
/**
 * 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 "connector-form-edit.twig" %}
{% import "forms.twig" as forms %}
{% import "inline.twig" as inline %}

{% block callBack %}audienceFormOpen{% endblock %}
{% block connectorFormFields %}

    {% if not interface.isProviderSetting("apiKey") %}
        <h4>{% trans "Settings" %}</h4>
        <p>{% trans "Your API key allows for secure communication between the CMS and the Xibo audience service. It is used to analyse your proof of play data for Ad Campaigns and retrieve reports. It is never possible to retrieve credentials." %}</p>

        {% set title %}{% trans "API Key" %}{% endset %}
        {% set helpText %}{% trans "Enter your API Key from Xibo." %}{% endset %}
        {{ forms.input("apiKey", title, interface.getSetting("apiKey"), helpText) }}
    {% endif %}

    <p>{% trans "Once enabled additional reporting will be shown for your Ad Campaigns in the 'All Reports' section. To vary your cost/impressions per play by date, time of day, day of week or geo location, add a DMA (designated market area) below." %}</p>

    {% set options = interface.getOptionsFromAxe() %}
    {% if options.error %}
        <p class="alert alert-danger">{{ options.message }}</p>
    {% else %}
        {% set numberOfAuthedDisplays = options.displays %}
        <p class="alert alert-info">{% trans %}Your API key is authorised for {{ numberOfAuthedDisplays }} displays.{% endtrans %}</p>
    {% endif %}

    {% if interface.getSetting("apiKey") %}
        <div class="form-group row">
            <div class="XiboGrid container" id="{{ random() }}" data-grid-name="connector-audience-dma">
                <div class="XiboData card pt-3">
                    <table id="audience-dma" class="table table-striped" style="width:100%"
                           data-connector-id="{{ connector.connectorId }}"
                           data-proxy-url="{{ url_for("connector.edit.form.proxy", {id: connector.connectorId, method: ":method"}) }}"
                           data-impression-sources="{{ options.impressionSource|json_encode }}"
                           data-state-preference-name="connector-audience-dma">
                        <thead>
                        <tr>
                            <th>{% trans "Name" %}</th>
                            <th>{% trans "Cost per Play" %}</th>
                            <th>{% trans "Impressions per Play" %}</th>
                            <th>{% trans "Impression Source" %}</th>
                            <th>{% trans "Start Date" %}</th>
                            <th>{% trans "End Date" %}</th>
                            <th>{% trans "Days of week" %}</th>
                            <th>{% trans "Start Time" %}</th>
                            <th>{% trans "End Time" %}</th>
                            <th>{% trans "Is Geo?" %}</th>
                            <th>{% trans "Priority" %}</th>
                            <th>{% trans "Displays" %}</th>
                            <th></th>
                        </tr>
                        </thead>
                        <tbody>

                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    {% endif %}

{% endblock %}
