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

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{% block title %}MASAR CARGO{% endblock %}</title>
  {% if project_description %}
  <meta name="description" content="{{ project_description }}">
  {% endif %}
  
  <!-- Bootstrap 5 CSS -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
  {% if CURRENT_LANG == 'ar' %}
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.rtl.min.css">
  {% endif %}
  
  <!-- Font Awesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
  
  <link rel="stylesheet" href="{% static 'css/custom.css' %}?v={{ deployment_timestamp }}">
  {% block head %}{% endblock %}
  <style>
    body { font-family: 'Outfit', sans-serif; background-color: #f8f9fa; }
    {% if CURRENT_LANG == 'ar' %}
    body { font-family: 'Cairo', sans-serif; }
    {% endif %}
    .navbar { background-color: #0A1D37; }
    .navbar-brand, .nav-link { color: #fff !important; }
    .btn-primary { background-color: #2196F3; border-color: #2196F3; }
    footer { background-color: #0A1D37; color: #fff; padding: 3rem 0; }
  </style>
</head>

<body>
  <nav class="navbar navbar-expand-lg sticky-top">
    <div class="container">
      <a class="navbar-brand" href="/">
        <i class="fa-solid fa-truck-fast me-2 text-info"></i> MASAR CARGO
      </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 ms-auto align-items-center">
          {% if user.is_authenticated %}
            <li class="nav-item">
              <a class="nav-link" href="{% url 'dashboard' %}">{% trans "Dashboard" %}</a>
            </li>
            {% if user.profile.role == 'TRUCK_OWNER' %}
            <li class="nav-item">
              <a class="nav-link" href="{% url 'marketplace' %}">{% trans "Marketplace" %}</a>
            </li>
            {% endif %}
          {% endif %}
          
          <li class="nav-item dropdown ms-lg-3">
            <a class="nav-link dropdown-toggle" href="#" id="langDropdown" role="button" data-bs-toggle="dropdown">
              <i class="fa-solid fa-globe me-1"></i> {{ CURRENT_LANG|upper }}
            </a>
            <ul class="dropdown-menu">
              <li>
                <form action="{% url 'set_language' %}" method="post">
                  {% csrf_token %}
                  <input name="next" type="hidden" value="{{ request.get_full_path }}">
                  <input name="language" type="hidden" value="en">
                  <button type="submit" class="dropdown-item">English</button>
                </form>
              </li>
              <li>
                <form action="{% url 'set_language' %}" method="post">
                  {% csrf_token %}
                  <input name="next" type="hidden" value="{{ request.get_full_path }}">
                  <input name="language" type="hidden" value="ar">
                  <button type="submit" class="dropdown-item">العربية</button>
                </form>
              </li>
            </ul>
          </li>

          {% if user.is_authenticated %}
          <li class="nav-item dropdown ms-lg-3">
            <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown">
              <i class="fa-solid fa-user-circle me-1"></i> {{ user.username }}
            </a>
            <ul class="dropdown-menu">
              <li>
                <form action="{% url 'logout' %}" method="post">
                  {% csrf_token %}
                  <button type="submit" class="dropdown-item">{% trans "Logout" %}</button>
                </form>
              </li>
            </ul>
          </li>
          {% else %}
          <li class="nav-item ms-lg-3">
            <a class="nav-link" href="{% url 'login' %}">{% trans "Login" %}</a>
          </li>
          <li class="nav-item">
            <a class="btn btn-primary" href="{% url 'register' %}">{% trans "Get Started" %}</a>
          </li>
          {% endif %}
        </ul>
      </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>
    <div class="container">
      <div class="row">
        <div class="col-md-4 mb-4">
          <h4 class="fw-bold">MASAR CARGO</h4>
          <p class="text-white-50">{% trans "Empowering logistics with smart technology. Locally and abroad." %}</p>
        </div>
        <div class="col-md-4 mb-4">
          <h5 class="fw-bold">{% trans "Quick Links" %}</h5>
          <ul class="list-unstyled">
            <li><a href="#" class="text-white-50 text-decoration-none">{% trans "Privacy Policy" %}</a></li>
            <li><a href="#" class="text-white-50 text-decoration-none">{% trans "Terms of Service" %}</a></li>
            <li><a href="#" class="text-white-50 text-decoration-none">{% trans "Contact Us" %}</a></li>
          </ul>
        </div>
        <div class="col-md-4 mb-4">
          <h5 class="fw-bold">{% trans "Contact" %}</h5>
          <p class="text-white-50">
            <i class="fa-brands fa-whatsapp me-2"></i> +123 456 7890<br>
            <i class="fa-solid fa-envelope me-2"></i> info@masarcargo.com
          </p>
        </div>
      </div>
      <hr class="bg-white-50">
      <p class="text-center text-white-50 mb-0">&copy; 2026 MASAR CARGO. All rights reserved.</p>
    </div>
  </footer>
<div class="container text-center text-muted small py-2">Debug: Lang={{ CURRENT_LANG }}, Cookie={{ request.COOKIES.django_language }}</div>

  <!-- Bootstrap 5 JS Bundle -->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>

</html>
