@props([ 'variant' => 'light', ]) @php use App\Enums\ApplicationStatus; use App\Enums\UserRole; use App\Models\Application; use Illuminate\Support\Facades\Cache; $authUser = auth()->user(); @endphp @if ($authUser) @php $cacheKey = 'notif_bell:'.$authUser->id; $data = Cache::remember($cacheKey, now()->addSeconds(15), function () use ($authUser) { $base = Application::query()->where('is_submitted', true); $base = match ($authUser->role) { UserRole::Admin => $base, UserRole::Agent => $base->where('agent_id', $authUser->id), UserRole::Customer=> $base->where('user_id', $authUser->id), default => $base->whereRaw('1=0'), }; $base->where('status', ApplicationStatus::Pending->value) ->whereNotExists(function ($q) use ($authUser): void { $q->select(\Illuminate\Support\Facades\DB::raw(1)) ->from('notification_reads') ->whereColumn('notification_reads.application_id', 'applications.id') ->where('notification_reads.user_id', $authUser->id); }); $count = (clone $base)->count(); $items = (clone $base) ->latest('created_at') ->limit(5) ->get(['id', 'full_name', 'passport_number', 'created_at']); return ['count' => $count, 'items' => $items]; }); $count = (int) ($data['count'] ?? 0); $items = $data['items'] ?? collect(); $listRoute = match ($authUser->role) { UserRole::Admin => route('admin.applications.index'), UserRole::Agent => route('agent.applications.index'), UserRole::Customer => route('customer.applications.index'), default => '#', }; $isDark = $variant === 'dark'; $btnClasses = $isDark ? 'relative rounded-full p-2 text-cv-navy-light hover:bg-cv-cream' : 'relative rounded-full p-2 text-ui-nav hover:bg-slate-100'; $badgeClasses = $isDark ? 'absolute right-1 top-1 flex h-4 min-w-[16px] items-center justify-center rounded-full bg-cv-gold px-1 text-[10px] font-bold text-cv-navy-deep' : 'absolute -right-1 -top-1 inline-flex h-4 min-w-[16px] items-center justify-center rounded-full bg-ui-gold px-1 text-[9px] font-bold leading-none text-white'; @endphp
@endif