<?php

namespace App\View\Components;

use Illuminate\View\Component;
use Illuminate\View\View;
use Illuminate\Support\Facades\Auth;
use App\Models\Notification;

class AppLayout extends Component
{
    public $unreadNotifications;

    public function __construct()
    {
        $this->unreadNotifications = Auth::check() 
            ? Notification::where('user_id', Auth::id())->where('is_read', 0)->count()
            : 0;
    }

    public function render(): View
    {
        return view('layouts.app', [
            'unreadNotifications' => $this->unreadNotifications
        ]);
    }
}
