<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{% if page_title %}{{ page_title }} | {% endif %}routerfleet</title>

    <!-- Google Font: Source Sans Pro -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="/static/AdminLTE-3.2.0/plugins/fontawesome-free/css/all.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="/static/AdminLTE-3.2.0/plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
    <link rel="stylesheet" href="/static/AdminLTE-3.2.0/plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
    <link rel="stylesheet" href="/static/AdminLTE-3.2.0/plugins/datatables-buttons/css/buttons.bootstrap4.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
    <!-- Tempusdominus Bootstrap 4 -->
    <link rel="stylesheet" href="/static/AdminLTE-3.2.0/plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="/static/AdminLTE-3.2.0/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
    <!-- JQVMap -->
    <link rel="stylesheet" href="/static/AdminLTE-3.2.0/plugins/jqvmap/jqvmap.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="/static/AdminLTE-3.2.0/dist/css/adminlte.min.css">
    <!-- overlayScrollbars -->
    <link rel="stylesheet" href="/static/AdminLTE-3.2.0/plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="/static/AdminLTE-3.2.0/plugins/daterangepicker/daterangepicker.css">
    <!-- chosen -->
    <link rel="stylesheet" href="/static/plugins/chosen/bootstrap-chosen.css">

    <style>
        .dataTables_filter, .dataTables_length{
            padding-top: 10px;
        }
        .datatables-with-export, .datatables-no-export{
            display: none;
        }
        .min-width {
            width: 1%;
            white-space: nowrap;
        }
        .preloader{
            display: none;
        }
    </style>

    {% block page_custom_head %}{% endblock%}
</head>
{% load custom_tags %}
{% tag_webadmin_version as webadmin_version %}

