{% extends 'base.html.twig' %}
{% block title %}Přehled{% endblock %}
{% block body %}
    <!-- Content Header (Page header) -->
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1 class="m-0">Přehled</h1>
                </div><!-- /.col -->
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item active">Přehled</li>
                    </ol>
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->

    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-12">
                    {% for message in app.flashes('good') %}
                        <div class="flash-notice pull-right col-xs-12 " style="padding:0;">
                            <div class="alert alert-success alert-dismissible fade show" role="alert">
                                <strong>{{ message|raw }}</strong>
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                        </div>
                    {% endfor %}
                    {% for message in app.flashes('bad') %}
                        <div class="flash-notice pull-right col-xs-12 " style="padding:0;">
                            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                                <strong>{{ message|raw }}</strong>
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                        </div>
                    {% endfor %}
                </div>
            </div>
            <h5 class="mb-2">Zařízení</h5>
            <!-- Info boxes -->
            <div class="row">
                <div class="col-12 col-md-6 col-lg-4">
                    <div class="info-box">
                        <span class="info-box-icon bg-success elevation-1">
                            <i class="fas fa-fw fa-check">

                            </i></span>

                        <div class="info-box-content">
                            <span class="info-box-text">
                                <a href="{{ path('devices_index') }}" title="Schválená zařízení">
                                    Schváleno
                                </a>
                            </span>
                            <span class="info-box-number">
                            {% if allowedDevices is defined and allowedDevices is not empty %}
                                {{ allowedDevices|length }}
                            {% else %}
                                0
                            {% endif %}
                            </span>
                        </div>
                        <!-- /.info-box-content -->
                    </div>
                    <!-- /.info-box -->
                </div>
                <!-- /.col -->
                <div class="col-12 col-md-6 col-lg-4">
                    <div class="info-box mb-3">
                        <span class="info-box-icon bg-info elevation-1">
                            <i class="fas fa-fw fa-hourglass"></i>
                        </span>
                        <div class="info-box-content">
                            <span class="info-box-text">
                                 <a href="{{ path('devices_waiting') }}">
                                    Neschváleno
                                </a>
                            </span>
                            <span class="info-box-number">
                                {% if waitingDevices is defined and waitingDevices is not empty %}
                                    {{ waitingDevices|length }}
                                {% else %}
                                    0
                                {% endif %}
                            </span>
                        </div>
                        <!-- /.info-box-content -->
                    </div>
                    <!-- /.info-box -->
                </div>
                <!-- /.col -->

                <!-- fix for small devices only -->
                <div class="clearfix hidden-md-up"></div>

                <div class="col-12 col-md-6 col-lg-4">
                    <div class="info-box mb-3">
                        <span class="info-box-icon bg-danger elevation-1">
                            <i class="fas fa-fw fa-times"></i>
                        </span>
                        <div class="info-box-content">
                            <span class="info-box-text">
                                <a href="{{ path('devices_not_activated') }}">
                                    Neaktivováno
                                </a>
                            </span>
                            <span class="info-box-number">
                                {% if notActivatedDevices is defined and notActivatedDevices is not empty %}
                                    {{ notActivatedDevices|length }}
                                {% else %}
                                    0
                                {% endif %}
                            </span>
                        </div>
                        <!-- /.info-box-content -->
                    </div>
                    <!-- /.info-box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
            {% if is_granted("ROLE_ADMIN") %}
            <h5 class="mb-2">Uživatelé</h5>
            <div class="row">
                    <div class="col-12 col-md-6 col-lg-4">
                        <div class="info-box mb-3">
                        <span class="info-box-icon bg-warning elevation-1">
                            <i class="fas fa-fw fa-users"></i>
                        </span>

                            <div class="info-box-content">
                                <span class="info-box-text">
                                    <a href="{{ path('users_index') }}" title="Uživatelé">
                                        Uživatelé
                                    </a>
                                </span>
                                <span class="info-box-number">
                                {% if users is defined and users is not empty %}
                                    {{ users|length }}
                                {% else %}
                                    0
                                {% endif %}
                            </span>
                            </div>
                            <!-- /.info-box-content -->
                        </div>
                        <!-- /.info-box -->
                    </div>
                    <!-- /.col -->
            </div>
            {% endif %}
            <h5 class="mb-2">Vaše oznámení</h5>
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header">
                            <div class="row d-flex align-items-center">
                                <div class="col-md-10 text-center text-md-left pt-3 pb-4 pb-md-0 pt-md-0">
                                    <h3 class="card-title w-100">Přehled nevyřízených oznámení</h3>
                                </div>
                            </div>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body">
                            <table id="notifications"  class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>Stav</th>
                                    <th>Výskyt</th>
                                    <th>Obsah</th>
                                    <th>Přidružené zařízení</th>
                                    <th>Přidružený senzor</th>
                                    <th>Akce</th>
                                </tr>
                                </thead>
                                <tbody>
                                {% if notifications is defined and notifications is not empty %}
                                    {% for notification in notifications %}
                                        <tr>
                                            <td>
                                                {% if notification.state == 1 %}
                                                    <span class="state bg-success">Neaktivní</span>
                                                {% else %}
                                                    <span class="state bg-danger">Aktivní</span>
                                                {% endif %}
                                            </td>
                                            <td>{{ notification.occurrence|date("H:i:s d.m.Y") }}</td>
                                            <td style="max-width: 300px">{{ notification.notificationContent }}</td>
                                            <td>
                                                {% if notification.parentDevice.name is defined and notification.parentDevice.name is not empty %}
                                                    <a href="{{ path('devices_detail', {'id':notification.parentDevice.Id,'origin':app.request.attributes.get('_route')}) }}" title="{{ notification.parentDevice.name }}">
                                                        {{ notification.parentDevice.name }}
                                                    </a>
                                                {% else %}
                                                    <span class="text-info">Nedefinováno</span>
                                                {% endif %}
                                            </td>
                                            <td>
                                                {% if notification.sensor.hardwareId is defined and notification.sensor.hardwareId is not empty %}
                                                    {{ notification.sensor.hardwareId }}
                                                {% else %}
                                                    <span class="text-info">Nedefinováno</span>
                                                {% endif %}
                                            </td>
                                            <td class="text-center">
                                                {% if notification.state == true %}
                                                    <a href="{{ path('notifications_confirm',{'id':notification.id,'origin':app.request.attributes.get('_route')}) }}"
                                                       title="Deaktivovat" class="text-danger m-2">
                                                        <i class="fa-fw fas fa-times"></i>
                                                    </a>
                                                {% else %}
                                                    <a href="{{ path('notifications_confirm',{'id':notification.id,'origin':app.request.attributes.get('_route')}) }}"
                                                       title="Potvrdit" class="text-success m-2">
                                                        <i class="fa-fw fas fa-check"></i>
                                                    </a>
                                                {% endif %}
                                            </td>
                                        </tr>
                                    {% endfor %}
                                {% endif %}
                                <tfoot>
                                <tr>
                                    <th>Stav</th>
                                    <th>Výskyt</th>
                                    <th>Obsah</th>
                                    <th>Přidružené zařízení</th>
                                    <th>Přidružený senzor</th>
                                    <th>Akce</th>
                                </tr>
                                </tfoot>
                            </table>
                        </div>
                        <!-- /.card-body -->
                    </div>
                    <!-- /.card -->

                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </div><!--/. container-fluid -->
    </section>
    <!-- /.content -->
{% endblock %}
{% block stylesheets %}
    {{ parent() }}
    <!-- DataTables -->
    <link rel="stylesheet" href="{{ asset('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css') }}">
    <link rel="stylesheet" href="{{ asset('plugins/datatables-responsive/css/responsive.bootstrap4.min.css') }}">
    <link rel="stylesheet" href="{{ asset('plugins/datatables-buttons/css/buttons.bootstrap4.min.css') }}">
{% endblock %}
{% block javascripts %}
    {{ parent() }}
    <!-- PAGE PLUGINS -->
    <script src="{{ asset('plugins/datatables/jquery.dataTables.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables-responsive/js/dataTables.responsive.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables-responsive/js/responsive.bootstrap4.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables-buttons/js/dataTables.buttons.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables-buttons/js/buttons.bootstrap4.min.js') }}"></script>
    <script src="{{ asset('plugins/jszip/jszip.min.js') }}"></script>
    <script src="{{ asset('plugins/pdfmake/pdfmake.min.js') }}"></script>
    <script src="{{ asset('plugins/pdfmake/vfs_fonts.js') }}"></script>
    <script src="{{ asset('plugins/datatables-buttons/js/buttons.html5.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables-buttons/js/buttons.print.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables-buttons/js/buttons.colVis.min.js') }}"></script>
    <script>
        $(function () {
            var visible = [0, 1, 2, 3, 4]
            $("#notifications").DataTable({
                "paging": true,
                "lengthChange": false,
                "searching": true,
                "ordering": true,
                "info": true,
                "autoWidth": false,
                "responsive": true,
                "buttons": [
                    {
                        extend: 'excelHtml5',
                        title: 'Oznámení',
                        exportOptions: {
                            columns: visible
                        }
                    },
                    {
                        extend: 'pdfHtml5',
                        title: 'Oznámení',
                        exportOptions: {
                            columns: visible
                        }
                    },
                ]
            }).buttons().container().appendTo('#notifications_wrapper .col-md-6:eq(0)');
        });
    </script>
{% endblock %}
