<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ title }}</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
    <!-- Icons (optional) -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css"
        integrity="sha512-Kc323vGBEqzTmouAECnVceyQqyqdsSiqLQISBL29aUW4U/M7pSPA/gEUZQqv1cwx4OnYxTxve5UMg5GT6L4JJg=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
        <link rel="icon" type="image/x-icon" href="/static/images/favicon.ico">

    <script src="https://unpkg.com/htmx.org"></script>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"
        integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
    
</head>

<body>
    <!-- Sidebar container with static sidebar for larger screens and offcanvas for mobile -->
    <div class="d-flex">
        <!-- Offcanvas sidebar for mobile screens -->
        <div class="offcanvas offcanvas-start d-md-none" tabindex="-1" id="mobileSidebar"
            aria-labelledby="mobileSidebarLabel">
            <div class="offcanvas-header">
                <h5 class="offcanvas-title" id="mobileSidebarLabel">Jellyplist</h5>
                <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
            </div>
            <div class="offcanvas-body">
                <nav>
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link" href="/playlists"><i class="fab fa-spotify"></i> Featured</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/categories"><i class="fa-solid fa-layer-group"></i>
                                Categories</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/playlists/monitored"><i
                                    class="fa-solid fa-tower-observation"></i> Monitored</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/jellyfin_playlists"><i class="fas fa-list"></i> Jellyfin
                                Playlists</a>
                        </li>
                        {% if session.get('is_admin') and session.get('debug') %}
                        <li class="nav-item">
                            <a class="nav-link" href="/admin"><i class="fas fa-flask"></i> Admin</a>
                        </li>
                        {% endif %}
                        <li class="nav-item">
                            <a class="nav-link" href="/logout"><i class="fas fa-sign-in-alt"></i> Logout</a>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>

        <!-- Sidebar for larger screens -->
        <div class="d-none d-md-block sidebar p-4 vh-100 sticky-top">
            <nav>
                <div class="sidebar-logo mb-4 text-center text-white">
                    <img src="/static/images/logo_large.png" alt="Logo">
                </div>
                <ul class="nav flex-column">
                    <li class="nav-item">
                        <a class="nav-link text-white" href="/playlists"><i class="fab fa-spotify"></i> Featured</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-white" href="/categories"><i class="fa-solid fa-layer-group"></i>
                            Categories</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-white" href="/playlists/monitored"><i
                                class="fa-solid fa-tower-observation"></i> Monitored </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-white" href="/jellyfin_playlists"><i class="fas fa-list"></i> Jellyfin
                            Playlists</a>
                    </li>
                    {% if session.get('is_admin') %}
                    <li class="nav-item">
                        
                        <a class="nav-link text-white" href="/admin"><i class="fas fa-flask"></i> Admin
                            {% include 'partials/_unlinked_tracks_badge.html' %}
                        </a>
                    </li>
                    {% endif %}
                    <li class="nav-item">
                        <a class="nav-link text-white" href="/logout"><i class="fas fa-sign-in-alt"></i> Logout</a>
                    </li>
                </ul>
            </nav>
            <span class="fixed-bottom m-3">{{version}}</span>
        </div>

        <!-- Main content with toggle button for mobile sidebar -->
        <div class="container-fluid p-4 ">
            <div class="d-flex justify-content-between align-items-center">
                <!-- Toggle button for mobile sidebar -->
                <button class="btn btn-primary d-md-none" type="button" data-bs-toggle="offcanvas"
                    data-bs-target="#mobileSidebar" aria-controls="mobileSidebar">
                    <i class="fas fa-bars"></i>
                </button>

                <h1 class="mb-4 ms-3">{{ title }}</h1>

                <div class="d-flex align-items-center ">
                    <form action="/search" method="GET" class="w-100">
                        <div class="input-group">
                            <input
                                type="search"
                                class="form-control"
                                name="query"
                                placeholder="Search Spotify..."
                                aria-label="Search"
                            >
                            <button class="btn btn-primary" type="submit">Search</button>
                        </div>
                    </form>
                    <div class="ms-4">
                        <!-- Display Initials Badge -->
                        <span >{{ session.get('jellyfin_user_name') }}</span>
                    </div>
                </div>

            </div>

            {% block content %}{% endblock %}
        </div>
    </div>
    <div id="alerts"></div>
    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        document.addEventListener("showToastMessages", function () {
            console.log("showToastMessages")
            var toastElements = document.querySelectorAll('.toast');
            console.log(toastElements)

            toastElements.forEach(function (toastNode) {
                var toast = new bootstrap.Toast(toastNode);
                console.log(toast);

                toast.show();
            });
        });

        document.addEventListener("htmx:afterSwap", (event) => {
            console.log("htmx.afterswap")
            var toastElements = document.querySelectorAll('.toast');
            console.log(toastElements)
            toastElements.forEach(function (toastNode) {
                var toast = new bootstrap.Toast(toastNode);
                console.log(toast);
                toast.show();
            });
        });
    </script>
    <script src="/static/js/preview.js"></script>
    {% block scripts %}
    {% endblock %}
</body>

</html>