<?php

declare(strict_types=1);

namespace App\Http\View\Composers;

use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;

/**
 * Class UserNotificationComposer
 *
 * @package App\Http\View\Composers
 */
class UserNotificationComposer
{
    /**
     * @var \Illuminate\Database\Eloquent\Collection|null
     */
    protected ?Collection $notifications;

    /**
     * UserNotificationComposer constructor.
     */
    public function __construct()
    {
        $this->notifications = auth()->user()->unreadNotifications;
    }

    /**
     * @param \Illuminate\Contracts\View\View $view
     *
     * @return mixed
     */
    public function compose(View $view): View
    {
        return $view->withUserNotifications($this->notifications);
    }
}
