<?php

declare(strict_types=1);

namespace App\Http\Livewire\Components\Notifications;

use Illuminate\Support\Collection;
use Livewire\Component;

/**
 * Class Simple
 */
abstract class Simple extends Component
{
    protected Collection $userNotifications;

    /**
     * @var string[]
     */
    protected $listeners = [
        'userNotificationsReadChanged' => 'reloadState',
    ];

    public function mount($userNotifications = null): void
    {
        if (is_null($userNotifications)) {
            $userNotifications = collect();
        }

        $this->userNotifications = $userNotifications;
    }

    public function reloadState(): void
    {
        $this->userNotifications = auth()->user()->unreadNotifications;
    }
}