<body class="hold-transition sidebar-mini layout-fixed {% if request.COOKIES.sidebarState == 'collapsed' %}sidebar-collapse{% endif %}">
<div class="wrapper">

    <!-- Preloader -->
    <div class="preloader flex-column justify-content-center align-items-center">
    </div>

    <!-- Navbar -->
    <nav class="main-header navbar navbar-expand navbar-white navbar-light">
        <!-- Left navbar links -->
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
            </li>
            <li class="nav-item d-none d-sm-inline-block">
                <a href="/" class="nav-link">Home</a>
            </li>
            <li class="nav-item d-none d-sm-inline-block">
                <a href="/status/" class="nav-link">Status</a>
            </li>
        </ul>

        <!-- Right navbar links -->
        <ul class="navbar-nav ml-auto">
            <li class="nav-item">
                <a href="/accounts/logout/" class="nav-link">
                    <i class="fas fa-sign-out-alt"></i>
                </a>
            </li>
        </ul>
    </nav>
    <!-- /.navbar -->

    <!-- Main Sidebar Container -->
    <aside class="main-sidebar sidebar-dark-primary elevation-4">
        <!-- Brand Logo -->
        <a href="/" class="brand-link">
            <span class="brand-text font-weight-light">routerfleet</span>
        </a>

        <!-- Sidebar -->
        <div class="sidebar">
            <!-- Sidebar Menu -->
            <nav class="mt-2">
                <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
                    <!-- Add icons to the links using the .nav-icon class with font-awesome or any other icon font library -->
                    <li class="nav-item">
                        <a href="/" class="nav-link {% if '/' == request.path %}active{% endif %}">
                            <i class="fas fa-home nav-icon"></i>
                            <p>
                                Home
                            </p>
                        </a>
                    </li>

                    <li class="nav-item">
                        <a href="/status/" class="nav-link {% if '/status/' in request.path %}active{% endif %}">
                            <i class="fas fa-tachometer-alt nav-icon"></i>
                            <p>
                                Status
                            </p>
                        </a>
                    </li>


                    <li class="nav-item">
                        <a href="/router/list/" class="nav-link {% if '/router/' in request.path %}active{% endif %}">
                            <i class="fas fa-network-wired nav-icon"></i>
                            <p>
                                Router Manager
                            </p>
                        </a>
                    </li>


                    <li class="nav-item">
                        <a href="/backup/profile_list/" class="nav-link {% if '/backup/' in request.path %}active{% endif %}">
                            <i class="fas fa-box-open"></i>
                            <p>
                                Backup
                            </p>
                        </a>
                    </li>

                    <li class="nav-item">
                        <a href="/user/list/" class="nav-link {% if '/user/' in request.path %}active{% endif %}">
                            <i class="fas fa-users nav-icon"></i>
                            <p>
                                User Manager
                            </p>
                        </a>
                    </li>
                
                    <li class="nav-item">
                        <a href="/message_center/channel_list/" class="nav-link {% if '/message_center/' in request.path %}active{% endif %}">
                            <i class="far fa-envelope nav-icon"></i>
                            <p>
                                Message Center
                            </p>
                        </a>
                    </li>

                    <li class="nav-item">
                        <a href="/wireguard_webadmin/" class="nav-link {% if '/wireguard_webadmin/' in request.path %}active{% endif %}">
                            <i class="fas fa-project-diagram nav-icon"></i>
                            <p>
                                WireGuard WebAdmin
                            </p>
                        </a>
                    </li>

                </ul>
            </nav>
            <!-- /.sidebar-menu -->
        </div>
        <!-- /.sidebar -->
    </aside>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <div class="content-header">
            <div class="container-fluid">

            </div><!-- /.container-fluid -->
        </div>
        <!-- /.content-header -->

        <!-- Generic Modal Structure -->
        <div class="modal fade" id="genericModal" tabindex="-1" aria-labelledby="genericModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="genericModalLabel">Modal Title</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body" id="genericModalBody">
                        <!-- Content will be loaded here -->
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal" id="genericModalCloseButton">Close</button>
                        <a href="#" class="btn btn-primary" id="genericModalActionButton">Action</a>
                    </div>
                </div>
            </div>
        </div>

        <!-- End modal -->

        <!-- Main content -->




        <section class="content">
            <div class="container-fluid">
                {% block content %}{% endblock %}
            </div><!-- /.container-fluid -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <footer class="main-footer">
        {% if webadmin_version.update_available %}<a class='btn btn-sm btn-danger' id="btn_update_changelog">Update Available</a>{% else %}routerfleet {% endif %}
        <div class="float-right d-none d-sm-inline-block">
            <b>Version</b> {{ webadmin_version.current_version }}
        </div>
    </footer>

    <!-- Control Sidebar -->
    <aside class="control-sidebar control-sidebar-dark">
        <!-- Control sidebar content goes here -->
    </aside>
    <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="/static/AdminLTE-3.2.0/plugins/jquery/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="/static/AdminLTE-3.2.0/plugins/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
    $.widget.bridge('uibutton', $.ui.button)
</script>
<!-- Bootstrap 4 -->
<script src="/static/AdminLTE-3.2.0/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- ChartJS -->
<script src="/static/AdminLTE-3.2.0/plugins/chart.js/Chart.min.js"></script>
<!-- Sparkline -->
<script src="/static/AdminLTE-3.2.0/plugins/sparklines/sparkline.js"></script>
<!-- JQVMap -->
<script src="/static/AdminLTE-3.2.0/plugins/jqvmap/jquery.vmap.min.js"></script>
<script src="/static/AdminLTE-3.2.0/plugins/jqvmap/maps/jquery.vmap.usa.js"></script>
<!-- jQuery Knob Chart -->
<script src="/static/AdminLTE-3.2.0/plugins/jquery-knob/jquery.knob.min.js"></script>
<!-- daterangepicker -->
<script src="/static/AdminLTE-3.2.0/plugins/moment/moment.min.js"></script>
<script src="/static/AdminLTE-3.2.0/plugins/daterangepicker/daterangepicker.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="/static/AdminLTE-3.2.0/plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
{% comment %}<!-- Summernote -->
<script src="/static/AdminLTE-3.2.0/plugins/summernote/summernote-bs4.min.js"></script>
{% endcomment %}
<!-- overlayScrollbars -->
<script src="/static/AdminLTE-3.2.0/plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<!-- DataTables  & Plugins -->
<script src="/static/AdminLTE-3.2.0/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="/static/AdminLTE-3.2.0/plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="/static/AdminLTE-3.2.0/plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="/static/AdminLTE-3.2.0/plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="/static/AdminLTE-3.2.0/plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="/static/AdminLTE-3.2.0/plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="/static/AdminLTE-3.2.0/plugins/jszip/jszip.min.js"></script>
<script src="/static/AdminLTE-3.2.0/plugins/pdfmake/pdfmake.min.js"></script>
<script src="/static/AdminLTE-3.2.0/plugins/pdfmake/vfs_fonts.js"></script>
<script src="/static/AdminLTE-3.2.0/plugins/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="/static/AdminLTE-3.2.0/plugins/datatables-buttons/js/buttons.print.min.js"></script>
<script src="/static/AdminLTE-3.2.0/plugins/datatables-buttons/js/buttons.colVis.min.js"></script>
<!-- AdminLTE App -->
<script src="/static/AdminLTE-3.2.0/dist/js/adminlte.js"></script>
<!-- chosen -->
<script src="/static/plugins/chosen/chosen.jquery.min.js"></script>
{% comment %}<script src="/static/AdminLTE-3.2.0/dist/js/pages/dashboard.js"></script>{% endcomment %}
<script>
    $('.selectmultiple').chosen();
    $('.select').chosen();
