import{r as c,j as r}from"./main-yCyLqVcf.js";import{m as M}from"./proxy-DDs1xMqj.js";import"./index-qgskiNTF.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 A=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),j=(...e)=>e.filter((a,t,i)=>!!a&&a.trim()!==""&&i.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 z={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 T=c.forwardRef(({color:e="currentColor",size:a=24,strokeWidth:t=2,absoluteStrokeWidth:i,className:d="",children:m,iconNode:h,...n},o)=>c.createElement("svg",{ref:o,...z,width:a,height:a,stroke:e,strokeWidth:i?Number(t)*24/Number(a):t,className:j("lucide",d),...n},[...h.map(([s,l])=>c.createElement(s,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:i,...d},m)=>c.createElement(T,{ref:m,iconNode:a,className:j(`lucide-${A(e)}`,i),...d}));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 $=[["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"}]],q=k("Radar",$);/**
 * @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 B=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],F=k("Square",B),D=/\b(hey|ok|hé)\b.*\b(obohr|obor|obhor|oboir)\b/;function O(e){return e.toLowerCase().normalize("NFD").replace(new RegExp("\\p{Diacritic}","gu"),"").replace(/[^a-z0-9\s]/g," ").replace(/\s+/g," ").trim()}function P(e){const a=O(e);return D.test(a)}function N(){const e=window;return e.SpeechRecognition||e.webkitSpeechRecognition||null}function V(){return!!N()}function U(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 i=0;const d=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 o,s;(o=e.onError)==null||o.call(e,n.error||"speech_error"),(s=e.onState)==null||s.call(e,"error")},t.onresult=n=>{var s;let o="";for(let l=n.resultIndex;l<n.results.length;l+=1)o+=n.results[l][0].transcript;if((s=e.onPartial)==null||s.call(e,o.trim()),P(o)){const l=Date.now();l-i>d&&(i=l,e.onWake(o.trim()))}},t.start(),t}function g(e){try{e==null||e.stop()}catch{}}function Z({enabled:e,onWake:a,lang:t="fr-FR"}){const[i,d]=c.useState(e?"listening":"idle"),[m,h]=c.useState(""),[n,o]=c.useState(null),s=c.useRef(null),l=c.useRef(e);return c.useEffect(()=>{l.current=e},[e]),c.useEffect(()=>{if(!e){g(s.current),d("idle");return}if(!V()){o("SpeechRecognition indisponible"),d("error");return}const p=()=>{s.current=U({lang:t,onWake:a,onPartial:y=>h(y),onState:y=>d(y),onError:y=>o(y)}),s.current&&(s.current.onend=()=>{l.current?setTimeout(p,600):d("stopped")})};return p(),()=>{g(s.current)}},[e,t,a]),{state:i,lastTranscript:m,error:n}}function J({isListening:e,transcript:a,alwaysListening:t,onToggle:i,onToggleAlwaysListening:d,onSendVoice:m}){const h=c.useRef(null),n=c.useRef([]),[o,s]=c.useState(null),l=c.useCallback(()=>{try{const u=new AudioContext,x=u.createOscillator(),f=u.createGain();x.type="sine",x.frequency.value=880,f.gain.value=.08,x.connect(f),f.connect(u.destination),x.start(),x.stop(u.currentTime+.15)}catch{}},[]),p=async()=>{s(null);const u=await navigator.mediaDevices.getUserMedia({audio:!0}),x=new MediaRecorder(u,{mimeType:"audio/webm"});x.ondataavailable=f=>{f.data.size>0&&n.current.push(f.data)},x.onstop=async()=>{const f=new Blob(n.current,{type:"audio/webm"});n.current=[];const W=await f.arrayBuffer(),C=btoa(String.fromCharCode(...new Uint8Array(W)));m(C),u.getTracks().forEach(E=>E.stop())},h.current=x,x.start(),i(!0)},y=()=>{var u;(u=h.current)==null||u.stop(),i(!1)},R=async()=>{try{e?y():await p()}catch(u){s(u instanceof Error?u.message:"Micro error")}},S=c.useCallback(u=>{l(),e||p().catch(()=>null)},[e,l]),{state:v,lastTranscript:w,error:b}=Z({enabled:t,onWake:S});return r.jsxs(M.section,{className:"hud-panel rounded-3xl p-6",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:R,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(F,{className:"h-5 w-5"}):r.jsx(I,{className:"h-5 w-5"})}),r.jsxs("button",{onClick:()=>d(!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(q,{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: ",v]}),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};
