{% 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 "Ethio-Marketplace" %}{% endblock %}</title>
  
  {% if project_description %}
  <meta name="description" content="{{ project_description }}">
  <meta property="og:description" content="{{ project_description }}">
  <meta property="twitter:description" content="{{ project_description }}">
  {% endif %}
  
  {% if project_image_url %}
  <meta property="og:image" content="{{ project_image_url }}">
  <meta property="twitter:image" content="{{ project_image_url }}">
  {% endif %}

  <!-- Bootstrap 5 CSS -->
  <link rel="stylesheet" href="{% static 'bootstrap/dist/css/bootstrap.min.css' %}">
  <!-- Bootstrap Icons -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
  <!-- Custom CSS -->
  <link rel="stylesheet" href="{% static 'css/custom.css' %}?v={{ deployment_timestamp }}">
  
  <style>
    :root {
      --primary-color: #0d6efd;
      --secondary-color: #6c757d;
    }
    body {
      font-family: 'Inter', system-ui, -apple-system, sans-serif;
      background-color: #f8f9fa;
      color: #333;
    }
    .navbar {
      box-shadow: 0 2px 10px rgba(0,0,0,.05);
    }
    .hero-section {
      padding: 5rem 0;
      background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    }
    .card {
      transition: transform 0.2s ease, box-shadow 0.2s ease;
    }
    .card:hover {
      transform: translateY(-5px);
      box-shadow: 0 10px 20px rgba(0,0,0,.08) !important;
    }
    .btn-primary {
      padding: 0.6rem 1.5rem;
      border-radius: 8px;
    }
  </style>
  {% block head %}{% endblock %}
</head>

<body>
  <nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top py-3">
    <div class="container">
      <a class="navbar-brand fw-bold text-primary fs-4" href="{% url 'index' %}">
        <i class="bi bi-shop me-2"></i>{% trans "Ethio-Market" %}
      </a>
      <button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
        <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 px-3" href="{% url 'index' %}">{% trans "Home" %}</a>
          </li>
          <li class="nav-item">
            <a class="nav-link px-3" href="{% url 'product_list' %}">{% trans "Products" %}</a>
          </li>
        </ul>
        
        <div class="d-flex align-items-center">
          <!-- Language Switcher -->
          <form action="{% url 'set_language' %}" method="post" class="me-3">
            {% csrf_token %}
            <input name="next" type="hidden" value="{{ request.get_full_path }}">
            <select name="language" onchange="this.form.submit()" class="form-select form-select-sm bg-light border-0">
              {% get_current_language as CURRENT_LANGUAGE %}
              {% get_available_languages as LANGUAGES %}
              {% get_language_info_list for LANGUAGES as languages %}
              {% for language in languages %}
                <option value="{{ language.code }}" {% if language.code == CURRENT_LANGUAGE %}selected{% endif %}>
                  {{ language.name_local }}
                </option>
              {% endfor %}
            </select>
          </form>

          <!-- Cart -->
          <a href="{% url 'cart_detail' %}" class="btn btn-link text-dark position-relative me-3">
            <i class="bi bi-cart3 fs-5"></i>
            {% if request.session.cart %}
              <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger" style="font-size: 0.6rem;">
                {{ request.session.cart|length }}
              </span>
            {% endif %}
          </a>

          {% if user.is_authenticated %}
            <div class="dropdown">
              <a class="btn btn-outline-primary btn-sm dropdown-toggle d-flex align-items-center" href="#" role="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                <i class="bi bi-person-circle me-1"></i> {{ user.username }}
              </a>
              <ul class="dropdown-menu dropdown-menu-end border-0 shadow-sm" aria-labelledby="userDropdown">
                {% if user.vendor %}
                  <li><a class="dropdown-item" href="{% url 'vendor_dashboard' %}"><i class="bi bi-speedometer2 me-2"></i>{% trans "Vendor Dashboard" %}</a></li>
                {% else %}
                  <li><a class="dropdown-item" href="{% url 'vendor_register' %}"><i class="bi bi-shop-window me-2"></i>{% trans "Become a Seller" %}</a></li>
                {% endif %}
                <li><a class="dropdown-item" href="{% url 'admin:index' %}"><i class="bi bi-gear me-2"></i>{% trans "Admin" %}</a></li>
                <li><hr class="dropdown-divider"></li>
                <li>
                  <form action="{% url 'admin: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 'admin:index' %}" class="btn btn-primary btn-sm">{% trans "Login" %}</a>
          {% endif %}
        </div>
      </div>
    </div>
  </nav>

  {% 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 %}

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

  <footer class="bg-white py-5 mt-5 border-top">
    <div class="container">
      <div class="row">
        <div class="col-md-6 text-center text-md-start mb-3 mb-md-0">
          <h5 class="fw-bold text-primary mb-3">{% trans "Ethio-Market" %}</h5>
          <p class="text-muted small">{% trans "Connecting Ethiopian local vendors with customers everywhere." %}</p>
        </div>
        <div class="col-md-6 text-center text-md-end">
          <p class="text-muted mb-0">&copy; 2026 {% trans "Ethio-Marketplace" %}. {% trans "All rights reserved." %}</p>
        </div>
      </div>
    </div>
  </footer>

  <!-- Bootstrap 5 Bundle with Popper -->
  <script src="{% static 'bootstrap/dist/js/bootstrap.bundle.min.js' %}"></script>
  {% block scripts %}{% endblock %}
</body>

</html>