{% load i18n static %}
<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE }}">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}{% trans "Jimma Market - Your Local Online Marketplace" %}{% endblock %}</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <!-- Custom CSS -->
    <link rel="stylesheet" href="{% static 'css/custom.css' %}?v={{ deployment_timestamp }}">
    <style>
        body {
            font-family: 'Inter', sans-serif;
            background-color: #f8f9fa;
        }
        .navbar-brand {
            font-weight: 700;
            color: #0d6efd;
        }
        .btn-primary {
            background-color: #0d6efd;
            border-color: #0d6efd;
            padding: 0.5rem 1.5rem;
            border-radius: 8px;
        }
        .card {
            border-radius: 12px;
            overflow: hidden;
            transition: transform 0.2s;
        }
        .card:hover {
            transform: translateY(-5px);
        }
        .footer {
            background-color: #f8f9fa;
            padding: 4rem 0 2rem;
            margin-top: 5rem;
            border-top: 1px solid #dee2e6;
        }
        .lang-switcher .dropdown-toggle::after {
            display: none;
        }
    </style>
    {% block extra_css %}{% endblock %}
</head>
<body>
    <!-- Top Bar (Optional, for Language Switcher) -->
    <div class="bg-light py-1 border-bottom">
        <div class="container d-flex justify-content-end">
            <div class="dropdown lang-switcher">
                <button class="btn btn-sm btn-link text-dark dropdown-toggle text-decoration-none py-0" type="button" data-bs-toggle="dropdown">
                    <i class="bi bi-translate me-1"></i>
                    {% get_current_language as CURRENT_LANG %}
                    {% for code, name in LANGUAGES %}
                        {% if code == CURRENT_LANG %}{{ name }}{% endif %}
                    {% endfor %}
                </button>
                <ul class="dropdown-menu dropdown-menu-end shadow-sm border-0">
                    {% for code, name in LANGUAGES %}
                        <li>
                            <form action="{% url 'set_language' %}" method="post">
                                {% csrf_token %}
                                <input name="next" type="hidden" value="{{ request.get_full_path|slice:'3:' }}">
                                <input name="language" type="hidden" value="{{ code }}">
                                <button type="submit" class="dropdown-item {% if code == CURRENT_LANG %}active{% endif %}">
                                    {{ name }}
                                </button>
                            </form>
                        </li>
                    {% endfor %}
                </ul>
            </div>
        </div>
    </div>

    <!-- Navigation -->
    <nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top shadow-sm">
        <div class="container">
            <a class="navbar-brand d-flex align-items-center" href="{% url 'home' %}">
                <i class="bi bi-shop-window me-2 text-primary"></i>
                Jimma Market
            </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="{% url 'product_list' %}">{% trans "Shop" %}</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'about_us' %}">{% trans "About" %}</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'article_list' %}">{% trans "Blog" %}</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'contact_us' %}">{% trans "Contact" %}</a>
                    </li>
                </ul>
                <div class="d-flex align-items-center">
                    <a href="{% url 'track_order' %}" class="btn btn-outline-primary me-2 d-none d-md-inline-block rounded-pill">
                        <i class="bi bi-truck me-1"></i> {% trans "Track Order" %}
                    </a>
                    <a href="{% url 'cart_detail' %}" class="btn btn-link text-dark position-relative me-3">
                        <i class="bi bi-cart3 fs-5"></i>
                        <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger" id="cart-count">
                            {{ request.session.cart|length|default:0 }}
                        </span>
                    </a>
                    {% if user.is_authenticated %}
                        <div class="dropdown">
                            <button class="btn btn-link text-dark dropdown-toggle text-decoration-none" type="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                                <i class="bi bi-person-circle fs-5 me-1"></i>
                                {{ user.username }}
                            </button>
                            <ul class="dropdown-menu dropdown-menu-end shadow border-0" aria-labelledby="userDropdown">
                                {% if user.vendor %}
                                    <li><a class="dropdown-item" href="{% url 'vendor_dashboard' %}"><i class="bi bi-speedometer2 me-2"></i>{% trans "Dashboard" %}</a></li>
                                {% else %}
                                    <li><a class="dropdown-item" href="{% url 'vendor_register' %}"><i class="bi bi-shop me-2"></i>{% trans "Become a Seller" %}</a></li>
                                {% endif %}
                                <li><hr class="dropdown-divider"></li>
                                <li>
                                    <form action="{% url 'logout' %}" method="post" class="d-inline">
                                        {% csrf_token %}
                                        <button type="submit" class="dropdown-item text-danger"><i class="bi bi-box-arrow-right me-2"></i>{% trans "Logout" %}</button>
                                    </form>
                                </li>
                            </ul>
                        </div>
                    {% else %}
                        <a href="{% url 'login' %}" class="btn btn-outline-primary me-2 rounded-pill px-4">{% trans "Login" %}</a>
                        <a href="{% url 'signup' %}" class="btn btn-primary rounded-pill px-4">{% trans "Sign Up" %}</a>
                    {% endif %}
                </div>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <main>
        {% if messages %}
            <div class="container mt-3">
                {% for message in messages %}
                    <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                        {{ message }}
                        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                    </div>
                {% endfor %}
            </div>
        {% endif %}

        {% block content %}{% endblock %}
    </main>

    <!-- Footer -->
    <footer class="footer">
        <div class="container">
            <div class="row g-4">
                <div class="col-lg-4">
                    <h5 class="fw-bold mb-4">Jimma Market</h5>
                    <p class="text-muted mb-4">{% trans "The most trusted online marketplace in Jimma, connecting local vendors with customers across the city. Experience quality and convenience at your doorstep." %}</p>
                    <div class="social-links">
                        <a href="https://t.me/Bilnett" target="_blank" class="text-dark me-3 fs-5" title="Telegram"><i class="bi bi-telegram"></i></a>
                        <a href="https://github.com/Osman-1234" target="_blank" class="text-dark me-3 fs-5" title="GitHub"><i class="bi bi-github"></i></a>
                        <a href="#" class="text-dark me-3 fs-5"><i class="bi bi-facebook"></i></a>
                        <a href="#" class="text-dark me-3 fs-5"><i class="bi bi-instagram"></i></a>
                    </div>
                </div>
                <div class="col-6 col-lg-2">
                    <h6 class="fw-bold mb-4">{% trans "Quick Links" %}</h6>
                    <ul class="list-unstyled">
                        <li class="mb-2"><a href="{% url 'product_list' %}" class="text-muted text-decoration-none">{% trans "Shop Products" %}</a></li>
                        <li class="mb-2"><a href="{% url 'article_list' %}" class="text-muted text-decoration-none">{% trans "Market News" %}</a></li>
                        <li class="mb-2"><a href="{% url 'how_it_works' %}" class="text-muted text-decoration-none">{% trans "How it Works" %}</a></li>
                        <li class="mb-2"><a href="{% url 'track_order' %}" class="text-muted text-decoration-none">{% trans "Track Order" %}</a></li>
                    </ul>
                </div>
                <div class="col-6 col-lg-2">
                    <h6 class="fw-bold mb-4">{% trans "Support" %}</h6>
                    <ul class="list-unstyled">
                        <li class="mb-2"><a href="{% url 'about_us' %}" class="text-muted text-decoration-none">{% trans "About Us" %}</a></li>
                        <li class="mb-2"><a href="{% url 'contact_us' %}" class="text-muted text-decoration-none">{% trans "Contact Support" %}</a></li>
                        <li class="mb-2"><a href="{% url 'delivery_info' %}" class="text-muted text-decoration-none">{% trans "Delivery Info" %}</a></li>
                        <li class="mb-2"><a href="{% url 'project_log' %}" class="text-muted text-decoration-none">{% trans "Project Log" %}</a></li>
                    </ul>
                </div>
                <div class="col-lg-4">
                    <h6 class="fw-bold mb-4">{% trans "Company Contact" %}</h6>
                    <p class="text-muted small mb-3">{% trans "For business inquiries, partnerships, or technical support, please reach out directly." %}</p>
                    <ul class="list-unstyled text-muted small">
                        <li class="mb-1"><i class="bi bi-person-fill me-2"></i> Bilal</li>
                        <li class="mb-1"><i class="bi bi-envelope-fill me-2"></i> bilalmaa614@gmail.com</li>
                        <li class="mb-1"><i class="bi bi-telephone-fill me-2"></i> +251 980 375 465</li>
                        <li class="mb-1"><i class="bi bi-telegram me-2"></i> <a href="https://t.me/Bilnett" target="_blank" class="text-muted text-decoration-none">@Bilnett</a></li>
                        <li class="mb-1"><i class="bi bi-github me-2"></i> <a href="https://github.com/Osman-1234" target="_blank" class="text-muted text-decoration-none">Osman-1234</a></li>
                    </ul>
                </div>
            </div>
            <hr class="my-4">
            <div class="row align-items-center">
                <div class="col-md-6 text-center text-md-start">
                    <p class="text-muted mb-0 small">&copy; 2026 Jimma Market. {% trans "All rights reserved." %}</p>
                </div>
                <div class="col-md-6 text-center text-md-end">
                    <p class="text-muted mb-0 small">{% trans "Built by" %} <a href="https://github.com/Osman-1234" target="_blank" class="text-primary text-decoration-none fw-bold">Bilal</a> | <a href="{% url 'project_log' %}" class="text-muted text-decoration-none">v1.1.0</a></p>
                </div>
            </div>
        </div>
    </footer>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    {% block extra_js %}{% endblock %}
</body>
</html>