<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Session;

class NotificationController extends Controller
{
    /**
     * 检查是否有新的通知
     */
    public function checkNotifications(Request $request): JsonResponse
    {
        $notification = Session::get('notification');

        if ($notification) {
            // 清除session中的通知，避免重复显示
            Session::forget('notification');

            return response()->json([
                'hasNotification' => true,
                'notification' => $notification
            ]);
        }

        return response()->json(['hasNotification' => false]);
    }
}