{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ PROJECT_NAME }}</title> <!-- Use dynamic title -->
    <link rel="icon" type="image/png" href="{% static BRAND_LOGO %}">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.1/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.10.5/font/bootstrap-icons.min.css">
    <style>
        body {
            margin: 0;
            display: flex;
            height: 100vh;
            font-family: Arial, sans-serif;
            background-color: #f4f5f7;
        }

        /* Sidebar */
        .sidebar {
            width: 250px;
            background-color: #343a40;
            color: white;
            display: flex;
            flex-direction: column;
            position: fixed;
            top: 0;
            left: 0;
            bottom: 0;
        }

        .sidebar .logo {
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 10px;
            background-color: #212529;
            font-size: 1.2rem;
            font-weight: bold;
            color: white;
            position: sticky;
            top: 0;
            z-index: 10;
        }

        .sidebar .logo img {
            width: 60px;
            height: 60px;
            margin-right: 10px;
        }

        .menu-items {
            overflow-y: auto;
            flex: 1;
            padding: 10px;
        }

        .menu-items a {
            padding: 15px;
            text-decoration: none;
            color: #ddd;
            display: flex;
            align-items: center;
            transition: background-color 0.3s;
        }

        .menu-items a:hover {
            background-color: #495057;
            color: white;
        }

        .menu-items a i {
            margin-right: 15px;
            font-size: 1.2rem;
        }

        .menu-items .active {
            background-color: #495057; /* Active color */
            color: white;
        }

        .content {
            margin-left: 250px;
            padding: 20px;
            background-color: #f4f5f7;
            flex: 1;
            overflow-y: auto;
            height: calc(100vh - 70px);
            margin-top: 70px;
        }

        /* Header */
        .header {
            margin-left: 250px;
            height: 70px;
            background-color: #212529;
            color: white;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 40px;
            position: fixed;
            top: 0;
            width: calc(100% - 250px);
            z-index: 1000;
        }

        .header-title {
            font-size: 1.6rem;
            margin-left: -98px;
            font-weight: bold;
        }

        .header .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            overflow: hidden;
            cursor: pointer;
        }

        .header .user-avatar img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .dropdown-menu {
            position: absolute;
            top: 60px;
            right: 20px;
            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            display: none;
            z-index: 1000;
            width: 150px;
        }

        .dropdown-menu a {
            display: block;
            padding: 10px;
            text-decoration: none;
            color: #333;
            font-size: 14px;
        }

        .dropdown-menu a:hover {
            background-color: #f4f4f4;
        }
    </style>
</head>
<body>
    <!-- Sidebar -->
    <div class="sidebar">
        <div class="logo">
            <img src="{% static BRAND_LOGO %}" alt="Logo">
        </div>
        <div class="menu-items">
            {% for link in SIDEBAR_LINKS %}
                <a href="{{ link.url }}" class="{% if request.path == link.url %}active{% endif %}">
                    <i class="bi {{ link.icon }}"></i> {{ link.label }}
                </a>
            {% endfor %}
        </div>
    </div>

    <!-- Header -->
    <div class="header">
        <div class="header-title">{{ PROJECT_NAME }}</div>
        <div class="header-right">
            <div class="user-avatar" id="user-avatar">
                <img src="https://i.ibb.co/9mHps1F6/profile.png" alt="User Avatar">
            </div>
            <div class="dropdown-menu" id="dropdown-menu">
                <a href="{% url 'logout' %}">Logout</a>
            </div>
        </div>
    </div>

    <!-- Content -->
    <div class="content">
        {% block content %}
        <!-- Dynamic page content goes here -->
        {% endblock %}
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const avatar = document.getElementById('user-avatar');
            const dropdownMenu = document.getElementById('dropdown-menu');

            avatar.addEventListener('click', function () {
                const isVisible = dropdownMenu.style.display === 'block';
                dropdownMenu.style.display = isVisible ? 'none' : 'block';
            });

            document.addEventListener('click', function (event) {
                if (!avatar.contains(event.target) && !dropdownMenu.contains(event.target)) {
                    dropdownMenu.style.display = 'none';
                }
            });
        });
    </script>
</body>
</html>
