import{r as c,j as r}from"./index-DVgsXMJe.js";import{m as A}from"./proxy-BdznxAXt.js";/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const z=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),j=(...e)=>e.filter((a,t,d)=>!!a&&a.trim()!==""&&d.indexOf(a)===t).join(" ").trim();/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */var T={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const _=c.forwardRef(({color:e="currentColor",size:a=24,strokeWidth:t=2,absoluteStrokeWidth:d,className:i="",children:m,iconNode:h,...n},s)=>c.createElement("svg",{ref:s,...T,width:a,height:a,stroke:e,strokeWidth:d?Number(t)*24/Number(a):t,className:j("lucide",i),...n},[...h.map(([o,l])=>c.createElement(o,l)),...Array.isArray(m)?m:[m]]));/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const k=(e,a)=>{const t=c.forwardRef(({className:d,...i},m)=>c.createElement(_,{ref:m,iconNode:a,className:j(`lucide-${z(e)}`,d),...i}));return t.displayName=`${e}`,t};/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const $=[["path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z",key:"131961"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}]],I=k("Mic",$);/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const q=[["path",{d:"M19.07 4.93A10 10 0 0 0 6.99 3.34",key:"z3du51"}],["path",{d:"M4 6h.01",key:"oypzma"}],["path",{d:"M2.29 9.62A10 10 0 1 0 21.31 8.35",key:"qzzz0"}],["path",{d:"M16.24 7.76A6 6 0 1 0 8.23 16.67",key:"1yjesh"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M17.99 11.66A6 6 0 0 1 15.77 16.67",key:"1u2y91"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"m13.41 10.59 5.66-5.66",key:"mhq4k0"}]],B=k("Radar",q);/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const F=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],D=k("Square",F),O=/\b(hey|ok|hé)\b.*\b(obohr|obor|obhor|oboir)\b/;function P(e){return e.toLowerCase().normalize("NFD").replace(new RegExp("\\p{Diacritic}","gu"),"").replace(/[^a-z0-9\s]/g," ").replace(/\s+/g," ").trim()}function V(e){const a=P(e);return O.test(a)}function N(){const e=window;return e.SpeechRecognition||e.webkitSpeechRecognition||null}function U(){return!!N()}function Z(e){var m,h;const a=N();if(!a)return(m=e.onError)==null||m.call(e,"SpeechRecognition not supported"),(h=e.onState)==null||h.call(e,"error"),null;const t=new a;t.lang=e.lang||"fr-FR",t.continuous=!0,t.interimResults=!0;let d=0;const i=e.debounceMs??1200;return t.onstart=()=>{var n;return(n=e.onState)==null?void 0:n.call(e,"listening")},t.onend=()=>{var n;return(n=e.onState)==null?void 0:n.call(e,"stopped")},t.onerror=n=>{var s,o;(s=e.onError)==null||s.call(e,n.error||"speech_error"),(o=e.onState)==null||o.call(e,"error")},t.onresult=n=>{var o;let s="";for(let l=n.resultIndex;l<n.results.length;l+=1)s+=n.results[l][0].transcript;if((o=e.onPartial)==null||o.call(e,s.trim()),V(s)){const l=Date.now();l-d>i&&(d=l,e.onWake(s.trim()))}},t.start(),t}function g(e){try{e==null||e.stop()}catch{}}function G({enabled:e,onWake:a,lang:t="fr-FR"}){const[d,i]=c.useState(e?"listening":"idle"),[m,h]=c.useState(""),[n,s]=c.useState(null),o=c.useRef(null),l=c.useRef(e);return c.useEffect(()=>{l.current=e},[e]),c.useEffect(()=>{if(!e){g(o.current),i("idle");return}if(!U()){s("SpeechRecognition indisponible"),i("error");return}const p=()=>{o.current=Z({lang:t,onWake:a,onPartial:f=>h(f),onState:f=>i(f),onError:f=>s(f)}),o.current&&(o.current.onend=()=>{l.current?setTimeout(p,600):i("stopped")})};return p(),()=>{g(o.current)}},[e,t,a]),{state:d,lastTranscript:m,error:n}}function J({isListening:e,transcript:a,alwaysListening:t,className:d="",onToggle:i,onToggleAlwaysListening:m,onSendVoice:h}){const n=c.useRef(null),s=c.useRef([]),[o,l]=c.useState(null),p=c.useCallback(()=>{try{const u=new AudioContext,x=u.createOscillator(),y=u.createGain();x.type="sine",x.frequency.value=880,y.gain.value=.08,x.connect(y),y.connect(u.destination),x.start(),x.stop(u.currentTime+.15)}catch{}},[]),f=async()=>{l(null);const u=await navigator.mediaDevices.getUserMedia({audio:!0}),x=new MediaRecorder(u,{mimeType:"audio/webm"});x.ondataavailable=y=>{y.data.size>0&&s.current.push(y.data)},x.onstop=async()=>{const y=new Blob(s.current,{type:"audio/webm"});s.current=[];const C=await y.arrayBuffer(),E=btoa(String.fromCharCode(...new Uint8Array(C)));h(E),u.getTracks().forEach(M=>M.stop())},n.current=x,x.start(),i(!0)},R=()=>{var u;(u=n.current)==null||u.stop(),i(!1)},S=async()=>{try{e?R():await f()}catch(u){l(u instanceof Error?u.message:"Micro error")}},v=c.useCallback(u=>{p(),e||f().catch(()=>null)},[e,p]),{state:W,lastTranscript:w,error:b}=G({enabled:t,onWake:v});return r.jsxs(A.section,{className:`hud-panel rounded-3xl p-6 ${d}`,initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.6,delay:.1},children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("h2",{className:"font-display text-lg text-neon-cyan",children:"Voice Interface"}),r.jsx("span",{className:"text-xs uppercase tracking-[0.3em] text-neon-cyan/60",children:"Whisper"})]}),r.jsxs("div",{className:"mt-6 flex flex-wrap items-center gap-4",children:[r.jsx("button",{onClick:S,className:"flex h-12 w-12 items-center justify-center rounded-full border border-neon-cyan/40 bg-neon-cyan/15 text-neon-cyan shadow-glow",children:e?r.jsx(D,{className:"h-5 w-5"}):r.jsx(I,{className:"h-5 w-5"})}),r.jsxs("button",{onClick:()=>m(!t),className:"flex items-center gap-2 rounded-full border border-neon-cyan/30 px-4 py-2 text-xs uppercase tracking-[0.3em] text-neon-cyan/80",children:[r.jsx(B,{className:"h-4 w-4"}),t?"Always On":"Wake OFF"]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-xs uppercase tracking-[0.3em] text-neon-cyan/60",children:"Status"}),r.jsx("p",{className:"text-sm text-white",children:e?"Listening…":"Idle"})]})]}),r.jsxs("div",{className:"mt-4 rounded-2xl border border-neon-cyan/15 bg-bg-800/60 p-4",children:[r.jsx("p",{className:"text-xs uppercase tracking-[0.3em] text-neon-cyan/60",children:"Transcript"}),r.jsx("p",{className:"mt-2 text-sm text-white",children:a||"Aucune transcription"}),o&&r.jsx("p",{className:"mt-2 text-sm text-rose-300",children:o}),t&&r.jsxs("div",{className:"mt-3 text-xs uppercase tracking-[0.3em] text-neon-cyan/50",children:["Wake state: ",W]}),w&&r.jsxs("p",{className:"mt-2 text-xs text-neon-cyan/60",children:["Wake text: ",w]}),b&&r.jsx("p",{className:"mt-2 text-xs text-rose-300",children:b})]})]})}export{J as VoiceInterface};
