/**
 * Joue une courte sonnerie d'alerte (double bip) via la Web Audio API.
 * Utilisée pour signaler de nouvelles notifications au livreur.
 */
export function playNotificationAlertSound(): void {
    if (typeof window === 'undefined') return;
    try {
        const Ctx = window.AudioContext || (window as unknown as { webkitAudioContext: typeof AudioContext }).webkitAudioContext;
        if (!Ctx) return;
        const ctx = new Ctx();
        if (ctx.state === 'suspended') {
            ctx.resume();
        }
        const playBeep = (frequency: number, startTime: number, duration: number) => {
            const osc = ctx.createOscillator();
            const gain = ctx.createGain();
            osc.connect(gain);
            gain.connect(ctx.destination);
            osc.frequency.value = frequency;
            osc.type = 'sine';
            gain.gain.setValueAtTime(0.15, startTime);
            gain.gain.exponentialRampToValueAtTime(0.01, startTime + duration);
            osc.start(startTime);
            osc.stop(startTime + duration);
        };
        playBeep(880, 0, 0.08);
        playBeep(880, 0.15, 0.08);
    } catch {
        // Ignore si l'API audio n'est pas disponible ou bloquée par le navigateur
    }
}
