<!DOCTYPE html>
<html lang="en">
<head>
    {% block head %}
    <title>{% block title %}{% endblock %} - OpenGnsys</title>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Font Awesome Icons -->
    <link rel="stylesheet" href="{{ url_for('static', filename='AdminLTE/plugins/fontawesome-free/css/all.min.css') }}">
    <!-- Theme style -->
    <link rel="stylesheet" href="{{ url_for('static', filename='AdminLTE/dist/css/adminlte.min.css') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/soleta.css') }}" />
    {% endblock %}
</head>
<body>
    <div class="main d-flex flex-column align-items-stretch h-100">
        <nav class="ogcp-nav navbar navbar-expand-lg navbar-dark bg-dark">
            <a class="navbar-brand" href="#">OpenGnsys</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>

            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav mr-auto">
                    {% if current_user.is_authenticated %}
                    <li class="nav-item {% block nav_dashboard%}{% endblock %}">
                        <a class="nav-link" href="{{ url_for('index') }}">{{ _('Dashboard') }}<span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item {% block nav_commands%}{% endblock %}">
                        <a class="nav-link" href="{{ url_for('commands') }}">{{ _('Commands') }}</a>
                    </li>
                    <li class="nav-item {% block nav_images%}{% endblock %}">
                        <a class="nav-link" href="{{ url_for('images') }}">{{ _('Images') }}</a>
                    </li>
                    {% if current_user.admin %}
                    <li class="nav-item {% block nav_scopes%}{% endblock %}">
                        <a class="nav-link" href="{{ url_for('scopes') }}">{{ _('Scopes management') }}</a>
                    </li>
                    <li class="nav-item {% block nav_servers %}{% endblock %}">
                        <a class="nav-link" href="{{ url_for('manage_servers') }}">{{ _('Servers') }}</a>
                    </li>
                    <li class="nav-item {% block nav_users %}{% endblock %}">
                        <a class="nav-link" href="{{ url_for('users') }}">{{ _('Users') }}</a>
                    </li>
                    {% endif %}
                    {% endif %}
                </ul>

                <ul class="nav navbar-nav navbar-right">
                    {% if current_user.is_authenticated %}

                    <li class="nav-item">
                        <a class="btn btn-danger" href="{{ url_for('logout') }}">{{ _('Logout') }}</a>
                    </li>

                    {% else %}

                    <li class="nav-item">
                        <a class="btn btn-primary" href="{{ url_for('login') }}">{{ _('Login') }}</a>
                    </li>

                    {% endif %}
                </ul>
            </div>
        </nav>
        <div class="container-fluid flex-grow-1">
            {% block container %}
            <div class="row h-100">
                    {# The sidebar is not visible on index and login #}
                    {% if request.endpoint not in ["index", "login"] %}
                        <div id="sidebar" class="bg-light col-md-3 col-lg-2">
                            {% block sidebar %}{% endblock %}
                        </div>
                    {% else %}
                    {% endif %}
                    <div id="content" class="col">
                        <div id="commands" class="py-2">{% block commands %}{% endblock %}</div>
                        <div class="container">
                            {% block content %}{% endblock %}
                        </div>
                    </div>
            </div>
            {% endblock %}
        </div>

        {% block footer %}
        <footer class="footer navbar-inverse bg-dark flex-shrink-0" role="contentinfo">
            <div class="text-center text-secondary mt-1 p-3">
                Powered by
                <a class="text-light" href="https://opengnsys.soleta.eu/">Soleta Networks</a>
            </div>
        </footer>
        {% endblock %}
    </div>

    <!-- jQuery -->
    <script src="{{ url_for('static', filename='AdminLTE/plugins/jquery/jquery.min.js') }}"></script>
    <!-- Bootstrap 4 -->
    <script src="{{ url_for('static', filename='AdminLTE/plugins/bootstrap/js/bootstrap.bundle.min.js') }}"></script>
    <!-- AdminLTE App -->
    <script src="{{ url_for('static', filename='AdminLTE/dist/js/adminlte.min.js') }}"></script>
    <!-- ChartJS -->
    <script src="{{ url_for('static', filename='AdminLTE/plugins/chart.js/Chart.min.js') }}"></script>

    <script src="{{ url_for('static', filename='js/ogcp.js') }}"></script>

    <script>
        // error messages
        {% for category, message in get_flashed_messages(with_categories=True) %}
            let bgclass = 'bg-success';
            {% if category == 'info' %}
                bgclass = 'bg-info';
            {% elif category == 'error' %}
                bgclass = 'bg-danger';
            {% else %}
                bgclass = 'bg-warning';
            {% endif %}
            $(document).Toasts('create', {
                class: bgclass,
                position: 'bottomRight',
                autohide: true,
                delay: 30000,
                title: '{{ message }}',
            })
        {% endfor %}
    </script>

    {% block extrabody %}{% endblock %}
</body>
</html>
