@php
  // Define core modules with their routes, icons, and display names
  $coreModules = [
    [
      'name' => 'AccountingCore',
      'label' => __('Accounting'),
      'route' => 'accountingcore.dashboard',
      'icon' => 'bx-calculator',
      'color' => 'primary',
    ],
    [
      'name' => 'CRMCore',
      'label' => __('CRM'),
      'route' => 'crmcore.dashboard',
      'icon' => 'bx-user-voice',
      'color' => 'info',
    ],
    [
      'name' => 'PMCore',
      'label' => __('Projects'),
      'route' => 'pmcore.dashboard.index',
      'icon' => 'bx-briefcase',
      'color' => 'success',
    ],
    [
      'name' => 'WMSInventoryCore',
      'label' => __('Inventory'),
      'route' => 'wmsinventorycore.dashboard.index',
      'icon' => 'bx-package',
      'color' => 'warning',
    ],
    [
      'name' => 'AICore',
      'label' => __('AI'),
      'route' => 'aicore.dashboard',
      'icon' => 'bx-bot',
      'color' => 'secondary',
    ],
    [
      'name' => null, // HR is part of the base system, not a module
      'label' => __('HR'),
      'route' => 'employees.index',
      'icon' => 'bx-group',
      'color' => 'danger',
    ],
  ];

  // Filter modules that exist and have valid routes
  $availableModules = collect($coreModules)->filter(function ($module) {
    // Check if route exists
    if (!\Illuminate\Support\Facades\Route::has($module['route'])) {
      return false;
    }
    // If module name is null, it's a base system feature (always available)
    if ($module['name'] === null) {
      return true;
    }
    // Otherwise check if module exists
    return moduleExists($module['name']);
  });
@endphp

@if($availableModules->isNotEmpty())
  <li class="nav-item dropdown dropdown-shortcuts">
    <a class="nav-link modern-icon-btn" href="javascript:void(0);"
       data-bs-toggle="dropdown"
       aria-expanded="false"
       data-bs-auto-close="outside">
      <i class="bx bx-grid-alt bx-md"></i>
    </a>
    <div class="dropdown-menu dropdown-menu-end modern-dropdown shortcuts-dropdown p-3" style="min-width: 320px;">
      <div class="dropdown-header d-flex justify-content-between align-items-center mb-3">
        <h6 class="mb-0 text-uppercase small text-muted">@lang('Quick Access')</h6>
        <a href="{{ url('/') }}" class="text-muted small">
          <i class="bx bx-home-alt me-1"></i>@lang('Dashboard')
        </a>
      </div>
      <div class="row g-2">
        @foreach($availableModules as $module)
          <div class="col-6">
            <a href="{{ route($module['route']) }}"
               class="d-flex flex-column align-items-center justify-content-center p-3 rounded-3 text-center shortcut-item">
              <div class="shortcut-icon bg-label-{{ $module['color'] }} mb-2">
                <i class="bx {{ $module['icon'] }}"></i>
              </div>
              <span class="fw-medium text-heading small">{{ $module['label'] }}</span>
            </a>
          </div>
        @endforeach
      </div>
    </div>
  </li>

  <style>
    .shortcuts-dropdown .shortcut-item {
      background: var(--bs-gray-100);
      transition: all 0.2s ease;
    }

    .shortcuts-dropdown .shortcut-item:hover {
      background: var(--bs-gray-200) !important;
      transform: translateY(-2px);
    }

    .shortcuts-dropdown .shortcut-icon {
      width: 42px;
      height: 42px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .shortcuts-dropdown .shortcut-icon i {
      font-size: 1.25rem;
    }

    [data-bs-theme="dark"] .shortcuts-dropdown .shortcut-item {
      background: var(--bs-gray-800) !important;
    }

    [data-bs-theme="dark"] .shortcuts-dropdown .shortcut-item:hover {
      background: var(--bs-gray-700) !important;
    }
  </style>
@endif
