const g=5,m=[{id:"chime",label:"Chime",description:"Soft two-note chime — the default.",tones:[{freq:880,start:0,duration:.18},{freq:1318.5,start:.13,duration:.28}]},{id:"ping",label:"Ping",description:"Single short blip. Least intrusive.",tones:[{freq:1568,start:0,duration:.14}]},{id:"bell",label:"Bell",description:"Three descending notes.",tones:[{freq:1318.5,start:0,duration:.16},{freq:1046.5,start:.12,duration:.16},{freq:783.99,start:.24,duration:.34}]},{id:"alert",label:"Alert",description:"Two firm beeps. Hardest to miss.",tones:[{freq:987.77,start:0,duration:.11,type:"square",gain:.16},{freq:987.77,start:.17,duration:.11,type:"square",gain:.16}]},{id:"pop",label:"Pop",description:"Short low pop. Quiet in an open office.",tones:[{freq:523.25,start:0,duration:.09},{freq:392,start:.06,duration:.12}]},{id:"rise",label:"Rise",description:"Rising three-note motif.",tones:[{freq:587.33,start:0,duration:.12},{freq:739.99,start:.1,duration:.12},{freq:987.77,start:.2,duration:.3}]}],r={enabled:!0,soundId:"chime",volume:.6,repeatMode:"ONCE",repeatIntervalSeconds:30},l="crm_notification_sound_v1",S="crm-notification-sound-changed",p=e=>m.find(t=>t.id===e),I=()=>{try{const e=localStorage.getItem(l);if(!e)return r;const t=JSON.parse(e);return{enabled:typeof t.enabled=="boolean"?t.enabled:r.enabled,soundId:typeof t.soundId=="string"&&p(t.soundId)?t.soundId:r.soundId,volume:typeof t.volume=="number"&&t.volume>=0&&t.volume<=1?t.volume:r.volume,repeatMode:t.repeatMode==="ONCE"||t.repeatMode==="UNTIL_READ"?t.repeatMode:r.repeatMode,repeatIntervalSeconds:typeof t.repeatIntervalSeconds=="number"&&t.repeatIntervalSeconds>=5?t.repeatIntervalSeconds:r.repeatIntervalSeconds}}catch{return r}},A=e=>{try{localStorage.setItem(l,JSON.stringify(e)),window.dispatchEvent(new Event(S))}catch{}};let d=null;const N=()=>{if(typeof window>"u")return null;const e=window.AudioContext??window.webkitAudioContext;if(!e)return null;if(!d)try{d=new e}catch{return null}return d},u=(e,t,o)=>{const n=e.currentTime;t.forEach(a=>{const i=e.createOscillator(),s=e.createGain();i.type=a.type??"sine",i.frequency.setValueAtTime(a.freq,n+a.start);const f=Math.max(o*(a.gain??.35),2e-4);s.gain.setValueAtTime(1e-4,n+a.start),s.gain.exponentialRampToValueAtTime(f,n+a.start+.015),s.gain.exponentialRampToValueAtTime(1e-4,n+a.start+a.duration),i.connect(s).connect(e.destination),i.start(n+a.start),i.stop(n+a.start+a.duration+.02)})},T=(e,t)=>{const o=N();if(!o)return;const n=Math.max(0,Math.min(1,t));if(n!==0){if(o.state==="suspended"){o.resume().then(()=>u(o,e,n)).catch(()=>{});return}u(o,e,n)}},h=(e,t)=>{const o=p(e);if(o){if(o.src){try{const n=new Audio(o.src);n.volume=Math.max(0,Math.min(1,t)),n.play().catch(()=>{})}catch{}return}T(o.tones,t)}},v=2e3;let c=0;const E=()=>{const e=I();if(!e.enabled)return;const t=Date.now();t-c<v||(c=t,h(e.soundId,e.volume))};export{g as M,m as N,h as a,S as b,I as l,E as p,A as s};
