<div class="drawer-side z-40">
  <label for="sidebar-toggle" class="drawer-overlay"></label>

  <aside class="w-64 min-h-screen bg-base-100 shadow-xl flex flex-col">

    <!-- Logo / Business name -->
    <div class="p-4 border-b border-base-200">
      {% if business.logo %}
        <img src="{{ business.logo.url }}" alt="logo" class="h-10 mb-1"/>
      {% endif %}
      <div class="font-bold text-lg">{{ business.name|default:"BizTrack" }}</div>
      <div class="text-xs text-base-content/50">{{ request.user.username }} · {{ request.user.get_role_display }}</div>
    </div>

    <!-- Navigation -->
<ul class="menu menu-md flex-1 p-3 gap-1">

  <li>
    <a href="{% url 'finance:dashboard' %}"
       class="{% if request.resolver_match.app_name == 'finance' and 'dashboard' in request.resolver_match.url_name %}active{% endif %}">
      📊 Dashboard
    </a>
  </li>

  {% if request.user.can_access_sales %}
  <li class="menu-title">Sales</li>
  <li>
    <a href="{% url 'sales:sale_list' %}"
       class="{% if request.resolver_match.app_name == 'sales' and request.resolver_match.url_name == 'sale_list' %}active{% endif %}">
      🧾 Sales
    </a>
  </li>
  <li>
    <a href="{% url 'sales:invoice_list' %}"
       class="{% if request.resolver_match.app_name == 'sales' and 'invoice' in request.resolver_match.url_name %}active{% endif %}">
      📄 Invoices
    </a>
  </li>
  <li>
    <a href="{% url 'sales:customer_list' %}"
       class="{% if 'customer' in request.resolver_match.url_name %}active{% endif %}">
      👥 Customers
    </a>
  </li>
  <li>
    <a href="{% url 'sales:sales_return_list' %}"
       class="{% if 'sales_return' in request.resolver_match.url_name %}active{% endif %}">
      ↩️ Sales Returns
    </a>
  </li>
  {% if request.user.can_create_sales %}
  <li>
    <a href="{% url 'sales:sale_create' %}"
       class="{% if request.resolver_match.url_name == 'sale_create' %}active{% endif %}">
      ➕ New Sale
    </a>
  </li>
  {% endif %}
  {% endif %}

  {% if request.user.can_access_inventory %}
  <li class="menu-title">Inventory</li>
    <li>
  <a href="{% url 'inventory:category_list' %}"
     class="{% if request.resolver_match.url_name == 'category_list' %}active{% endif %}">
    🗂 Categories
  </a>
</li>
  <li>
    <a href="{% url 'inventory:product_list' %}"
       class="{% if request.resolver_match.app_name == 'inventory' %}active{% endif %}">
      📦 Products
    </a>
  </li>
  <li>
  <a href="{% url 'inventory:supplier_list' %}"
     class="{% if request.resolver_match.url_name == 'supplier_list' %}active{% endif %}">
    🏭 Suppliers
  </a>
</li>
<li>
  <a href="{% url 'inventory:po_list' %}"
     class="{% if 'po' in request.resolver_match.url_name %}active{% endif %}">
    📋 Purchase Orders
  </a>
</li>
<li>
  <a href="{% url 'inventory:purchase_return_list' %}"
     class="{% if 'purchase_return' in request.resolver_match.url_name %}active{% endif %}">
    ↩️ Purchase Returns
  </a>
</li>
<li>
  <a href="{% url 'inventory:branch_list' %}"
     class="{% if 'branch' in request.resolver_match.url_name %}active{% endif %}">
    🏢 Branches
  </a>
</li>
<li>
  <a href="{% url 'inventory:location_list' %}"
     class="{% if 'location' in request.resolver_match.url_name %}active{% endif %}">
    🏬 Locations
  </a>
</li>
<li>
  <a href="{% url 'inventory:transfer_list' %}"
     class="{% if 'transfer' in request.resolver_match.url_name %}active{% endif %}">
    🔄 Transfers
  </a>
</li>
<li>
  <a href="{% url 'inventory:adjustment_request_list' %}"
     class="{% if 'adjustment_request' in request.resolver_match.url_name %}active{% endif %}">
    🛠 Adjustments
  </a>
