<?php

declare(strict_types=1);

namespace App\Http\Livewire\Components\Notifications;

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

/**
 * Class Simple
 *
 * @package App\Http\Livewire\Components\Notifications
 */
abstract class Simple extends Component
{
    /**
     * @var \Illuminate\Support\Collection
     */
    protected Collection $userNotifications;

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

    /**
     * @param $userNotifications
     * @return void
     */
    public function mount($userNotifications = null): void
    {
        if (is_null($userNotifications)) {
            $userNotifications = collect();
        }

        $this->userNotifications = $userNotifications;
    }

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