<?php
/**
 * GET /api/notifications/unread_count.php
 * Lightweight endpoint for the nav badge — avoids fetching the full list
 * just to show a number.
 */

require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../includes/response.php';
require_once __DIR__ . '/../includes/auth.php';

$userId = require_login();

$pdo = Database::connect();
$stmt = $pdo->prepare('SELECT COUNT(*) FROM notifications WHERE user_id = ? AND is_read = 0');
$stmt->execute([$userId]);

send_json(true, 'OK', ['unread_count' => (int) $stmt->fetchColumn()]);
