{#
/*
 * Xibo - Digital Signage - http://www.xibo.org.uk
 * Copyright (C) 2019 Xibo Signage Ltd
 *
 * 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 "authed.twig" %}
{% import "inline.twig" as inline %}



{% block pageContent %}

    <div class="row row-flex">
        <div class="col-lg-3 col-md-6 col-xs-12">
            <div class="widget content">
                <div class="widget-body">
                    <div class="widget-icon green">
                        <a class="XiboFormButton btns" href="{{ urlFor("stats.export.form") }}"> <i class="fa fa-external-link"></i></a>
                    </div>
                    <div class="widget-content">
                        <div class="report-title">{% trans "Proof of play" %}</div>
                        <div class="comment"><a class="XiboFormButton btns" href="{{ urlFor("stats.export.form") }}">{% trans "Export" %}</a></div>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>

         {% for report in defaults.availableReports %}
             {% if report.hidden == 0 %}
                <div class="report-box col-lg-3 col-md-6 col-xs-12">
                     <div class="widget content">
                        <div class="widget-body">
                            <div class="widget-icon {{ report.color }} ">
                                <i class="fa {{ report.fa_icon }}"></i>
                            </div>
                            <div class="widget-content">
                                <div class="report-title">  {{ report.description }}  </div>
                                <div class="comment"><a href="{{ urlFor("report.form", {name: report.name}) }}">{{ report.type }}</a></div>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </div>
                </div>
            {% endif %}
        {% endfor %}
    </div>

{% endblock %}


{% block javaScript %}
    <script type="text/javascript">
        function statsExportFormSubmit() {

            let form = $("#statisticsExportForm");
            let valid = true;

            const validateForm = function(element) {
                if (element.val() == null || element.val() == '') {
                    valid = false;
                    element.closest('.form-group').removeClass('has-success').addClass('has-error');
                } else {
                    element.closest('.form-group').addClass('has-success').removeClass('has-error');
                }
            };

            validateForm(form.find("#fromDt"));
            validateForm(form.find("#toDt"));

            if (valid) {
                form.submit();
                form.find(".form-error").remove();

                XiboDialogClose();

            } else {
                // Remove the spinner
                form.closest(".modal-dialog").find(".saving").remove();
                // https://github.com/xibosignage/xibo/issues/1589
                form.closest(".modal-dialog").find(".save-button").removeClass("disabled");

                if (!form.find(".form-error").length) {
                    form.append('<div class="alert alert-danger form-error">{% trans "Form field is required." %}</div>');
                }

            }

        }

        // Or use this to Open link in same window (similar to target=_blank)
        $(".report-box").click(function(){
            window.location = $(this).find("a:first").attr("href");
            return false;
        });

    </script>

    <style>
        .row-flex {
            display: flex;
            flex-wrap: wrap;
        }

        .content {
            height: 100%;
            padding: 20px 20px 10px;
        }

        div.report-box {
            position: relative;
        }

        div.report-box:hover {
            cursor: pointer;
            opacity: .9;
        }

        .widget .widget-content .report-title {
            font-size: 16px;
            padding: 10px 0 0;
            display: block;
        }

        .widget .widget-content .comment {
            font-size: 14px;
        }
    </style>
{% endblock %}