</li>
  {% endif %}

  {% if request.user.can_view_inventory_reports %}
  <li class="menu-title">Reports</li>
  <li>
    <a href="{% url 'inventory:low_stock_report' %}"
       class="{% if request.resolver_match.url_name == 'low_stock_report' %}active{% endif %}">
      ⚠️ Low Stock
    </a>
  </li>
  <li>
    <a href="{% url 'inventory:expired_stock_report' %}"
       class="{% if request.resolver_match.url_name == 'expired_stock_report' %}active{% endif %}">
      ⏰ Expired Stock
    </a>
  </li>
  <li>
    <a href="{% url 'inventory:stock_movement_report' %}"
       class="{% if request.resolver_match.url_name == 'stock_movement_report' %}active{% endif %}">
      🧾 Movement History
    </a>
  </li>
  {% endif %}

  {% if request.user.can_access_assets %}
  <li class="menu-title">Assets</li>
  <li>
    <a href="{% url 'inventory:asset_list' %}"
       class="{% if 'asset' in request.resolver_match.url_name %}active{% endif %}">
      🖥 Asset Register
    </a>
  </li>
  {% endif %}

  {% if request.user.can_access_finance %}
  <li class="menu-title">Finance</li>
  <li>
  <a href="{% url 'finance:category_list' %}"
     class="{% if request.resolver_match.url_name == 'category_list' %}active{% endif %}">
    🗂 Expense Categories
  </a>
</li>
  <li>
    <a href="{% url 'finance:expense_list' %}"
       class="{% if request.resolver_match.url_name == 'expense_list' %}active{% endif %}">
      💸 Expenses
    </a>
  </li>
  <li>
    <a href="{% url 'finance:income_list' %}"
       class="{% if request.resolver_match.url_name == 'income_list' %}active{% endif %}">
      💰 Other Income
    </a>
  </li>
  <li>
    <a href="{% url 'finance:account_list' %}"
       class="{% if request.resolver_match.url_name == 'account_list' %}active{% endif %}">
      🏦 Accounts
    </a>
  </li>
  <li>
    <a href="{% url 'finance:profit_loss' %}"
       class="{% if request.resolver_match.url_name == 'profit_loss' %}active{% endif %}">
      📈 Profit Report
    </a>
  </li>
  {% endif %}

  {% if request.user.can_manage_users %}
  <li class="menu-title">Administration</li>
  <li>
    <a href="{% url 'accounts:user_list' %}"
       class="{% if request.resolver_match.app_name == 'accounts' and request.resolver_match.url_name == 'user_list' %}active{% endif %}">
      👥 Users
    </a>
  </li>
  <li>
    <a href="{% url 'accounts:employee_list' %}"
       class="{% if request.resolver_match.app_name == 'accounts' and request.resolver_match.url_name == 'employee_list' %}active{% endif %}">
      🪪 Employees
    </a>
  </li>
  <li>
    <a href="{% url 'accounts:role_list' %}"
       class="{% if request.resolver_match.app_name == 'accounts' and request.resolver_match.url_name == 'role_list' %}active{% endif %}">
      🧩 Roles
    </a>
  </li>
  <li>
    <a href="{% url 'accounts:group_list' %}"
       class="{% if request.resolver_match.app_name == 'accounts' and request.resolver_match.url_name == 'group_list' %}active{% endif %}">
      🔐 Groups
    </a>
  </li>
  {% endif %}

  {% if request.user.is_owner %}
  <li class="menu-title">Owner</li>
  <li>
    <a href="{% url 'finance:draw_list' %}"
       class="{% if request.resolver_match.url_name == 'draw_list' %}active{% endif %}">
      💼 Owner Draws
    </a>
  </li>
  <li>
    <a href="{% url 'business:profile' %}"
       class="{% if request.resolver_match.url_name == 'profile' and request.resolver_match.app_name == 'business' %}active{% endif %}">
      ⚙️ Business Settings
    </a>
  </li>
  {% endif %}

  {% if request.user.can_view_audit_logs %}
  <li class="menu-title">Compliance</li>
  <li>
    <a href="{% url 'core:audit_log_list' %}"
       class="{% if request.resolver_match.app_name == 'core' and request.resolver_match.url_name == 'audit_log_list' %}active{% endif %}">
      🕵️ Audit Logs
    </a>
  </li>
  {% endif %}

</ul>

    <!-- Logout -->
    <div class="p-3 border-t border-base-200">
        <a href="{% url 'accounts:profile' %}" class="btn btn-ghost btn-sm w-full justify-start mb-1">
        👤 My Profile
     </a>
      <a href="{% url 'accounts:logout' %}" class="btn btn-outline btn-error btn-sm w-full">
        Logout
      </a>
    </div>

  </aside>
</div>
