<?php

declare(strict_types=1);

namespace App\Listeners;

use App\Events\UserLoggedIn;

/**
 * Class UpozornitPouzivatelaNaNeprecitaneNotifikacie
 *
 * @package App\Listeners
 */
final class UpozornitPouzivatelaNaNeprecitaneNotifikacie
{
    /**
     * @param \App\Events\UserLoggedIn $event
     */
    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');
    }
}
