<?php

namespace App\View\Composers;

use App\Services\NotificationService;
use Illuminate\View\View;

class TopbarComposer
{
    public function __construct(
        private readonly NotificationService $notifications,
    ) {}

    public function compose(View $view): void
    {
        $user = auth()->user();
        $unreadCount = 0;

        if ($user !== null && $user->hasPermission('notifications.view')) {
            $unreadCount = $this->notifications->unreadCount($user->id);
        }

        $view->with('unreadNotificationCount', $unreadCount);
    }
}
