{% load i18n static %}
{% get_current_language as LANGUAGE_CODE %}
<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE }}" dir="{% if LANGUAGE_CODE == 'ar' %}rtl{% else %}ltr{% endif %}">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}{% if LANGUAGE_CODE == 'ar' %}منصة التعليم الإلكتروني{% else %}EduPlatform{% endif %}{% endblock %}</title>
    
    <!-- Bootstrap 5 CDN -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap{% if LANGUAGE_CODE == 'ar' %}.rtl{% endif %}.min.css" rel="stylesheet">
    
    <!-- FontAwesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
    
    <!-- Google Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&family=Noto+Kufi+Arabic:wght@400;700&display=swap" rel="stylesheet">
    
    <!-- Custom CSS -->
    <style>
        :root {
            --primary-color: #2D31FA;
            --secondary-color: #FF6B6B;
            --accent-color: #4ECDC4;
            --bg-light: #F8F9FA;
            --glass-bg: rgba(255, 255, 255, 0.8);
            --glass-border: rgba(255, 255, 255, 0.2);
        }

        body {
            font-family: 'Noto Kufi Arabic', 'Outfit', sans-serif;
            background-color: var(--bg-light);
            color: #333;
            overflow-x: hidden;
        }

        .navbar {
            background: var(--glass-bg);
            backdrop-filter: blur(10px);
            border-bottom: 1px solid var(--glass-border);
            padding: 1rem 0;
        }

        .navbar-brand {
            font-weight: 700;
            font-size: 1.5rem;
            color: var(--primary-color) !important;
        }

        .btn-primary {
            background-color: var(--primary-color);
            border: none;
            padding: 0.6rem 1.5rem;
            border-radius: 12px;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(45, 49, 250, 0.3);
            background-color: #1b1edb;
        }

        .glass-card {
            background: var(--glass-bg);
            backdrop-filter: blur(10px);
            border: 1px solid var(--glass-border);
            border-radius: 20px;
            padding: 2rem;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.05);
            transition: transform 0.3s ease;
        }

        .glass-card:hover {
            transform: translateY(-10px);
        }

        .hero-section {
            padding: 8rem 0 5rem;
            background: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%);
            position: relative;
        }

        .hero-section::before {
            content: '';
            position: absolute;
            top: 0;
            right: 0; /* RTL adjusted */
            width: 300px;
            height: 300px;
            background: radial-gradient(circle, rgba(45, 49, 250, 0.1) 0%, transparent 70%);
            z-index: 0;
        }
        
        html[dir="ltr"] .hero-section::before {
            right: auto;
            left: 0;
        }

        .footer {
            padding: 3rem 0;
            background: #fff;
            border-top: 1px solid #eee;
        }

        /* RTL Specific tweaks */
        [dir="rtl"] .ms-auto {
            margin-right: auto !important;
            margin-left: 0 !important;
        }
        
        [dir="rtl"] .me-auto {
            margin-left: auto !important;
            margin-right: 0 !important;
        }
    </style>
    {% block extra_css %}{% endblock %}
</head>

<body>
    <nav class="navbar navbar-expand-lg fixed-top">
        <div class="container">
            <a class="navbar-brand" href="{% url 'index' %}">EduPlatform</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="#">{% if LANGUAGE_CODE == 'ar' %}الدورات{% else %}Courses{% endif %}</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">{% if LANGUAGE_CODE == 'ar' %}المعلمون{% else %}Teachers{% endif %}</a>
                    </li>
                    {% if user.is_staff %}
                    <li class="nav-item">
                        <a class="nav-link" href="/admin/">{% if LANGUAGE_CODE == 'ar' %}المسؤول{% else %}Admin{% endif %}</a>
                    </li>
                    {% endif %}
                </ul>
                <div class="d-flex align-items-center">
                    <!-- Language Switcher -->
                    <div class="dropdown mx-3">
                        <button class="btn btn-link nav-link p-0 text-dark d-flex align-items-center gap-2 dropdown-toggle text-decoration-none" type="button" id="languageDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="fas fa-globe fa-lg text-primary"></i>
                            <span class="small fw-bold">{{ LANGUAGE_CODE|upper }}</span>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-end shadow-sm border-0" aria-labelledby="languageDropdown" style="border-radius: 12px;">
                            {% get_available_languages as LANGUAGES %}
                            {% get_language_info_list for LANGUAGES as languages %}
                            {% for language in languages %}
                                <li>
                                    <form action="{% url 'set_language' %}" method="post" class="d-block">
                                        {% csrf_token %}
                                        <input name="next" type="hidden" value="{{ request.get_full_path }}">
                                        <input name="language" type="hidden" value="{{ language.code }}">
                                        <button type="submit" class="dropdown-item py-2 d-flex justify-content-between align-items-center {% if language.code == LANGUAGE_CODE %}bg-light text-primary fw-bold{% endif %}">
                                            <span>{{ language.name_local }}</span>
                                            {% if language.code == LANGUAGE_CODE %}
                                                <i class="fas fa-check small"></i>
                                            {% endif %}
                                        </button>
                                    </form>
                                </li>
                            {% endfor %}
                        </ul>
                    </div>

                    {% if user.is_authenticated %}
                    <div class="dropdown ms-2">
                        <button class="btn btn-link text-decoration-none dropdown-toggle text-dark d-flex align-items-center" type="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                            <span class="fw-semibold">{{ user.username }}</span>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-end shadow-sm border-0" aria-labelledby="userDropdown" style="border-radius: 12px;">
                            <li><a class="dropdown-item py-2" href="{% url 'profile' %}">{% if LANGUAGE_CODE == 'ar' %}الملف الشخصي{% else %}Profile{% endif %}</a></li>
                            {% if user.is_staff %}
                            <li><a class="dropdown-item py-2" href="/admin/">{% if LANGUAGE_CODE == 'ar' %}لوحة تحكم المسؤول{% else %}Dashboard{% endif %}</a></li>
                            {% endif %}
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item py-2 text-danger" href="{% url 'logout' %}">{% if LANGUAGE_CODE == 'ar' %}تسجيل الخروج{% else %}Logout{% endif %}</a></li>
                        </ul>
                    </div>
                    {% else %}
                    <a href="{% url 'register_student' %}" class="btn btn-outline-primary me-2">{% if LANGUAGE_CODE == 'ar' %}تسجيل{% else %}Register{% endif %}</a>
                    <a href="{% url 'login' %}" class="btn btn-primary">{% if LANGUAGE_CODE == 'ar' %}دخول{% else %}Login{% endif %}</a>
                    {% endif %}
                </div>
            </div>
        </div>
    </nav>

    {% block content %}{% endblock %}

    <footer class="footer mt-5">
        <div class="container text-center">
            <p>&copy; 2026 EduPlatform. {% if LANGUAGE_CODE == 'ar' %}جميع الحقوق محفوظة.{% else %}All rights reserved.{% endif %}</p>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
    {% block extra_js %}{% endblock %}
</body>

</html>