<?php

declare(strict_types=1);

namespace App\Listeners;

use App\Events\UserLoggedIn;

/**
 * Class UpozornitPouzivatelaNaNeprecitaneNotifikacie
 */
final class UpozornitPouzivatelaNaNeprecitaneNotifikacie
{
    public function handle(UserLoggedIn $event): void
    {
        /** @var \Illuminate\Database\Eloquent\Collection $notifications */
        $notifications = $event->pouzivatel->unreadNotifications;

        if ($notifications->isEmpty()) {
            return;
        }

        flash()->info(
            sprintf(
                'Máte neprečítané notifikácie. <a class="btn btn-info" href="%s">Zobraziť</a>',
                route('portal.pouzivatel.notifikacie.index'),
            ),
        )->overlay('', 'Upozornenie');
    }
}
