@php
  /** @var \App\Models\GeneralSetting $settings */
  $gs    = $settings ?? new \App\Models\GeneralSetting();
  $g1    = $gs->icon_color  ?? '#0B5D1E';
  $g2    = $gs->hover_color ?? '#0F7A2E';
  $hover = $gs->hover_color ?? '#0F7A2E';

  // Active helper
  if (!function_exists('navActive')) {
      function navActive($patterns){
          foreach ((array)$patterns as $p) {
              if (request()->routeIs($p) || request()->is($p)) return true;
          }
          return false;
      }
  }

  // base classes
  $basePill = 'w-9 h-9 rounded-full flex items-center justify-center transition';
  $baseText = 'text-[11px] mt-0.5';

  $adminUser = auth('admin')->user();
  $isSuperAdmin = $adminUser?->isSuperAdmin() ?? true;
  $subAdminQuickLinks = [];

  if (!$isSuperAdmin && $adminUser) {
      $subAdminQuickLinks = array_slice(
          \App\Support\AdminProjectPermissionRegistry::sidebarItemsForProjects($adminUser->assignedProjectPermissions()),
          0,
          3
      );
  }
@endphp

<style>
  /* ===== Bottom nav underline/tap highlight fix (scoped) ===== */
  #adminBottomNav a,
  #adminBottomNav a:visited,
  #adminBottomNav a:hover,
  #adminBottomNav a:active {
    text-decoration: none !important;
    -webkit-tap-highlight-color: transparent;
    color: #fff; /* icons (currentColor) + text = white */
  }
  #adminBottomNav a:focus { outline: none; }
  #adminBottomNav a:focus-visible {
    outline: 2px solid rgba(255,255,255,.7);
    outline-offset: 3px;
    border-radius: 10px;
  }

  /* Better hit-area on mobile */
  #adminBottomNav .nav-item { min-width: 64px; }

  /* Active pill halo */
  #adminBottomNav .pill-active {
    box-shadow: 0 6px 18px rgba(0,0,0,.22), 0 0 0 2px rgba(255,255,255,.12) inset;
  }

  /* Safe-area padding for iOS */
  #adminBottomNav .safe {
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
</style>

@if(!$isSuperAdmin)
@php
  $isHome = navActive(['admin.dashboard', 'admin/dashboard']);
@endphp
<footer id="adminBottomNav"
        class="fixed bottom-0 left-0 w-full shadow-md z-50 select-none"
        style="background:linear-gradient(90deg, {{ $g1 }}, {{ $g2 }}); color:#fff;">
  <div class="safe flex justify-around items-center py-2 text-white">
    <a href="{{ route('admin.dashboard') }}"
       class="nav-item flex flex-col items-center cursor-pointer"
       aria-label="Dashboard">
      <span class="{{ $basePill }} {{ $isHome ? 'pill-active' : '' }}"
            style="background: {{ $isHome ? $hover : 'rgba(255,255,255,.20)' }};">
        <i class="fa-solid fa-gauge"></i>
      </span>
      <span class="{{ $baseText }}">Dashboard</span>
    </a>

    @foreach($subAdminQuickLinks as $item)
      @php
        $isActiveItem = request()->routeIs($item['route_name']) || request()->routeIs($item['route_name'] . '.*');
      @endphp
      <a href="{{ route($item['route_name']) }}"
         class="nav-item flex flex-col items-center cursor-pointer"
         aria-label="{{ $item['label'] }}">
        <span class="{{ $basePill }} {{ $isActiveItem ? 'pill-active' : '' }}"
              style="background: {{ $isActiveItem ? $hover : 'rgba(255,255,255,.20)' }};">
          <i class="{{ $item['icon'] }}"></i>
        </span>
        <span class="{{ $baseText }}">{{ \Illuminate\Support\Str::limit($item['label'], 8, '') }}</span>
      </a>
    @endforeach
  </div>
</footer>
@php return; @endphp
@endif

@php
  $isHome     = navActive(['admin.dashboard', 'admin/dashboard']);
  $isUsers    = navActive(['admin.users.*','admin/users*']);
  $isWithdraw = navActive(['admin.withdraw.*','admin/withdraw*']);
  $isPayment  = navActive(['admin.payments.*','admin/payments*']);
@endphp

<footer id="adminBottomNav"
        class="fixed bottom-0 left-0 w-full shadow-md z-50 select-none"
        style="background:linear-gradient(90deg, {{ $g1 }}, {{ $g2 }}); color:#fff;">
  <div class="safe flex justify-around items-center py-2 text-white">

    {{-- হোম --}}
    <a href="{{ route('admin.dashboard') }}"
       class="nav-item flex flex-col items-center cursor-pointer"
       aria-label="হোম">
      <span class="{{ $basePill }} {{ $isHome ? 'pill-active' : '' }}"
            style="background: {{ $isHome ? $hover : 'rgba(255,255,255,.20)' }};">
        <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20" aria-hidden="true">
          <path d="M10 2L2 8h2v8h5v-5h2v5h5V8h2L10 2z"/>
        </svg>
      </span>
      <span class="{{ $baseText }}">হোম</span>
    </a>

    {{-- ইউজার --}}
    <a href="/admin/users"
       class="nav-item flex flex-col items-center cursor-pointer"
       aria-label="ইউজার">
      <span class="{{ $basePill }} {{ $isUsers ? 'pill-active' : '' }}"
            style="background: {{ $isUsers ? $hover : 'rgba(255,255,255,.20)' }};">
        <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20" aria-hidden="true">
          <path d="M13 7a3 3 0 11-6 0 3 3 0 016 0zM5 14a4 4 0 018 0v1H5v-1z"/>
        </svg>
      </span>
      <span class="{{ $baseText }}">ইউজার</span>
    </a>

    {{-- উইথড্র --}}
    <a href="{{ route('admin.withdraw.pending') }}"
       class="nav-item flex flex-col items-center cursor-pointer"
       aria-label="উইথড্র">
      <span class="{{ $basePill }} {{ $isWithdraw ? 'pill-active' : '' }}"
            style="background: {{ $isWithdraw ? $hover : 'rgba(255,255,255,.20)' }};">
        <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
          <path d="M12 21c4.418 0 8-1.79 8-4V5c0-2.21-3.582-4-8-4S4 2.79 4 5v12c0 2.21 3.582 4 8 4zm0-2c-3.314 0-6-1.343-6-3s2.686-3 6-3 6 1.343 6 3-2.686 3-6 3z"/>
        </svg>
      </span>
      <span class="{{ $baseText }}">উইথড্র</span>
    </a>

    {{-- পেমেন্ট --}}
    <a href="{{ route('admin.payments.index') }}"
       class="nav-item flex flex-col items-center cursor-pointer"
       aria-label="পেমেন্ট">
      <span class="{{ $basePill }} {{ $isPayment ? 'pill-active' : '' }}"
            style="background: {{ $isPayment ? $hover : 'rgba(255,255,255,.20)' }};">
        <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
          <path d="M12 1C8.134 1 5 4.134 5 8s3.134 7 7 7 7-3.134 7-7-3.134-7-7-7zm0 12a5 5 0 110-10 5 5 0 010 10zm-1 2v2H7v2h5v2h2v-2h5v-2h-5v-2h-2z"/>
        </svg>
      </span>
      <span class="{{ $baseText }}">পেমেন্ট</span>
    </a>

  </div>
</footer>
