<!DOCTYPE html>
<html>
<head>
    <title>{% block title %}{% endblock %}</title>
    <link rel="icon" type="image/png" href="/static/logo-caterva2-16x16.png">

    {# bootstrap #}
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
          integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
          crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
            integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
            crossorigin="anonymous"></script>

    {# fontawesome #}
    <link href="/static/vendor/fontawesome-6.5.1.min.css" rel="stylesheet">

    {# htmx #}
    <script src="/static/vendor/htmx-2.0.0.min.js"></script>
    <script src="/static/vendor/htmx-idiomorph-ext-0.3.0.min.js"></script>

    {# Project's assets #}
    <script src="/static/main.js"></script>
    <link href="/static/main.css" rel="stylesheet">
</head>

<body class="vh-120">

{% if username %}
<div class="alert alert-info mb-0 rounded-0">
    Logged in as {{ username }}.
    <form action="/auth/jwt/logout" method="post" class="d-inline-block" id="logout-form"
          onsubmit="submitForm(this, '/logout'); return false">
        <button type="submit" class="btn btn-link">Logout</button>
    </form>
</div>
{% endif %}

<div id="alert-error"></div>

<a href="https://ironarray.io/caterva2" target="blank_" class="float-end m-3 text-decoration-none" style="font-size: 1.1rem">
    <i class="fa-regular fa-circle-question"></i> Help
</a>

<!-- Main section -->
<div id="page">
    <div hx-get="{{ roots_url }}" hx-trigger="load"></div>
    <div id="path-list-wrapper">
        {% include 'loading.html' %}
        <div id="path-list"{% if paths_url %} hx-get="{{ paths_url }}" hx-trigger="load"{% endif %}>
        </div>
    </div>
    <div id="meta-wrapper">
        {% include 'loading.html' %}
        <div id="meta"{% if meta_url %} hx-get="{{ meta_url }}" hx-trigger="load"{% endif %}></div>
    </div>
</div>

<script>
document.body.addEventListener('htmx:beforeSwap', function(evt) {
    // Allow 400 responses to swap, we treat these as form validation errors
    let detail = evt.detail;
    if (detail.xhr.status === 400) {
        detail.isError = false;  // Avoid error message in console
        detail.shouldSwap = true;
        detail.target = htmx.find("#alert-error");
    }
});
</script>

</body>
</html>
