{% load static %}
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>File: {{ image_path.name }}</title>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.0/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer">
        <link href="{% static 'css/styles.css' %}" rel="stylesheet">
        <noscript>
            <link href="{% static 'css/noscript.css' %}" rel="stylesheet">
        </noscript>
    </head>
    <body class="theme-{{ theme }}">
        <div class="app-shell d-flex">
            <aside class="sidebar d-none d-lg-flex flex-column">
                <div class="d-flex align-items-center user-row">
                    <span><i class="fa-solid fa-circle-user fa-lg"></i></span>
                    <span class="user-name text-truncate">{{ request.user.username }}</span>
                    <a class="btn btn-sm btn-plain ms-auto" href="{{ theme_toggle_url }}" aria-label="Toggle theme">
                        {% if theme == 'dark' %}
                            <i class="fa-solid fa-sun"></i>
                        {% else %}
                            <i class="fa-solid fa-moon"></i>
                        {% endif %}
                    </a>
                </div>

                <hr>

                <a href="/gallery/favorites/" class="sidebar-link {% if is_special and breadcrumbs.0.label == 'Favorites' %}active-sort{% endif %}">Favorites</a>
                <a href="/gallery/most-visited/" class="sidebar-link {% if is_special and breadcrumbs.0.label == 'Most Visited' %}active-sort{% endif %}">Most visited</a>
                <a href="/gallery/recent/" class="sidebar-link {% if is_special and breadcrumbs.0.label == 'Recent' %}active-sort{% endif %}">Recently visited</a>

                <hr>

                <div class="sidebar-scroll flex-grow-1">
                    {% if not is_special or is_special and 'favorites' in breadcrumbs.0.path %}
                        {% if prev_url %}
                            <a href="{{ prev_url }}" class="subdir-item">
                                {% if prev_thumb %}
                                    <img src="{{ prev_thumb }}" class="subdir-thumb" alt="prev thumb">
                                {% else %}
                                    <span class="subdir-fallback"><i class="fa-solid fa-image"></i></span>
                                {% endif %}
                                <span>Previous</span>
                            </a>
                        {% else %}
                            <div class="subdir-item text-muted">
                                <span class="subdir-fallback"><i class="fa-solid fa-image"></i></span>
                                <span>Previous</span>
                            </div>
                        {% endif %}

                        {% if next_url %}
                            <a href="{{ next_url }}" class="subdir-item">
                                {% if next_thumb %}
                                    <img src="{{ next_thumb }}" class="subdir-thumb" alt="next thumb">
                                {% else %}
                                    <span class="subdir-fallback"><i class="fa-solid fa-image"></i></span>
                                {% endif %}
                                <span>Next</span>
                            </a>
                        {% else %}
                            <div class="subdir-item text-muted">
                                <span class="subdir-fallback"><i class="fa-solid fa-image"></i></span>
                                <span>Next</span>
                            </div>
                        {% endif %}
                    {% endif %}

                    {% if is_special %}
                        <a href="{{ breadcrumbs.0.path }}" class="subdir-item">
                            {% if back_thumb %}
                                <img src="{{ back_thumb }}" class="subdir-thumb" alt="back thumb">
                            {% else %}
                                <span class="subdir-fallback"><i class="fa-solid fa-image"></i></span>
                            {% endif %}
                            <span>Back</span>
                        </a>
                    {% else %}
                        <a href="{{ back_url }}" class="subdir-item">
                            {% if back_thumb %}
                                <img src="{{ back_thumb }}" class="subdir-thumb" alt="back thumb">
                            {% else %}
                                <span class="subdir-fallback"><i class="fa-solid fa-image"></i></span>
                            {% endif %}
                            <span>Back</span>
                        </a>
                    {% endif %}

                    <a href="{{ home_url }}" class="subdir-item">
                        {% if home_thumb %}
                            <img src="{{ home_thumb }}" class="subdir-thumb" alt="home thumb">
                        {% else %}
                            <span class="subdir-fallback"><i class="fa-solid fa-image"></i></span>
                        {% endif %}
                        <span>Home</span>
                    </a>
                </div>

                <hr>

                <form method="post" action="{% url 'logout' %}">
                    {% csrf_token %}
                    <button type="submit" class="btn btn-sm btn-plain w-100">
                        <i class="fa-solid fa-arrow-up-from-bracket"></i>
                        <span class="ms-1">Logout</span>
                    </button>
                </form>
            </aside>

            <main class="main-area d-flex flex-column flex-grow-1">
                <div class="top-bar d-flex align-items-center gap-2">
                    <button class="btn btn-sm btn-plain sidebar-toggle d-lg-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#sidebarOffcanvas" aria-controls="sidebarOffcanvas" aria-label="Open menu">
                        <i class="fa-solid fa-bars"></i>
                    </button>

                    <div class="breadcrumb-wrap flex-grow-1">
                        {% for crumb in breadcrumbs %}
                            {% if not forloop.first %}
                                <span class="crumb-sep">/</span>
                            {% endif %}
                            {% if crumb.path %}
                                <a href="{{ crumb.path }}" class="{% if not forloop.last %}crumb-link{% else %}crumb-link-last{% endif %}">{{ crumb.label }}</a>
                            {% else %}
                                <span class="{% if not forloop.last %}crumb-link{% else %}crumb-link-last{% endif %}">{{ crumb.label }}</span>
                            {% endif %}
                        {% endfor %}
                    </div>

                    <form method="post" action="{% url 'gallery_view_path' path=path %}">
                        {% csrf_token %}
                        <button class="btn btn-sm btn-plain" type="submit" title="Favorite" aria-label="Fav image" name="favorite">
                            {% if image_meta.favorite %}
                                <i class="fa-solid fa-star"></i>
                            {% else %}
                                <i class="fa-regular fa-star"></i>
                            {% endif %}
                        </button>
                    </form>

                    <div class="dropdown ms-auto">
                        <button class="btn btn-sm btn-plain" type="button" data-bs-toggle="dropdown" aria-expanded="false" title="Info" aria-label="Image info">
                            <i class="fa-solid fa-circle-info"></i>
                        </button>
                        <div class="dropdown-menu dropdown-menu-end info-menu p-2">
                            <div style="max-height:300px; overflow:auto;">
                                <div class="small text-muted">{{ image_meta.filename|truncatechars:40 }}</div>
                                {% if image_meta.width and image_meta.height %}
                                    <div>{{ image_meta.width }} x {{ image_meta.height }} px</div>
                                {% endif %}
                                {% if image_meta.filesize %}
                                    <div>{{ image_meta.filesize }}</div>
                                {% endif %}
                                {% if image_meta.created %}
                                    <div class="small text-muted">Creation date</div>
                                    <div>{{ image_meta.created }}</div>
                                {% endif %}
                                {% if image_meta.modified %}
                                    <div class="small text-muted">Modification date</div>
                                    <div>{{ image_meta.modified }}</div>
                                {% endif %}
                                {% if image_meta.visits %}
                                    <div class="small text-muted">Visits:</div>
                                    <div>{{ image_meta.visits }}</div>
                                {% endif %}
                                {% if image_meta.visited %}
                                    <div class="small text-muted">Last visit:</div>
                                    <div>{{ image_meta.visited }}</div>
                                {% endif %}
                            </div>
                        </div>
                    </div>
                </div>

                <section class="gallery-scroll flex-grow-1 d-flex">
                    <div class="image-content w-100">
                        <div class="image-wrapper">
                            <a href="{{ image_path }}" target="_blank">
                                <img src="{{ image_path }}" alt="{{ image_path.name }}" class="image-full">
                            </a>
                        </div>
                    </div>
                </section>
            </main>
        </div>

        <div class="offcanvas offcanvas-start" tabindex="-1" id="sidebarOffcanvas" aria-labelledby="sidebarOffcanvasLabel">
            <div class="offcanvas-header pb-2">
                <div class="d-flex align-items-center user-row w-100 gap-2">
                    <span><i class="fa-solid fa-circle-user fa-lg"></i></span>
                    <span class="user-name w-100 text-truncate">{{ request.user.username }}</span>
                    <a class="btn btn-sm btn-plain" href="{{ theme_toggle_url }}" aria-label="Toggle theme">
                        {% if theme == 'dark' %}
                            <i class="fa-solid fa-sun"></i>
                        {% else %}
                            <i class="fa-solid fa-moon"></i>
                        {% endif %}
                    </a>
                    <button type="button" class="btn btn-sm btn-plain sidebar-close" data-bs-dismiss="offcanvas" aria-label="Close menu">
                        <i class="fa-solid fa-xmark"></i>
                    </button>
                </div>
            </div>
            <div class="offcanvas-body pt-0 d-flex flex-column">
                <a href="/gallery/favorites/" class="sidebar-link {% if is_special and breadcrumbs.0.label == 'Favorites' %}active-sort{% endif %}">Favorites</a>
                <a href="/gallery/most-visited/" class="sidebar-link {% if is_special and breadcrumbs.0.label == 'Most Visited' %}active-sort{% endif %}">Most visited</a>
                <a href="/gallery/recent/" class="sidebar-link {% if is_special and breadcrumbs.0.label == 'Recent' %}active-sort{% endif %}">Recently visited</a>

                <hr>

                <div class="sidebar-scroll flex-grow-1">
                    {% if not is_special or is_special and 'favorites' in breadcrumbs.0.path %}
                        {% if prev_url %}
                            <a href="{{ prev_url }}" class="subdir-item">
                                {% if prev_thumb %}
                                    <img src="{{ prev_thumb }}" class="subdir-thumb" alt="prev thumb">
                                {% else %}
                                    <span class="subdir-fallback"><i class="fa-solid fa-image"></i></span>
                                {% endif %}
                                <span>Previous</span>
                            </a>
                        {% endif %}

                        {% if next_url %}
                            <a href="{{ next_url }}" class="subdir-item">
                                {% if next_thumb %}
                                    <img src="{{ next_thumb }}" class="subdir-thumb" alt="next thumb">
                                {% else %}
                                    <span class="subdir-fallback"><i class="fa-solid fa-image"></i></span>
                                {% endif %}
                                <span>Next</span>
                            </a>
                        {% endif %}
                    {% endif %}

                    {% if is_special %}
                        <a href="{{ breadcrumbs.0.path }}" class="subdir-item">
                            {% if back_thumb %}
                                <img src="{{ back_thumb }}" class="subdir-thumb" alt="back thumb">
                            {% else %}
                                <span class="subdir-fallback"><i class="fa-solid fa-image"></i></span>
                            {% endif %}
                            <span>Back</span>
                        </a>
                    {% else %}
                        <a href="{{ back_url }}" class="subdir-item">
                            {% if back_thumb %}
                                <img src="{{ back_thumb }}" class="subdir-thumb" alt="back thumb">
                            {% else %}
                                <span class="subdir-fallback"><i class="fa-solid fa-image"></i></span>
                            {% endif %}
                            <span>Back</span>
                        </a>
                    {% endif %}

                    <a href="{{ home_url }}" class="subdir-item">
                        {% if home_thumb %}
                            <img src="{{ home_thumb }}" class="subdir-thumb" alt="home thumb">
                        {% else %}
                            <span class="subdir-fallback"><i class="fa-solid fa-image"></i></span>
                        {% endif %}
                        <span>Home</span>
                    </a>
                </div>

                <hr>

                <form method="post" action="{% url 'logout' %}">
                    {% csrf_token %}
                    <button type="submit" class="btn btn-sm btn-plain w-100">
                        <i class="fa-solid fa-arrow-up-from-bracket"></i>
                        <span class="ms-1">Logout</span>
                    </button>
                </form>
            </div>
        </div>

        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
    </body>
</html>
