<?php

namespace App\Livewire\Merchant;

use Livewire\Component;

class NotificationsDropdown extends Component
{
    public function markAsRead(string $notificationId): void
    {
        $notification = auth()->user()->notifications()->find($notificationId);
        $notification?->markAsRead();
    }

    public function markAllAsRead(): void
    {
        auth()->user()->unreadNotifications->markAsRead();
    }

    public function getUnreadCountProperty(): int
    {
        return auth()->user()->unreadNotifications()->count();
    }

    public function getNotificationsProperty()
    {
        return auth()->user()->notifications()->latest()->limit(15)->get();
    }

    public function render()
    {
        return view('livewire.merchant.notifications-dropdown');
    }
}
