<!--
Copyright (C) 2019-2022  Nicola Murino

This program 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, version 3.

This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
-->
{{define "base"}}
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>{{.Branding.Name}} - {{template "title" .}}</title>

    <link rel="shortcut icon" href="{{.StaticURL}}{{.Branding.FaviconPath}}" />

    <!-- Custom fonts for this template-->
    <link href="{{.StaticURL}}/vendor/fontawesome-free/css/fontawesome.min.css" rel="stylesheet" type="text/css">
    <link href="{{.StaticURL}}/vendor/fontawesome-free/css/solid.min.css" rel="stylesheet" type="text/css">
    <link href="{{.StaticURL}}/vendor/fontawesome-free/css/regular.min.css" rel="stylesheet" type="text/css">

    <!-- Custom styles for this template-->
    <link href="{{.StaticURL}}{{.Branding.DefaultCSS}}" rel="stylesheet">
    <style>
        {{template "commoncss" .}}
    </style>
    {{block "extra_css" .}}{{end}}

    {{range .Branding.ExtraCSS}}
    <link href="{{$.StaticURL}}{{.}}" rel="stylesheet" type="text/css">
    {{end}}

</head>

<body id="page-top">

    <!-- Page Wrapper -->
    <div id="wrapper">

        {{if .LoggedAdmin.Username}}
        <!-- Sidebar -->
        <ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">

            <!-- Sidebar - Brand -->
            <div class="sidebar-brand d-flex align-items-center justify-content-center">
                <div class="sidebar-brand-icon">
                    <img src="{{.StaticURL}}{{.Branding.LogoPath}}" alt="logo" style="width: 2rem; height: auto;">
                </div>
                <div class="sidebar-brand-text mx-3" style="text-transform: none;">{{.Branding.ShortName}}</div>
            </div>

            <!-- Divider -->
            <hr class="sidebar-divider my-0">

            {{ if .LoggedAdmin.HasPermission "view_users"}}
            <li class="nav-item {{if eq .CurrentURL .UsersURL}}active{{end}}">
                <a class="nav-link" href="{{.UsersURL}}">
                    <i class="fas fa-users"></i>
                    <span>{{.UsersTitle}}</span></a>
            </li>

            <li class="nav-item {{if eq .CurrentURL .FoldersURL}}active{{end}}">
                <a class="nav-link" href="{{.FoldersURL}}">
                    <i class="fas fa-folder"></i>
                    <span>{{.FoldersTitle}}</span></a>
            </li>
            {{end}}

            {{ if .LoggedAdmin.HasPermission "manage_groups"}}
            <li class="nav-item {{if eq .CurrentURL .GroupsURL}}active{{end}}">
                <a class="nav-link" href="{{.GroupsURL}}">
                    <i class="fas fa-user-friends"></i>
                    <span>{{.GroupsTitle}}</span></a>
            </li>
            {{end}}

            {{ if .LoggedAdmin.HasPermission "manage_event_rules"}}
            <li class="nav-item {{if .IsEventManagerPage}}active{{end}}">
                <a class="nav-link {{if not .IsEventManagerPage}}collapsed{{end}}" href="#" data-toggle="collapse" data-target="#collapseEventManager"
                    aria-expanded="true" aria-controls="collapseEventManager">
                    <i class="fas fa-calendar-alt"></i>
                    <span>Event Manager</span>
                </a>
                <div id="collapseEventManager" class="collapse {{if .IsEventManagerPage}}show{{end}}" aria-labelledby="headingEventManager" data-parent="#accordionSidebar">
                    <div class="bg-white py-2 collapse-inner rounded">
                        <a class="collapse-item {{if eq .CurrentURL .EventRulesURL}}active{{end}}" href="{{.EventRulesURL}}">{{.EventRulesTitle}}</a>
                        <a class="collapse-item {{if eq .CurrentURL .EventActionsURL}}active{{end}}" href="{{.EventActionsURL}}">{{.EventActionsTitle}}</a>
                    </div>
                </div>
            </li>
            {{end}}

            {{ if .LoggedAdmin.HasPermission "view_conns"}}
            <li class="nav-item {{if eq .CurrentURL .ConnectionsURL}}active{{end}}">
                <a class="nav-link" href="{{.ConnectionsURL}}">
                    <i class="fas fa-exchange-alt"></i>
                    <span>{{.ConnectionsTitle}}</span></a>
            </li>
            {{end}}

            {{ if and .HasDefender (.LoggedAdmin.HasPermission "view_defender")}}
            <li class="nav-item {{if eq .CurrentURL .DefenderURL}}active{{end}}">
                <a class="nav-link" href="{{.DefenderURL}}">
                    <i class="fas fa-shield-alt"></i>
                    <span>{{.DefenderTitle}}</span></a>
            </li>
            {{end}}

            {{ if .LoggedAdmin.HasPermission "manage_admins"}}
            <li class="nav-item {{if eq .CurrentURL .AdminsURL}}active{{end}}">
                <a class="nav-link" href="{{.AdminsURL}}">
                    <i class="fas fa-user-cog"></i>
                    <span>{{.AdminsTitle}}</span></a>
            </li>
            {{end}}

            {{ if .LoggedAdmin.HasPermission "manage_system"}}
            <li class="nav-item {{if eq .CurrentURL .MaintenanceURL}}active{{end}}">
                <a class="nav-link" href="{{.MaintenanceURL}}">
                    <i class="fas fa-wrench"></i>
                    <span>{{.MaintenanceTitle}}</span></a>
            </li>
            {{end}}

            {{ if .LoggedAdmin.HasPermission "view_status"}}
            <li class="nav-item {{if eq .CurrentURL .StatusURL}}active{{end}}">
                <a class="nav-link" href="{{.StatusURL}}">
                    <i class="fas fa-info-circle"></i>
                    <span>{{.StatusTitle}}</span></a>
            </li>
            {{end}}

            <!-- Divider -->
            <hr class="sidebar-divider d-none d-md-block">

            <!-- Sidebar Toggler (Sidebar) -->
            <div class="text-center d-none d-md-inline">
                <button class="rounded-circle border-0" id="sidebarToggle"></button>
            </div>

        </ul>
        <!-- End of Sidebar -->
        {{end}}

        <!-- Content Wrapper -->
        <div id="content-wrapper" class="d-flex flex-column">

            <!-- Main Content -->
            <div id="content">

                {{if .LoggedAdmin.Username}}
                <!-- Topbar -->
                <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">

                    <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
                        <i class="fa fa-bars"></i>
                    </button>

                    <!-- Topbar Navbar -->
                    <ul class="navbar-nav ml-auto">
                        {{block "additionalnavitems" .}}{{end}}

                        <!-- Nav Item - User Information -->
                        <li class="nav-item dropdown no-arrow">
                            <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-toggle="dropdown"
                                aria-haspopup="true" aria-expanded="false">
                                <span class="mr-2 d-none d-lg-inline text-gray-600 small">{{.LoggedAdmin.Username}}</span>
                                <i class="fas fa-user fa-fw"></i>
                            </a>
                            <!-- Dropdown - User Information -->
                            <div class="dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="userDropdown">
                                {{if not .HasExternalLogin}}
                                <a class="dropdown-item" href="{{.ProfileURL}}">
                                    <i class="fas fa-user fa-sm fa-fw mr-2 text-gray-400"></i>
                                    Profile
                                </a>
                                <a class="dropdown-item" href="{{.ChangePwdURL}}">
                                    <i class="fas fa-key fa-sm fa-fw mr-2 text-gray-400"></i>
                                    Change password
                                </a>
                                {{if .LoggedAdmin.CanManageMFA}}
                                <a class="dropdown-item" href="{{.MFAURL}}">
                                    <i class="fas fa-user-lock fa-sm fa-fw mr-2 text-gray-400"></i>
                                    Two-Factor Auth
                                </a>
                                {{end}}
                                <div class="dropdown-divider"></div>
                                {{end}}
                                <a class="dropdown-item" href="#" data-toggle="modal" data-target="#logoutModal">
                                    <i class="fas fa-sign-out-alt fa-sm fa-fw mr-2 text-gray-400"></i>
                                    Logout
                                </a>
                            </div>
                        </li>

                    </ul>

                </nav>
                <!-- End of Topbar -->
                {{end}}

                <!-- Begin Page Content -->
                <div class="container-fluid">

                    {{template "page_body" .}}

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

            </div>
            <!-- End of Main Content -->
            {{if .LoggedAdmin.Username}}
            <!-- Footer -->
            <footer class="sticky-footer bg-white">
                <div class="container my-auto">
                    <div class="copyright text-center my-auto">
                        <span>SFTPGo {{.Version}}</span>
                    </div>
                </div>
            </footer>
            <!-- End of Footer -->
            {{end}}

        </div>
        <!-- End of Content Wrapper -->

    </div>
    <!-- End of Page Wrapper -->

    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
        <i class="fas fa-angle-up"></i>
    </a>

    {{if .LoggedAdmin.Username}}
    <!-- Logout Modal-->
    <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel"
        aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="modalLabel">Ready to Leave?</h5>
                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
                <div class="modal-footer">
                    <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                    <a class="btn btn-primary" href="{{.LogoutURL}}">Logout</a>
                </div>
            </div>
        </div>
    </div>
    {{end}}

    {{block "dialog" .}}{{end}}

    <!-- Bootstrap core JavaScript-->
    <script src="{{.StaticURL}}/vendor/jquery/jquery.min.js"></script>
    <script src="{{.StaticURL}}/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="{{.StaticURL}}/vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="{{.StaticURL}}/js/sb-admin-2.min.js"></script>

    <script type="text/javascript">
        function escapeHTML(str) {
            var div = document.createElement('div');
            div.appendChild(document.createTextNode(str));
            return div.innerHTML;
        }

        function unescapeHTML(escapedStr) {
            var div = document.createElement('div');
            div.innerHTML = escapedStr;
            var child = div.childNodes[0];
            return child ? child.nodeValue : '';
        }

        function fixedEncodeURIComponent(str) {
            return encodeURIComponent(unescapeHTML(str)).replace(/[!'()*]/g, function (c) {
                return '%' + c.charCodeAt(0).toString(16);
            });
        }
    </script>

    <!-- Page level plugins -->
    {{block "extra_js" .}}{{end}}

</body>

</html>
{{end}}