{#
/**
 * 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/>.
 */
#}

{% set randomId = random() %}

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

{% block formTitle %}
    {% set mediaName = media.name %}
    {% trans %}Usage Report for {{ mediaName }}{% endtrans %}
{% endblock %}

{% block formButtons %}
    {% trans "Close" %}, XiboDialogClose()
{% endblock %}

{% block callBack %}usageFormOpen{% endblock %}

{% block formHtml %}
    <div class="row">
        <div class="col-md-12">
            <ul class="nav nav-tabs" role="tablist">
                <li class="nav-item"><a class="nav-link active"href="#displays" role="tab" data-toggle="tab"><span>{% trans "Displays" %}</span></a></li>
                <li class="nav-item"><a class="nav-link"href="#layouts" role="tab" data-toggle="tab"><span>{% trans "Layouts" %}</span></a></li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane active" id="displays">
                    <div class="row">
                        <div class="col-md-12">
                            <p class="alert alert-info">
                                {% trans %}This media is directly assigned to {{ countDisplays }} displays, the ones you have permission to see are shown below.{% endtrans %}
                                {% trans %}Direct assignment is where Layouts/Media are assigned to a Display/DisplayGroup without being in a Schedule.{% endtrans %}
                                <br>
                                <br>
                                {% trans %}If the media is used in scheduled events it is also shown below. To restrict to a specific time enter a date in the filter below.{% endtrans %}
                            </p>
                        </div>
                    </div>
                    <div class="XiboGrid" id="{{ random() }}" data-grid-name="usageReport">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="XiboFilter">
                                    <div class="FilterDiv card-body" id="Filter">
                                        <form class="form-inline" id="usageReportForm">
                                            {% set title %}{% trans "From Date" %}{% endset %}
                                            {{ inline.dateTime("mediaEventFromDate", title, "", helpText, "", "") }}

                                            {% set title %}{% trans "To Date" %}{% endset %}
                                            {{ inline.dateTime("mediaEventToDate", title, "", helpText, "", "") }}
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <table id="usageReportTable" class="table table-bordered membersTable" style="width:100%" data-media-id="{{ media.mediaId }}">
                                    <thead>
                                        <tr>
                                            <th>{% trans "ID" %}</th>
                                            <th>{% trans "Display" %}</th>
                                            <th>{% trans "Description" %}</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="tab-pane" id="layouts">
                    <div class="XiboGrid" id="{{ random() }}" data-grid-name="usageReportLayouts">
                        <div class="row">
                            <div class="col-md-12">
                                <table id="usageReportLayoutsTable" class="table table-bordered" style="width:100%" data-media-id="{{ media.mediaId }}">
                                    <thead>
                                    <tr>
                                        <th>{% trans "ID" %}</th>
                                        <th>{% trans "Layout" %}</th>
                                        <th>{% trans "Description" %}</th>
                                        <th></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}