</script>
<script>
    var dataTable;
    $(function () {
        $(".datatables-with-export").DataTable({
            "responsive": true, "lengthChange": false, "autoWidth": false,
            "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
        }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
        dataTable = $('.datatables-no-export').DataTable({
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "order": [],
            "info": true,
            "autoWidth": false,
            "responsive": true,
        });
    });
    $('.datatables-with-export').show();
    $('.datatables-no-export').show();
</script>
<script>
    $(document).ready(function() {
        const webadminVersion = '{{ webadmin_version.current_version }}';
        $('#btn_update_changelog').on('click', function() {
            $.ajax({
                url: `https://updates.eth0.com.br/api/application_changelog/?app=routerfleet&version=${webadminVersion}`,
                type: 'GET',
                success: function(response) {
                    const updates = response.updates.sort((a, b) => new Date(b.release_date) - new Date(a.release_date));
                    let updatesHtml = '';
                    updates.forEach(update => {
                        updatesHtml += `<div class="update">
                                        <h5>Version ${update.version}</h5>
                                        <p>${update.release_notes.replace(/\r\n/g, "<br>")}</p>
                                    </div>`;
                    });

                    // Update modal content
                    $('#genericModalLabel').text('routerfleet Updates');
                    $('#genericModalBody').html(updatesHtml);
                    $('#genericModalCloseButton').text('Close');
                    $('#genericModalActionButton').text('Update Instructions').attr('href', 'https://github.com/eduardogsilva/routerfleet').attr('target', '_blank');

                    // Show modal
                    $('#genericModal').modal('show');
                },
                error: function(xhr, status, error) {
                    // Update modal for error display
                    $('#genericModalLabel').text('Error');
                    $('#genericModalBody').html('<p>An error occurred while fetching the update information. Please try again later.</p>');
                    $('#genericModalCloseButton').text('Close');
                    $('#genericModalActionButton').hide(); // Hide the action button in case of error

                    // Show modal
                    $('#genericModal').modal('show');
                    console.error("An error occurred while fetching updates: ", error);
                }
            });
        });
    });


</script>

<script>
    function setCookie(name, value, days) {
        var expires = "";
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days*24*60*60*1000));
            expires = "; expires=" + date.toUTCString();
        }
        document.cookie = name + "=" + (value || "")  + expires + "; path=/";
    }
</script>



<script>
    function getCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }
</script>

<script>
    $(document).ready(function() {
        var sidebarState = getCookie('sidebarState');
        if (sidebarState === 'collapsed') {
            $('body').addClass('sidebar-collapse');
        }

        $('[data-widget="pushmenu"]').on('click', function(event) {
            event.preventDefault();
            setTimeout(function() {
                if ($('body').hasClass('sidebar-collapse')) {
                    setCookie('sidebarState', 'collapsed', 7);
                } else {
                    setCookie('sidebarState', 'opened', 7);
                }
            }, 500);
        });
    });
</script>


{% include "template_messages.html" %}

{% block custom_page_scripts %}

{% endblock %}

</body>
</html>