import { useCallback, useEffect } from 'react';

export function useBrowserNotifications() {
    useEffect(() => {
        if ('Notification' in window && Notification.permission === 'default') {
            Notification.requestPermission();
        }
    }, []);

    const notify = useCallback((title: string, body: string) => {
        if ('Notification' in window && Notification.permission === 'granted') {
            new Notification(title, {
                body,
                icon: '/favicon.ico',
            });
        }

        // Play a subtle notification sound
        try {
            const audio = new Audio('/sounds/soundjay_notification_main-01.mp3');
            audio.volume = 0.3;
            audio.play().catch(() => {});
        } catch {
            // Audio not available
        }
    }, []);

    return { notify };
}
