lua-ai-chat 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';var react=require('react'),luaniverse=require('@lua-ai-global/luaniverse'),jsxRuntime=require('react/jsx-runtime'),reactVisuallyHidden=require('@radix-ui/react-visually-hidden'),St=require('react-markdown'),prismReactRenderer=require('prism-react-renderer'),reactLeaflet=require('react-leaflet');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var St__default=/*#__PURE__*/_interopDefault(St);function $l({onAudioRecorded:t,onClose:e,inputMessage:a}){let[l,r]=react.useState(false),[s,d]=react.useState(0),[u,n]=react.useState([]),[p,f]=react.useState(null),[o,i]=react.useState(null),h=react.useRef(null),c=react.useRef(null),v=react.useRef([]),g=react.useRef(null),C=react.useRef(null),x=react.useRef(null),N=react.useRef(null),m=react.useRef(false),w=react.useRef(false),U=react.useRef(null);react.useEffect(()=>{if(!l||!p)return;let P=setInterval(()=>{let k=Math.floor((Date.now()-p)/1e3);d(k);},1e3);return ()=>clearInterval(P)},[l,p]),react.useEffect(()=>((async()=>{if(!(m.current||w.current))try{m.current=!0;let k=await navigator.mediaDevices.getUserMedia({audio:!0});h.current=k,g.current=new AudioContext,C.current=g.current.createAnalyser(),C.current.fftSize=256,g.current.createMediaStreamSource(k).connect(C.current),x.current=new Uint8Array(C.current.frequencyBinCount);let q=()=>{if(!C.current||!x.current)return;C.current.getByteFrequencyData(x.current);let Wt=Array.from(x.current).map(Xt=>Xt/255);n(Wt),N.current=requestAnimationFrame(q);};q(),_t();}catch(k){console.error("Error accessing microphone:",k),e();}finally{m.current=false;}})(),()=>{B();}),[]);let B=()=>{if(!w.current)try{if(w.current=!0,l&&c.current&&(c.current.stop(),r(!1),f(null)),h.current){let P=h.current.getAudioTracks(),k=h.current.getVideoTracks();P.forEach(A=>{A.stop(),A.enabled=!1;}),k.forEach(A=>{A.stop(),A.enabled=!1;});}N.current&&cancelAnimationFrame(N.current),g.current&&g.current.close(),h.current=null,c.current=null,v.current=[],g.current=null,C.current=null,x.current=null,N.current=null;}finally{w.current=false;}},_t=()=>{if(!h.current)return;let k=["audio/webm","audio/mp4","audio/ogg","audio/wav"].find(q=>MediaRecorder.isTypeSupported(q));if(!k){console.error("No supported MIME type found for MediaRecorder"),e();return}U.current=k;let A=new MediaRecorder(h.current,{mimeType:k});c.current=A,v.current=[],A.ondataavailable=q=>{q.data.size>0&&v.current.push(q.data);},A.start(),r(true),f(Date.now()),d(0);},jt=async()=>{if(!c.current||!h.current)return;r(false),i(s),f(null),c.current.stop(),await new Promise(k=>{c.current&&(c.current.onstop=()=>k());});let P=new Blob(v.current,{type:U.current||"audio/webm"});t(P,a),B(),e();},mt=P=>{let k=Math.floor(P/60),A=P%60;return `${k.toString().padStart(2,"0")}:${A.toString().padStart(2,"0")}`};return jsxRuntime.jsxs("div",{className:"audio-recorder-container lua:bg-gray-100 lua:rounded-lg lua:p-2 lua:flex lua:items-center lua:gap-4",children:[jsxRuntime.jsx(luaniverse.IconButton,{variant:"muted",onClick:async()=>{B(),e();},className:"audio-recorder-close-button lua:flex-shrink-0",children:jsxRuntime.jsx(luaniverse.XIcon,{className:"audio-recorder-close-icon",color:"#00000099"})}),jsxRuntime.jsxs("div",{className:"audio-recorder-status lua:flex lua:items-center lua:gap-2",children:[jsxRuntime.jsx("div",{className:`audio-recorder-indicator lua:w-3 lua:h-3 lua:rounded-full ${l?"lua:bg-red-500 lua:animate-pulse":"lua:bg-gray-400"}`}),jsxRuntime.jsx("span",{className:"audio-recorder-time lua:text-gray-700 lua:text-sm",children:mt(l?s:o||0)})]}),jsxRuntime.jsx("div",{className:"audio-recorder-visualizer lua:flex-1","data-testid":"audio-visualizer-bar",children:u.length>0&&jsxRuntime.jsx("div",{className:"audio-recorder-bars lua:h-8 lua:flex lua:items-center lua:w-full lua:gap-px sm:lua:gap-0.5 md:lua:gap-1",children:u.slice(0,50).map((P,k)=>jsxRuntime.jsx("div",{className:"audio-recorder-bar lua:flex-1 lua:bg-blue-500",style:{height:`${P*100}%`}},k))})}),jsxRuntime.jsx(luaniverse.IconButton,{onClick:jt,className:"audio-recorder-send-button lua:flex-shrink-0 lua:mr-1","data-testid":"send-audio-button",children:jsxRuntime.jsx(luaniverse.ArrowUp,{className:"audio-recorder-send-icon",color:"white"})})]})}function aa(t){let e=Math.floor(t/60),a=t%60;return `${e.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}function Xl({videoRef:t,isRecording:e,recordingTime:a,loading:l,onStartRecording:r,onStopRecording:s,onClose:d,open:u}){return jsxRuntime.jsx(luaniverse.Dialog,{open:u,onOpenChange:d,children:jsxRuntime.jsxs(luaniverse.DialogContent,{className:"lua:w-full lua:max-w-2xl lua:p-2.5",showClose:false,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsxs("div",{className:"lua:relative lua:aspect-[4/3] lua:bg-black lua:rounded-xl lua:overflow-hidden lua:mb-8",children:[jsxRuntime.jsx("video",{ref:t,autoPlay:true,playsInline:true,muted:true,className:"lua:absolute lua:inset-0 lua:w-full lua:h-full lua:object-cover",style:{backgroundColor:"black"}}),e&&jsxRuntime.jsxs("div",{className:"lua:absolute lua:top-4 lua:left-4 lua:flex lua:items-center lua:gap-2 lua:bg-black lua:bg-opacity-50 lua:px-3 lua:py-1 lua:rounded-full",children:[jsxRuntime.jsx("div",{className:"lua:w-2 lua:h-2 lua:rounded-full lua:bg-red-500 lua:animate-pulse"}),jsxRuntime.jsx("span",{className:"lua:text-sm lua:font-medium lua:text-white",children:aa(a)})]})]}),jsxRuntime.jsx("div",{className:"lua:flex lua:justify-center lua:items-center lua:gap-5 lua:mb-2.5",children:e?jsxRuntime.jsx(luaniverse.IconButton,{"data-testid":"stop-recording-button",onClick:s,disabled:l,variant:"secondary",children:jsxRuntime.jsx(luaniverse.XIcon,{color:"#000000"})}):jsxRuntime.jsxs("svg",{onClick:r,"data-testid":"start-recording-button",width:"40",height:"40",viewBox:"0 0 40 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"cursor-pointer",children:[jsxRuntime.jsx("rect",{x:"2",y:"2",width:"36",height:"36",rx:"18",stroke:"#FF0342",strokeWidth:"4"}),jsxRuntime.jsx("rect",{x:"6",y:"6",width:"28",height:"28",rx:"14",fill:"#FF0342"})]})})]})})}function vt({url:t,alt:e,open:a,onClose:l}){return jsxRuntime.jsxs(luaniverse.Dialog,{open:a,onOpenChange:l,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsx(luaniverse.DialogContent,{className:"lua:w-full lua:fixed lua:inset-0 lua:h-full lua:max-w-none lua:p-0 lua:bg-transparent lua:shadow-none lua:translate-x-0 lua:translate-y-0 lua:m-0 lua:rounded-none",showClose:false,children:jsxRuntime.jsxs("div",{className:"lua:relative lua:w-full lua:h-full",children:[jsxRuntime.jsx("button",{onClick:l,className:"lua:cursor-pointer lua:absolute lua:top-4 lua:left-4 lua:z-10 lua:p-2 lua:bg-black/50 lua:rounded-full lua:hover:bg-black/70 lua:transition-colors",children:jsxRuntime.jsx(luaniverse.XIcon,{color:"white",className:"lua:w-6 lua:h-6"})}),jsxRuntime.jsx("div",{className:"lua:w-full lua:h-full lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("img",{src:t,alt:e,className:"sm:lua:aspect-[16/9] lua:object-contain lua:rounded-none sm:lua:rounded-lg"})})]})})]})}function yt({images:t,initialIndex:e=0,open:a,onClose:l}){let[r,s]=react.useState(),[d,u]=react.useState(0);return react.useEffect(()=>{if(!r)return;e>0&&e<t.length&&(r.scrollTo(e),u(e));let n=()=>{u(r.selectedScrollSnap());};return r.on("select",n),n(),()=>{r?.off("select",n);}},[r,e,t.length]),jsxRuntime.jsxs(luaniverse.Dialog,{open:a,onOpenChange:l,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsx(luaniverse.DialogContent,{className:"lua:w-full lua:m-0",showClose:false,children:jsxRuntime.jsxs("div",{className:"lua:relative lua:w-full lua:h-full",children:[jsxRuntime.jsx("button",{onClick:l,className:"lua:cursor-pointer lua:absolute lua:top-4 lua:left-4 lua:z-10 lua:p-2 lua:bg-black/50 lua:rounded-full lua:hover:bg-black/70 lua:transition-colors",children:jsxRuntime.jsx(luaniverse.XIcon,{color:"white",className:"lua:w-6 lua:h-6"})}),t.length>1&&jsxRuntime.jsxs("div",{className:"lua:absolute lua:top-4 lua:right-4 lua:z-10 lua:px-3 lua:py-1 lua:bg-black/50 lua:rounded-full lua:text-white lua:text-sm",children:[d+1," / ",t.length]}),jsxRuntime.jsx("div",{className:"lua:w-full lua:h-full lua:flex lua:items-center lua:justify-center lua:px-16",children:jsxRuntime.jsxs(luaniverse.Carousel,{setApi:s,className:"lua:w-full lua:max-w-5xl",opts:{align:"center",loop:t.length>1},children:[jsxRuntime.jsx(luaniverse.CarouselContent,{children:t.map((n,p)=>jsxRuntime.jsx(luaniverse.CarouselItem,{className:"lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("img",{src:n.src,alt:n.alt||`Image ${p+1}`,className:"lua:max-w-full lua:max-h-screen lua:object-contain lua:rounded-none sm:lua:rounded-lg",draggable:false})},p))}),t.length>1&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(luaniverse.CarouselPrevious,{className:"lua:left-4 lua:bg-black/50 lua:border-none lua:text-white lua:hover:bg-black/70 lua:hover:text-white-white/70"}),jsxRuntime.jsx(luaniverse.CarouselNext,{className:"lua:right-4 lua:bg-black/50 lua:border-none lua:text-white lua:hover:bg-black/70 lua:hover:text-white-white/70"})]})]})})]})})]})}function ir({videoRef:t,canvasRef:e,onCapture:a,onClose:l,open:r}){return jsxRuntime.jsxs(luaniverse.Dialog,{open:r,onOpenChange:l,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsxs(luaniverse.DialogContent,{className:"lua:w-full lua:max-w-2xl lua:p-2.5",showClose:false,children:[jsxRuntime.jsxs("div",{className:"lua:relative lua:aspect-[16/9] lua:bg-black lua:rounded-xl lua:overflow-hidden",children:[jsxRuntime.jsx("video",{ref:t,autoPlay:true,playsInline:true,muted:true,className:"lua:absolute lua:inset-0 lua:w-full lua:h-full lua:object-cover",style:{backgroundColor:"black"}}),jsxRuntime.jsx("canvas",{ref:e,className:"lua:hidden"})]}),jsxRuntime.jsxs("div",{className:"lua:flex lua:justify-center lua:items-center lua:gap-5 lua:mb-2.5 lua:mt-6",children:[jsxRuntime.jsx(luaniverse.IconButton,{onClick:a,"data-testid":"capture-button",children:jsxRuntime.jsx(luaniverse.Camera,{color:"#FFFFFF"})}),jsxRuntime.jsx(luaniverse.IconButton,{onClick:l,variant:"secondary",children:jsxRuntime.jsx(luaniverse.XIcon,{color:"#000000"})})]})]})]})}function cr({locationError:t,currentLocation:e,loading:a,onShare:l,onClose:r}){return jsxRuntime.jsx("div",{className:"lua:fixed lua:inset-0 lua:bg-black lua:bg-opacity-75 lua:flex lua:items-center lua:justify-center lua:z-50",children:jsxRuntime.jsxs("div",{className:"lua:bg-white lua:rounded-lg lua:p-4 lua:max-w-2xl lua:w-full lua:mx-4",children:[jsxRuntime.jsxs("div",{className:"lua:flex lua:justify-between lua:items-center lua:mb-4",children:[jsxRuntime.jsx("h3",{className:"lua:text-lg lua:font-semibold",children:"Share Location"}),jsxRuntime.jsx("button",{onClick:r,className:"lua:text-gray-500 lua:hover:text-gray-700",children:jsxRuntime.jsx("svg",{className:"lua:w-6 lua:h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsxRuntime.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),t?jsxRuntime.jsx("div",{className:"lua:bg-red-50 lua:text-red-500 lua:p-4 lua:rounded-lg lua:mb-4",children:t}):e?jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"lua:mb-4",children:[jsxRuntime.jsx("div",{className:"lua:text-sm lua:text-gray-500 lua:mb-2",children:"Current Location:"}),jsxRuntime.jsx("div",{className:"lua:text-gray-700 lua:mb-2",children:e.address}),jsxRuntime.jsxs("div",{className:"lua:text-sm lua:text-gray-500",children:[e.latitude.toFixed(6),","," ",e.longitude.toFixed(6)]})]})}):jsxRuntime.jsx("div",{className:"lua:flex lua:justify-center lua:items-center lua:h-48",children:jsxRuntime.jsx("div",{className:"lua:animate-spin lua:rounded-full lua:h-8 lua:w-8 lua:border-b-2 lua:border-blue-500"})}),jsxRuntime.jsx("div",{className:"lua:flex lua:justify-center",children:e&&jsxRuntime.jsxs("button",{onClick:l,disabled:a,className:`lua:px-4 lua:py-2 lua:rounded-full ${a?"lua:bg-blue-300 lua:cursor-not-allowed":"lua:bg-blue-500 lua:hover:bg-blue-600"} lua:text-white lua:flex lua:items-center lua:gap-2`,children:[jsxRuntime.jsx("svg",{className:"lua:w-5 lua:h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsxRuntime.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"})}),a?"Sharing...":"Share Location"]})})]})})}function Ct({children:t,language:e=""}){let[a,l]=react.useState(false),r=typeof t=="string"?t:String(t),s=e||"javascript";return jsxRuntime.jsxs("div",{className:"lua:relative lua:my-4 lua:rounded-lg lua:overflow-hidden lua:mx-4 lua:sm:mx-5 lua:grid",children:[jsxRuntime.jsxs("div",{className:"lua:flex lua:items-center lua:justify-between lua:bg-gray-800 lua:text-gray-200 lua:px-4 lua:py-2",children:[jsxRuntime.jsx("span",{className:"lua:text-xs lua:font-mono",children:s}),jsxRuntime.jsx("button",{onClick:()=>{navigator.clipboard.writeText(r),l(true),setTimeout(()=>l(false),2e3);},className:"lua:text-xs lua:bg-gray-700 lua:hover:bg-gray-600 lua:rounded lua:px-2 lua:py-1 lua:transition-colors","aria-label":"Copy code",children:a?"Copied!":"Copy"})]}),jsxRuntime.jsx(prismReactRenderer.Highlight,{theme:prismReactRenderer.themes.vsDark,code:r,language:s,children:({className:u,style:n,tokens:p,getLineProps:f,getTokenProps:o})=>jsxRuntime.jsx("pre",{className:`${u} lua:p-4 lua:overflow-x-auto`,style:n,children:p.map((i,h)=>jsxRuntime.jsx("div",{...f({line:i}),children:i.map((c,v)=>jsxRuntime.jsx("span",{...o({token:c})},v))},h))})})]})}var L={p:"lua:mb-2 lua:last:mb-0 lua:mx-4 lua:sm:mx-5 lua-paragraph-markdown",h1:"lua:text-2xl lua:font-bold lua:mb-2 lua:mx-4 lua:sm:mx-5",h2:"lua:text-xl lua:font-semibold lua:mb-2 lua:text-gray-700 lua:mx-4 lua:sm:mx-5",h3:"lua:text-lg lua:font-medium lua:mb-2 lua:mx-4 lua:sm:mx-5",h4:"lua:mx-4 lua:sm:mx-5",ul:"lua:list-disc lua:pl-6 lua:mb-4",ol:"lua:list-decimal lua:pl-6 lua:mb-4 lua:mx-4 lua:sm:mx-5",li:"lua:mb-1 lua:mx-4 lua:sm:mx-5",a:"lua:text-blue-500 lua:hover:underline",blockquote:"lua:border-l-4 lua:border-gray-200 lua:pl-4 lua:italic lua:my-4",pre:"lua:contents lua:bg-gray-100 lua:rounded lua:px-1 lua:text-gray-700 lua:mx-4 lua:sm:mx-5",code:"lua:bg-gray-100 lua:rounded lua:px-1 lua:mx-4 lua:sm:mx-5",img:"lua:max-w-full lua:h-auto lua:rounded-lg lua:mb-2",table:"lua:min-w-full lua:border lua:border-gray-200 lua:my-4",th:"lua:bg-gray-100 lua:border lua:border-gray-200 lua:px-4 lua:py-2",td:"lua:border lua:border-gray-200 lua:px-4 lua:py-2"};var Ra=t=>({code({children:e,className:a,...l}){let r=a?.replace("language-","")||"";return typeof e=="string"&&!e.includes(`
1
+ 'use strict';var luaniverse=require('luaniverse'),react=require('react'),jsxRuntime=require('react/jsx-runtime'),reactVisuallyHidden=require('@radix-ui/react-visually-hidden'),St=require('react-markdown'),prismReactRenderer=require('prism-react-renderer'),reactLeaflet=require('react-leaflet');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var St__default=/*#__PURE__*/_interopDefault(St);function $l({onAudioRecorded:t,onClose:e,inputMessage:a}){let[l,r]=react.useState(false),[s,d]=react.useState(0),[u,n]=react.useState([]),[p,f]=react.useState(null),[o,i]=react.useState(null),h=react.useRef(null),c=react.useRef(null),v=react.useRef([]),g=react.useRef(null),C=react.useRef(null),x=react.useRef(null),N=react.useRef(null),m=react.useRef(false),w=react.useRef(false),U=react.useRef(null);react.useEffect(()=>{if(!l||!p)return;let P=setInterval(()=>{let k=Math.floor((Date.now()-p)/1e3);d(k);},1e3);return ()=>clearInterval(P)},[l,p]),react.useEffect(()=>((async()=>{if(!(m.current||w.current))try{m.current=!0;let k=await navigator.mediaDevices.getUserMedia({audio:!0});h.current=k,g.current=new AudioContext,C.current=g.current.createAnalyser(),C.current.fftSize=256,g.current.createMediaStreamSource(k).connect(C.current),x.current=new Uint8Array(C.current.frequencyBinCount);let q=()=>{if(!C.current||!x.current)return;C.current.getByteFrequencyData(x.current);let Wt=Array.from(x.current).map(Xt=>Xt/255);n(Wt),N.current=requestAnimationFrame(q);};q(),_t();}catch(k){console.error("Error accessing microphone:",k),e();}finally{m.current=false;}})(),()=>{B();}),[]);let B=()=>{if(!w.current)try{if(w.current=!0,l&&c.current&&(c.current.stop(),r(!1),f(null)),h.current){let P=h.current.getAudioTracks(),k=h.current.getVideoTracks();P.forEach(A=>{A.stop(),A.enabled=!1;}),k.forEach(A=>{A.stop(),A.enabled=!1;});}N.current&&cancelAnimationFrame(N.current),g.current&&g.current.close(),h.current=null,c.current=null,v.current=[],g.current=null,C.current=null,x.current=null,N.current=null;}finally{w.current=false;}},_t=()=>{if(!h.current)return;let k=["audio/webm","audio/mp4","audio/ogg","audio/wav"].find(q=>MediaRecorder.isTypeSupported(q));if(!k){console.error("No supported MIME type found for MediaRecorder"),e();return}U.current=k;let A=new MediaRecorder(h.current,{mimeType:k});c.current=A,v.current=[],A.ondataavailable=q=>{q.data.size>0&&v.current.push(q.data);},A.start(),r(true),f(Date.now()),d(0);},jt=async()=>{if(!c.current||!h.current)return;r(false),i(s),f(null),c.current.stop(),await new Promise(k=>{c.current&&(c.current.onstop=()=>k());});let P=new Blob(v.current,{type:U.current||"audio/webm"});t(P,a),B(),e();},mt=P=>{let k=Math.floor(P/60),A=P%60;return `${k.toString().padStart(2,"0")}:${A.toString().padStart(2,"0")}`};return jsxRuntime.jsxs("div",{className:"audio-recorder-container lua:bg-gray-100 lua:rounded-lg lua:p-2 lua:flex lua:items-center lua:gap-4",children:[jsxRuntime.jsx(luaniverse.IconButton,{variant:"muted",onClick:async()=>{B(),e();},className:"audio-recorder-close-button lua:flex-shrink-0",children:jsxRuntime.jsx(luaniverse.XIcon,{className:"audio-recorder-close-icon",color:"#00000099"})}),jsxRuntime.jsxs("div",{className:"audio-recorder-status lua:flex lua:items-center lua:gap-2",children:[jsxRuntime.jsx("div",{className:`audio-recorder-indicator lua:w-3 lua:h-3 lua:rounded-full ${l?"lua:bg-red-500 lua:animate-pulse":"lua:bg-gray-400"}`}),jsxRuntime.jsx("span",{className:"audio-recorder-time lua:text-gray-700 lua:text-sm",children:mt(l?s:o||0)})]}),jsxRuntime.jsx("div",{className:"audio-recorder-visualizer lua:flex-1","data-testid":"audio-visualizer-bar",children:u.length>0&&jsxRuntime.jsx("div",{className:"audio-recorder-bars lua:h-8 lua:flex lua:items-center lua:w-full lua:gap-px sm:lua:gap-0.5 md:lua:gap-1",children:u.slice(0,50).map((P,k)=>jsxRuntime.jsx("div",{className:"audio-recorder-bar lua:flex-1 lua:bg-blue-500",style:{height:`${P*100}%`}},k))})}),jsxRuntime.jsx(luaniverse.IconButton,{onClick:jt,className:"audio-recorder-send-button lua:flex-shrink-0 lua:mr-1","data-testid":"send-audio-button",children:jsxRuntime.jsx(luaniverse.ArrowUp,{className:"audio-recorder-send-icon",color:"white"})})]})}function aa(t){let e=Math.floor(t/60),a=t%60;return `${e.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}function Xl({videoRef:t,isRecording:e,recordingTime:a,loading:l,onStartRecording:r,onStopRecording:s,onClose:d,open:u}){return jsxRuntime.jsx(luaniverse.Dialog,{open:u,onOpenChange:d,children:jsxRuntime.jsxs(luaniverse.DialogContent,{className:"lua:w-full lua:max-w-2xl lua:p-2.5",showClose:false,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsxs("div",{className:"lua:relative lua:aspect-[4/3] lua:bg-black lua:rounded-xl lua:overflow-hidden lua:mb-8",children:[jsxRuntime.jsx("video",{ref:t,autoPlay:true,playsInline:true,muted:true,className:"lua:absolute lua:inset-0 lua:w-full lua:h-full lua:object-cover",style:{backgroundColor:"black"}}),e&&jsxRuntime.jsxs("div",{className:"lua:absolute lua:top-4 lua:left-4 lua:flex lua:items-center lua:gap-2 lua:bg-black lua:bg-opacity-50 lua:px-3 lua:py-1 lua:rounded-full",children:[jsxRuntime.jsx("div",{className:"lua:w-2 lua:h-2 lua:rounded-full lua:bg-red-500 lua:animate-pulse"}),jsxRuntime.jsx("span",{className:"lua:text-sm lua:font-medium lua:text-white",children:aa(a)})]})]}),jsxRuntime.jsx("div",{className:"lua:flex lua:justify-center lua:items-center lua:gap-5 lua:mb-2.5",children:e?jsxRuntime.jsx(luaniverse.IconButton,{"data-testid":"stop-recording-button",onClick:s,disabled:l,variant:"secondary",children:jsxRuntime.jsx(luaniverse.XIcon,{color:"#000000"})}):jsxRuntime.jsxs("svg",{onClick:r,"data-testid":"start-recording-button",width:"40",height:"40",viewBox:"0 0 40 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"cursor-pointer",children:[jsxRuntime.jsx("rect",{x:"2",y:"2",width:"36",height:"36",rx:"18",stroke:"#FF0342",strokeWidth:"4"}),jsxRuntime.jsx("rect",{x:"6",y:"6",width:"28",height:"28",rx:"14",fill:"#FF0342"})]})})]})})}function vt({url:t,alt:e,open:a,onClose:l}){return jsxRuntime.jsxs(luaniverse.Dialog,{open:a,onOpenChange:l,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsx(luaniverse.DialogContent,{className:"lua:w-full lua:fixed lua:inset-0 lua:h-full lua:max-w-none lua:p-0 lua:bg-transparent lua:shadow-none lua:translate-x-0 lua:translate-y-0 lua:m-0 lua:rounded-none",showClose:false,children:jsxRuntime.jsxs("div",{className:"lua:relative lua:w-full lua:h-full",children:[jsxRuntime.jsx("button",{onClick:l,className:"lua:cursor-pointer lua:absolute lua:top-4 lua:left-4 lua:z-10 lua:p-2 lua:bg-black/50 lua:rounded-full lua:hover:bg-black/70 lua:transition-colors",children:jsxRuntime.jsx(luaniverse.XIcon,{color:"white",className:"lua:w-6 lua:h-6"})}),jsxRuntime.jsx("div",{className:"lua:w-full lua:h-full lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("img",{src:t,alt:e,className:"sm:lua:aspect-[16/9] lua:object-contain lua:rounded-none sm:lua:rounded-lg"})})]})})]})}function yt({images:t,initialIndex:e=0,open:a,onClose:l}){let[r,s]=react.useState(),[d,u]=react.useState(0);return react.useEffect(()=>{if(!r)return;e>0&&e<t.length&&(r.scrollTo(e),u(e));let n=()=>{u(r.selectedScrollSnap());};return r.on("select",n),n(),()=>{r?.off("select",n);}},[r,e,t.length]),jsxRuntime.jsxs(luaniverse.Dialog,{open:a,onOpenChange:l,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsx(luaniverse.DialogContent,{className:"lua:w-full lua:m-0",showClose:false,children:jsxRuntime.jsxs("div",{className:"lua:relative lua:w-full lua:h-full",children:[jsxRuntime.jsx("button",{onClick:l,className:"lua:cursor-pointer lua:absolute lua:top-4 lua:left-4 lua:z-10 lua:p-2 lua:bg-black/50 lua:rounded-full lua:hover:bg-black/70 lua:transition-colors",children:jsxRuntime.jsx(luaniverse.XIcon,{color:"white",className:"lua:w-6 lua:h-6"})}),t.length>1&&jsxRuntime.jsxs("div",{className:"lua:absolute lua:top-4 lua:right-4 lua:z-10 lua:px-3 lua:py-1 lua:bg-black/50 lua:rounded-full lua:text-white lua:text-sm",children:[d+1," / ",t.length]}),jsxRuntime.jsx("div",{className:"lua:w-full lua:h-full lua:flex lua:items-center lua:justify-center lua:px-16",children:jsxRuntime.jsxs(luaniverse.Carousel,{setApi:s,className:"lua:w-full lua:max-w-5xl",opts:{align:"center",loop:t.length>1},children:[jsxRuntime.jsx(luaniverse.CarouselContent,{children:t.map((n,p)=>jsxRuntime.jsx(luaniverse.CarouselItem,{className:"lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("img",{src:n.src,alt:n.alt||`Image ${p+1}`,className:"lua:max-w-full lua:max-h-screen lua:object-contain lua:rounded-none sm:lua:rounded-lg",draggable:false})},p))}),t.length>1&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(luaniverse.CarouselPrevious,{className:"lua:left-4 lua:bg-black/50 lua:border-none lua:text-white lua:hover:bg-black/70 lua:hover:text-white-white/70"}),jsxRuntime.jsx(luaniverse.CarouselNext,{className:"lua:right-4 lua:bg-black/50 lua:border-none lua:text-white lua:hover:bg-black/70 lua:hover:text-white-white/70"})]})]})})]})})]})}function ir({videoRef:t,canvasRef:e,onCapture:a,onClose:l,open:r}){return jsxRuntime.jsxs(luaniverse.Dialog,{open:r,onOpenChange:l,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsxs(luaniverse.DialogContent,{className:"lua:w-full lua:max-w-2xl lua:p-2.5",showClose:false,children:[jsxRuntime.jsxs("div",{className:"lua:relative lua:aspect-[16/9] lua:bg-black lua:rounded-xl lua:overflow-hidden",children:[jsxRuntime.jsx("video",{ref:t,autoPlay:true,playsInline:true,muted:true,className:"lua:absolute lua:inset-0 lua:w-full lua:h-full lua:object-cover",style:{backgroundColor:"black"}}),jsxRuntime.jsx("canvas",{ref:e,className:"lua:hidden"})]}),jsxRuntime.jsxs("div",{className:"lua:flex lua:justify-center lua:items-center lua:gap-5 lua:mb-2.5 lua:mt-6",children:[jsxRuntime.jsx(luaniverse.IconButton,{onClick:a,"data-testid":"capture-button",children:jsxRuntime.jsx(luaniverse.Camera,{color:"#FFFFFF"})}),jsxRuntime.jsx(luaniverse.IconButton,{onClick:l,variant:"secondary",children:jsxRuntime.jsx(luaniverse.XIcon,{color:"#000000"})})]})]})]})}function cr({locationError:t,currentLocation:e,loading:a,onShare:l,onClose:r}){return jsxRuntime.jsx("div",{className:"lua:fixed lua:inset-0 lua:bg-black lua:bg-opacity-75 lua:flex lua:items-center lua:justify-center lua:z-50",children:jsxRuntime.jsxs("div",{className:"lua:bg-white lua:rounded-lg lua:p-4 lua:max-w-2xl lua:w-full lua:mx-4",children:[jsxRuntime.jsxs("div",{className:"lua:flex lua:justify-between lua:items-center lua:mb-4",children:[jsxRuntime.jsx("h3",{className:"lua:text-lg lua:font-semibold",children:"Share Location"}),jsxRuntime.jsx("button",{onClick:r,className:"lua:text-gray-500 lua:hover:text-gray-700",children:jsxRuntime.jsx("svg",{className:"lua:w-6 lua:h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsxRuntime.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),t?jsxRuntime.jsx("div",{className:"lua:bg-red-50 lua:text-red-500 lua:p-4 lua:rounded-lg lua:mb-4",children:t}):e?jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"lua:mb-4",children:[jsxRuntime.jsx("div",{className:"lua:text-sm lua:text-gray-500 lua:mb-2",children:"Current Location:"}),jsxRuntime.jsx("div",{className:"lua:text-gray-700 lua:mb-2",children:e.address}),jsxRuntime.jsxs("div",{className:"lua:text-sm lua:text-gray-500",children:[e.latitude.toFixed(6),","," ",e.longitude.toFixed(6)]})]})}):jsxRuntime.jsx("div",{className:"lua:flex lua:justify-center lua:items-center lua:h-48",children:jsxRuntime.jsx("div",{className:"lua:animate-spin lua:rounded-full lua:h-8 lua:w-8 lua:border-b-2 lua:border-blue-500"})}),jsxRuntime.jsx("div",{className:"lua:flex lua:justify-center",children:e&&jsxRuntime.jsxs("button",{onClick:l,disabled:a,className:`lua:px-4 lua:py-2 lua:rounded-full ${a?"lua:bg-blue-300 lua:cursor-not-allowed":"lua:bg-blue-500 lua:hover:bg-blue-600"} lua:text-white lua:flex lua:items-center lua:gap-2`,children:[jsxRuntime.jsx("svg",{className:"lua:w-5 lua:h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsxRuntime.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"})}),a?"Sharing...":"Share Location"]})})]})})}function Ct({children:t,language:e=""}){let[a,l]=react.useState(false),r=typeof t=="string"?t:String(t),s=e||"javascript";return jsxRuntime.jsxs("div",{className:"lua:relative lua:my-4 lua:rounded-lg lua:overflow-hidden lua:mx-4 lua:sm:mx-5 lua:grid",children:[jsxRuntime.jsxs("div",{className:"lua:flex lua:items-center lua:justify-between lua:bg-gray-800 lua:text-gray-200 lua:px-4 lua:py-2",children:[jsxRuntime.jsx("span",{className:"lua:text-xs lua:font-mono",children:s}),jsxRuntime.jsx("button",{onClick:()=>{navigator.clipboard.writeText(r),l(true),setTimeout(()=>l(false),2e3);},className:"lua:text-xs lua:bg-gray-700 lua:hover:bg-gray-600 lua:rounded lua:px-2 lua:py-1 lua:transition-colors","aria-label":"Copy code",children:a?"Copied!":"Copy"})]}),jsxRuntime.jsx(prismReactRenderer.Highlight,{theme:prismReactRenderer.themes.vsDark,code:r,language:s,children:({className:u,style:n,tokens:p,getLineProps:f,getTokenProps:o})=>jsxRuntime.jsx("pre",{className:`${u} lua:p-4 lua:overflow-x-auto`,style:n,children:p.map((i,h)=>jsxRuntime.jsx("div",{...f({line:i}),children:i.map((c,v)=>jsxRuntime.jsx("span",{...o({token:c})},v))},h))})})]})}var L={p:"lua:mb-2 lua:last:mb-0 lua:mx-4 lua:sm:mx-5 lua-paragraph-markdown",h1:"lua:text-2xl lua:font-bold lua:mb-2 lua:mx-4 lua:sm:mx-5",h2:"lua:text-xl lua:font-semibold lua:mb-2 lua:text-gray-700 lua:mx-4 lua:sm:mx-5",h3:"lua:text-lg lua:font-medium lua:mb-2 lua:mx-4 lua:sm:mx-5",h4:"lua:mx-4 lua:sm:mx-5",ul:"lua:list-disc lua:pl-6 lua:mb-4",ol:"lua:list-decimal lua:pl-6 lua:mb-4 lua:mx-4 lua:sm:mx-5",li:"lua:mb-1 lua:mx-4 lua:sm:mx-5",a:"lua:text-blue-500 lua:hover:underline",blockquote:"lua:border-l-4 lua:border-gray-200 lua:pl-4 lua:italic lua:my-4",pre:"lua:contents lua:bg-gray-100 lua:rounded lua:px-1 lua:text-gray-700 lua:mx-4 lua:sm:mx-5",code:"lua:bg-gray-100 lua:rounded lua:px-1 lua:mx-4 lua:sm:mx-5",img:"lua:max-w-full lua:h-auto lua:rounded-lg lua:mb-2",table:"lua:min-w-full lua:border lua:border-gray-200 lua:my-4",th:"lua:bg-gray-100 lua:border lua:border-gray-200 lua:px-4 lua:py-2",td:"lua:border lua:border-gray-200 lua:px-4 lua:py-2"};var Ra=t=>({code({children:e,className:a,...l}){let r=a?.replace("language-","")||"";return typeof e=="string"&&!e.includes(`
2
2
  `)?jsxRuntime.jsx("code",{className:L.code,...l,children:e}):jsxRuntime.jsx(Ct,{language:r,className:a,children:e})},p({children:e,...a}){return jsxRuntime.jsx("p",{className:L.p,...a,children:e})},h1({children:e,...a}){return jsxRuntime.jsx("h1",{className:L.h1,...a,children:e})},h2({children:e,...a}){return jsxRuntime.jsx("h2",{className:L.h2,...a,children:e})},h3({children:e,...a}){return jsxRuntime.jsx("h3",{className:L.h3,...a,children:e})},h4({children:e,...a}){return jsxRuntime.jsx("h4",{className:L.h4,...a,children:e})},img({src:e,alt:a}){return jsxRuntime.jsx("img",{src:e,alt:a,className:"lua:w-full lua:h-48 lua:object-cover lua:rounded-lg lua:mb-3"})},ul({children:e,...a}){return jsxRuntime.jsx("ul",{className:L.ul,...a,children:e})},ol({children:e,...a}){return jsxRuntime.jsx("ol",{className:L.ol,...a,children:e})},li({children:e,...a}){return jsxRuntime.jsx("li",{className:`${L.li} cursor-pointer hover:bg-gray-50 rounded px-2 -mx-2 transition-colors`,onClick:()=>t(e),...a,children:e})},a({href:e,children:a,...l}){return jsxRuntime.jsx("a",{href:e,className:L.a,target:"_blank",rel:"noopener noreferrer",...l,children:a})},blockquote({children:e,...a}){return jsxRuntime.jsx("blockquote",{className:L.blockquote,...a,children:e})},pre({children:e}){return jsxRuntime.jsx(jsxRuntime.Fragment,{children:e})},table({children:e,...a}){return jsxRuntime.jsx("table",{className:L.table,...a,children:e})},th({children:e,...a}){return jsxRuntime.jsx("th",{className:L.th,...a,children:e})},td({children:e,...a}){return jsxRuntime.jsx("td",{className:L.td,...a,children:e})}}),be=Ra;function Ua(t){let e=new URL(t,"http://lua"),a=decodeURIComponent(e.pathname),l={};for(let[r,s]of e.searchParams.entries())l[r]=decodeURIComponent(s);return {pathname:a,queryParams:l}}var we=Ua;function Da(t){let e=t.match(/\[navigate\]\(([^)]+)\)/);return e?e[1]:null}var Nt=Da;var Fa=react.memo(function({block:e,onCardClick:a,onListItemClick:l,onNavigate:r}){let s=e.content.match(/^#\s+(.+)$/m),d=e.content.match(/!\[.*?]\((.*)\)/),u=s?s[1]:"",n=d?d[1]:null,p=Nt(e.content),f=e.content.replace(/^#\s+.+$/m,"").replace(/!\[.*?]\(.*?\)/g,"").replace(/\[.*?]\(.*?\)/g,"").trim(),o=be(l);return jsxRuntime.jsxs("div",{onClick:()=>{if(r&&p){let h=we(p);r(h.pathname,{...h.queryParams&&{query:h.queryParams}});}else a(e.content);},className:"chat-list-item group",children:[jsxRuntime.jsx("div",{className:"lua:absolute lua:inset-0 lua:bg-blue-500 lua:opacity-0 group-hover:lua:opacity-5 lua:rounded-lg lua:transition-opacity lua:duration-200"}),jsxRuntime.jsxs("div",{className:"chat-list-item-content",children:[n?jsxRuntime.jsx("div",{className:"chat-list-item-image-wrapper",children:jsxRuntime.jsx("img",{className:"chat-list-item-image",src:n,alt:u})}):null,jsxRuntime.jsxs("div",{className:"content-container",children:[jsxRuntime.jsx("h1",{className:"lua:text-base lua:leading-6 lua:font-semibold lua:text-gray-900 lua:mb-0",children:u}),jsxRuntime.jsx("div",{className:"lua:text-sm lua:leading-6 lua:font-normal lua:text-gray-600",children:jsxRuntime.jsx(St__default.default,{components:o,children:f})})]})]})]})}),re=Fa;var Ba=react.memo(function({group:e,onCardClick:a,onListItemClick:l,onNavigate:r}){return jsxRuntime.jsx("div",{className:"lua:w-full",children:jsxRuntime.jsx("div",{className:"chat-list-item-container",children:e.map((s,d)=>jsxRuntime.jsx(re,{block:s,onCardClick:a,onListItemClick:l,onNavigate:r},d))})})}),kt=Ba;function Oa(t){return {icon:()=>null}}function Ne({documents:t}){return t.map(e=>{let l=Oa(new File([],"",{type:e.mimeType})).icon;return jsxRuntime.jsx("a",{"data-testid":"chat-file-message",href:e.url,target:"_blank",rel:"noopener noreferrer",className:"chat-file-message lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsx("div",{className:"lua:flex lua:flex-col lua:gap-8",children:jsxRuntime.jsxs("div",{className:"chat-file-card lua:flex lua:items-center lua:justify-start lua:p-3 lua:border lua:border-gray-200 lua:rounded-lg lua:bg-white lua:w-80",children:[jsxRuntime.jsx(l,{className:"lua:w-12 lua:h-12 lua:text-gray-500"}),jsxRuntime.jsxs("div",{className:"lua:flex lua:flex-col lua:gap-1 lua:pl-2",children:[e.fileName||"File",jsxRuntime.jsx("span",{className:"lua:text-gray-500 lua:text-sm",children:e.mimeType})]})]})})},e.url)})}function $a(t){let e=[],a=t.split(`
3
3
  `).filter(l=>l.trim()!=="");for(let l of a){let r=/\[([^\]]+)\]\(([^)]+)\)\s+filename:([^\s]+)\s+mime:([^\s]+)/g,s;for(;(s=r.exec(l))!==null;){let[,d,u,n,p]=s;e.push({fileName:d.trim(),url:u.trim(),filename:n.trim(),mimeType:p.trim()});}}return e}var De=$a;function Lt({message:t}){return jsxRuntime.jsx("div",{className:"chat-audio-message lua:flex lua:flex-col lua:mx-4 lua:sm:mx-5","data-testid":"audio-preview",children:jsxRuntime.jsx("div",{className:"chat-audio-container audio-playback-container lua:relative",children:jsxRuntime.jsxs("div",{className:"chat-audio-controls lua:flex lua:items-center lua:gap-2 lua:min-w-full",children:[jsxRuntime.jsx("audio",{src:t.url,controls:true,className:"chat-audio-player lua:h-8",style:{backgroundColor:"transparent",border:"none"}}),t.isUploading&&jsxRuntime.jsx("div",{className:"chat-audio-upload-overlay lua:absolute lua:inset-0 lua:bg-black lua:bg-opacity-50 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("div",{className:"lua:text-white lua:text-sm",children:"Uploading..."})})]})})})}function Ee({url:t}){return jsxRuntime.jsxs(luaniverse.Button,{onClick:a=>{if(a.preventDefault(),/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)){window.open(t,"_blank","noopener,noreferrer");return}let r=500,s=600,d=window.screen.width/2-r/2,u=window.screen.height/2-s/2,n=window.open(t,"Payment",`width=${r},height=${s},left=${d},top=${u},toolbar=no,menubar=no,scrollbars=yes,resizable=yes`);(!n||n.closed||typeof n.closed>"u")&&window.open(t,"_blank","noopener,noreferrer");},className:"chat-payment-button lua:rounded-xl",children:[jsxRuntime.jsx(luaniverse.CreditCard,{size:16}),jsxRuntime.jsx("span",{children:"Open payment"})]})}var ja=t=>t.split(`
4
4
  `).filter(a=>a.trim()).filter(a=>a.trim().startsWith("-")).map(a=>({text:a.trim().substring(1).trim(),onClick:a.trim().substring(1).trim()})),Se=ja;var Wa=t=>{let e=/!\[(.*?)\]\((.*)\)/g,a=[],l;for(;(l=e.exec(t))!==null;)l[1]&&l[2]&&a.push({alt:l[1],src:l[2]});return a},Fe=Wa;var Xa=t=>{let e=/\[.*?\]\((.*?)\)/g,a=[],l;for(;(l=e.exec(t))!==null;)l[1]&&a.push(l[1]);return a},He=Xa;function Be(t){let e=t.match(/!\[([^\]]+)\]\(([^)]+)\)/);if(!e)return null;let[,a,l]=e;return {text:a,url:l}}var Ga=t=>{let e=/\[.*?\]\((.*?)\)/,a=t.match(e);return a?a[1]:null},Oe=Ga;var $e=t=>typeof t=="string"?t:Array.isArray(t)?t.map($e).join(""):typeof t=="object"&&t!==null&&"props"in t?$e(t.props.children):"",Pt=$e;function Ka(t){return t.replace(/([^\n]):::/g,`$1
@@ -12,7 +12,7 @@
12
12
  `:v?n+=m+`
13
13
  `:g?p+=m+`
14
14
  `:a+=m+`
15
- `;}return f?e.push({type:"list-item",content:l.trim(),isComplete:false}):o?e.push({type:"payment",content:r.trim(),isComplete:false}):i?e.push({type:"actions",content:s.trim(),isComplete:false}):h?e.push({type:"images",content:d.trim(),isComplete:false}):c?e.push({type:"links",content:u.trim(),isComplete:false}):v?e.push({type:"navigate",content:n.trim(),isComplete:false}):g?e.push({type:"documents",content:p.trim(),isComplete:false}):a.trim()&&e.push({type:"text",content:a.trim()}),e},At=Qa;function Me({images:t}){let[e,a]=react.useState(false),[l,r]=react.useState(0),s=react.useRef(null),[d,u]=react.useState(false),[n,p]=react.useState(0),[f,o]=react.useState(0),[i,h]=react.useState(0),c=react.useCallback(w=>{s.current&&(u(true),p(w.pageX-s.current.offsetLeft),o(s.current.scrollLeft),h(0),w.preventDefault());},[]),v=react.useCallback(w=>{if(!d||!s.current)return;w.preventDefault();let U=w.pageX-s.current.offsetLeft,B=(U-n)*2;s.current.scrollLeft=f-B,h(Math.abs(U-n));},[d,n,f]),g=react.useCallback(()=>{u(false);},[]),C=react.useCallback(()=>{u(false);},[]),x=react.useCallback((w,U)=>{if(i>5){U.preventDefault();return}r(w),a(true);},[i]);return jsxRuntime.jsxs("div",{"data-testid":"image-carousel-message",className:"chat-image-carousel-message lua:w-full",children:[jsxRuntime.jsx("div",{ref:s,className:"chat-image-carousel markdown-image-carousel",style:{cursor:d?"grabbing":"grab"},onMouseDown:c,onMouseMove:v,onMouseUp:g,onMouseLeave:C,onDragStart:w=>{w.preventDefault(),w.stopPropagation();},onDragOver:w=>{w.preventDefault(),w.stopPropagation();},children:t.map((w,U)=>jsxRuntime.jsx("div",{className:"chat-carousel-image-item markdown-image-item",onClick:B=>x(U,B),children:jsxRuntime.jsx("img",{src:w.src,alt:w.alt,draggable:false,style:{userSelect:"none"}})},w.src))}),jsxRuntime.jsx(yt,{images:t,initialIndex:l,open:e,onClose:()=>a(false)})]})}function ze({message:t}){let[e,a]=react.useState(false);return t.url?jsxRuntime.jsxs("div",{"data-testid":"image-message",className:"chat-image-message lua:flex lua:flex-col lua:w-3/5 lua:mx-4 lua:sm:mx-5",children:[jsxRuntime.jsxs("div",{className:"chat-image-container lua:relative",children:[jsxRuntime.jsx("img",{src:t.url,alt:t.content,className:"chat-image lua:rounded-lg lua:w-full lua:cursor-pointer",onClick:()=>a(true)}),t.isUploading&&jsxRuntime.jsx("div",{className:"chat-image-upload-overlay lua:absolute lua:inset-0 lua:bg-black lua:bg-opacity-50 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsxs("div",{className:"lua:text-white lua:text-sm",children:["Uploading..."," ",t.uploadProgress?Math.round(t.uploadProgress):0,"%"]})})]}),!t.isUploading&&t.content.length>0&&jsxRuntime.jsx("div",{className:"chat-image-caption lua:w-full lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content}),jsxRuntime.jsx(vt,{url:t.url,alt:t.content,open:e,onClose:()=>a(false)})]}):null}function _e({url:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){let[r,s]=react.useState(null),[d,u]=react.useState(true),[n,p]=react.useState(null);return react.useEffect(()=>{t&&e&&!l&&(async()=>{try{u(!0),p(null);let o=a;if(!o)throw new Error("No auth token available");let i=await fetch(`${e}/chat/url-metadata?url=${encodeURIComponent(t)}`,{headers:{Authorization:`Bearer ${o}`}});if(!i.ok)throw new Error(`Failed to fetch preview: ${i.status}`);let h=await i.json();s(h);}catch(o){console.error("Error fetching link preview:",o),p(o instanceof Error?o.message:"Failed to load preview");}finally{u(false);}})();},[t,e]),l?jsxRuntime.jsx("div",{className:"lua:mb-5 lua:mx-[-30px]",children:jsxRuntime.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:jsxRuntime.jsx(luaniverse.Button,{variant:"muted",children:t})})}):d?jsxRuntime.jsxs("div",{className:"lua:animate-pulse",children:[jsxRuntime.jsx("div",{className:"lua:bg-gray-300 lua:h-4 lua:w-3/4 lua:mb-2 lua:rounded"}),jsxRuntime.jsx("div",{className:"lua:bg-gray-300 lua:h-3 lua:w-1/2 lua:rounded"})]}):n||!r?jsxRuntime.jsx("div",{className:"lua:mb-5 lua:mx-[-30px]",children:jsxRuntime.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:jsxRuntime.jsx(luaniverse.Button,{variant:"muted",children:t})})}):jsxRuntime.jsxs("a",{href:r.url||t,target:"_blank",rel:"noopener noreferrer",className:"lua:block lua:border lua:border-gray-200 lua:rounded-lg lua:p-3 lua:hover:bg-gray-50 lua:transition-colors lua:no-underline lua:max-w-sm",children:[r.image&&jsxRuntime.jsx("img",{src:r.image,alt:r.title,className:"lua:w-full lua:h-32 lua:object-cover lua:rounded lua:mb-2",onError:f=>{f.currentTarget.style.display="none";}}),jsxRuntime.jsx("div",{className:"lua:text-sm lua:font-medium lua:text-gray-900 lua:mb-1 lua:line-clamp-2",children:r.title}),r.description&&jsxRuntime.jsx("div",{className:"lua:text-xs lua:text-gray-600 lua:line-clamp-2",children:r.description}),jsxRuntime.jsx("div",{className:"lua:text-xs lua:text-gray-400 lua:mt-1 lua:truncate",children:new URL(r.url||t).hostname})]})}function Te({links:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){return jsxRuntime.jsx("div",{"data-testid":"link-list-message",className:"chat-link-list-message lua:w-full",children:jsxRuntime.jsx("div",{className:"chat-links-container lua:space-y-2 lua:mx-4 lua:sm:mx-5",children:t.map(r=>jsxRuntime.jsx(_e,{url:r,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l},r))})})}function We({location:t}){let e=[t.latitude,t.longitude];return jsxRuntime.jsx("div",{className:"lua:w-full lua:h-48 lua:rounded-lg lua:overflow-hidden lua:border lua:border-gray-200",children:jsxRuntime.jsxs(reactLeaflet.MapContainer,{center:e,zoom:15,scrollWheelZoom:false,className:"lua:w-full lua:h-full",children:[jsxRuntime.jsx(reactLeaflet.TileLayer,{attribution:'\xA9 <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"}),jsxRuntime.jsx(reactLeaflet.Marker,{position:e,children:t.address&&jsxRuntime.jsx(reactLeaflet.Popup,{children:jsxRuntime.jsx("div",{children:t.address})})})]})})}function Xe({location:t}){return jsxRuntime.jsx("div",{className:"lua:w-full lua:h-full lua:bg-gray-200 lua:rounded-lg lua:flex lua:items-center lua:justify-center lua:flex-col",children:t.address&&jsxRuntime.jsx(We,{location:t})})}function Ge({location:t}){return jsxRuntime.jsx("div",{className:"lua:w-full lua:h-60 lua:rounded-lg","data-testid":"location-preview",children:jsxRuntime.jsx(Xe,{location:t})})}function Ke({message:t}){return jsxRuntime.jsx("div",{"data-testid":"location-message",className:"chat-location-message lua:flex lua:flex-col lua:w-11/12 sm:lua:w-3/5 lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:p-3 lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsxs("div",{className:"chat-location-preview-container location-preview-container lua:relative",children:[t.location&&jsxRuntime.jsx(Ge,{location:t.location}),t.isUploading&&jsxRuntime.jsx("div",{className:"chat-location-upload-overlay lua:absolute lua:inset-0 lua:bg-black lua:bg-opacity-50 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("div",{className:"lua:text-white lua:text-sm",children:"Sharing location..."})}),jsxRuntime.jsxs("div",{className:"chat-location-info lua:flex lua:items-center lua:gap-2 lua:mt-3",children:[jsxRuntime.jsx(luaniverse.MapPin,{fill:"black"}),jsxRuntime.jsx("div",{className:"lua:flex-1",children:jsxRuntime.jsx("div",{className:"lua:text-sm",children:t.content})})]})]})})}function Qe({url:t,onNavigate:e}){let[a,l]=react.useState(false);return react.useEffect(()=>{if(e&&!a){l(true);let r=we(t);e(r.pathname,{...r.queryParams&&{query:r.queryParams}});}},[a,e]),null}function Ye({message:t}){return jsxRuntime.jsxs("div",{"data-testid":"video-message",className:"chat-video-message lua:flex lua:flex-col lua:w-3/5 lua:mx-4 lua:sm:mx-5",children:[jsxRuntime.jsxs("div",{className:"chat-video-container lua:relative",children:[jsxRuntime.jsx("video",{src:t.url,controls:true,className:"chat-video lua:rounded-lg lua:w-full"}),t.isUploading&&jsxRuntime.jsx("div",{className:"chat-video-upload-overlay lua:absolute lua:inset-0 lua:bg-black lua:bg-opacity-50 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsxs("div",{className:"lua:text-white lua:text-sm",children:["Uploading..."," ",t.uploadProgress?Math.round(t.uploadProgress):0,"%"]})})]}),!t.isUploading&&t.content&&jsxRuntime.jsx("div",{className:"chat-video-caption lua:w-full lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content})]})}function cl(t){return new Date(t).toLocaleTimeString()}function dl(t){return {icon:()=>null}}var nn=react.memo(function({message:e,onSelect:a,luaApiUrl:l,authToken:r,disablePreviewOnLinks:s=false,onNavigate:d}){let u=react.useCallback(f=>{let o=f.match(/^#\s+(.+)$/m),i=f.match(/^##\s+(.+)$/m),h=o?o[1]:"",c=i?i[1]:"",v=`${h}. ${c}`;a&&a(v);},[a]),n=react.useCallback(f=>{if(!a)return;let o=Pt(f).trim();a(o);},[a]),p=react.useCallback(()=>{if(e.type==="location")return jsxRuntime.jsx(Ke,{message:e});if(e.mimeType?.startsWith("video"))return e.url?jsxRuntime.jsx(Ye,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mimeType?.startsWith("image"))return e.url?jsxRuntime.jsx(ze,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mimeType?.startsWith("audio"))return jsxRuntime.jsx(Lt,{message:e});if(e.type==="file"&&e.mimeType){let h=dl(new File([],"",{type:e.mimeType})).icon;return jsxRuntime.jsx("a",{"data-testid":"chat-file-message",href:e.url,target:"_blank",rel:"noopener noreferrer",className:"chat-file-message lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsxs("div",{className:"lua:flex lua:flex-col lua:gap-8",children:[jsxRuntime.jsxs("div",{className:"chat-file-card lua:flex lua:items-center lua:justify-start lua:p-3 lua:border lua:border-gray-200 lua:rounded-lg lua:bg-white lua:w-80",children:[jsxRuntime.jsx(h,{className:"lua:w-12 lua:h-12 lua:text-gray-500"}),jsxRuntime.jsxs("div",{className:"lua:flex lua:flex-col lua:gap-1 lua:pl-2",children:["File",jsxRuntime.jsx("span",{className:"lua:text-gray-500 lua:text-sm",children:e.mimeType})]})]}),e.content&&jsxRuntime.jsx("div",{className:"chat-file-content lua:bg-gray-100 lua:rounded-2xl lua:px-4 lua:py-2 lua:w-80",children:jsxRuntime.jsx("div",{className:"lua:text-sm lua:text-gray-900",children:e.content})})]})})}if(e.role==="user")return e.content;if(e.content==="...")return null;let f=At(e.content),o=be(n);return jsxRuntime.jsx("div",{className:"chat-markdown-content lua:prose lua:prose-sm lua:max-w-none",children:jsxRuntime.jsx("div",{className:"lua:flex lua:flex-wrap lua:gap-4",children:(()=>{if(f.filter(c=>c.type==="list-item").length>1){let c=[],v=[];return f.forEach(g=>{g.type==="list-item"?v.push(g):(v.length>0&&(c.push(v),v=[]),c.push([g]));}),v.length>0&&c.push(v),c.map((g,C)=>g.length>1&&g[0].type==="list-item"?jsxRuntime.jsx(kt,{group:g,onCardClick:u,onListItemClick:n,onNavigate:d},C):g.map((x,N)=>{if(x.type==="list-item")return jsxRuntime.jsx(re,{block:x,onCardClick:u,onListItemClick:n,onNavigate:d},N);if(x.type==="actions")return Se(x.content).length>0&&x.isComplete,null;if(x.type==="images"){let m=Fe(x.content);if(m.length>0)return jsxRuntime.jsx(Me,{images:m},N)}if(x.type==="links"){let m=He(x.content);return m.length>0&&x.isComplete?jsxRuntime.jsx(Te,{links:m,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:s},N):null}if(x.type==="navigate"){let m=Be(x.content);return m&&x.isComplete?jsxRuntime.jsx(Qe,{text:m.text,url:m.url,onNavigate:d},N):null}if(x.type==="documents"){let m=De(x.content);return jsxRuntime.jsx(Ne,{documents:m},N)}if(x.type==="payment"){let m=Oe(x.content);return m?jsxRuntime.jsx("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsx(Ee,{url:m})},N):null}return jsxRuntime.jsx("div",{className:"chat-markdown-block lua:w-full",children:jsxRuntime.jsx(St__default.default,{components:o,children:x.content})},N)}))}return f.map((c,v)=>{if(c.type==="list-item")return jsxRuntime.jsx(re,{block:c,onCardClick:u,onListItemClick:n,onNavigate:d},v);if(c.type==="actions")return Se(c.content).length>0&&c.isComplete,null;if(c.type==="images"){let g=Fe(c.content);if(g.length>0)return jsxRuntime.jsx(Me,{images:g},v)}if(c.type==="navigate"){let g=Be(c.content);return g&&c.isComplete?jsxRuntime.jsx(Qe,{text:g.text,url:g.url,onNavigate:d},v):null}if(c.type==="documents"){let g=De(c.content);return jsxRuntime.jsx(Ne,{documents:g},v)}if(c.type==="links"){let g=He(c.content);return g.length>0&&c.isComplete?jsxRuntime.jsx(Te,{links:g,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:s},v):null}if(c.type==="payment"){let g=Oe(c.content);return g?jsxRuntime.jsx("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5 lua:mb-5",children:jsxRuntime.jsx(Ee,{url:g})},v):null}return jsxRuntime.jsx("div",{className:"chat-markdown-block lua:w-full",children:jsxRuntime.jsx(St__default.default,{components:o,children:c.content})},v)})})()})})},[e,u,n]);return jsxRuntime.jsxs("div",{className:`chat-message-container lua:flex lua:flex-col ${e.role==="user"?"lua:items-end":"lua:items-start"} lua:gap-1`,children:[jsxRuntime.jsxs("div",{className:`lua:flex ${e.role==="user"?"lua:justify-end":"lua:justify-start"} lua:items-start lua:gap-2 lua:w-full`,children:[!["file","image","video","tool","location"].includes(e.type||"")&&e.content!=="..."&&jsxRuntime.jsx("div",{className:`chat-message-bubble ${e.role==="user"?"chat-message-bubble-user lua:max-w-full md:lua:max-w-3/5 lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:py-3 lua:mx-4 lua:sm:mx-5 lua:whitespace-pre-wrap":"chat-message-bubble-agent lua:w-full lua:bg-white lua:text-gray-800 lua:rounded-lg lua:py-3 lua:rounded-bl-none"}`,style:{wordBreak:"break-word"},children:p()}),["file","image","video","location"].includes(e.type||"")&&p()]}),jsxRuntime.jsx("div",{className:`lua-message-timestamp lua:text-xs lua:text-gray-400 lua:px-1 ${e.role==="user"?"lua:mr-4 sm:lua:mr-5":"lua:ml-4 sm:lua:ml-5"}`,children:cl(e.createdAt)})]})});var tt=react.createContext(void 0),at=react.createContext(void 0),lt=react.createContext(void 0),rt=react.createContext(void 0),ot=react.createContext(void 0);function mn({children:t}){let[e,a]=react.useState([]),[l,r]=react.useState(""),[s,d]=react.useState(null),[u,n]=react.useState(false),[p]=react.useState(new Map),f=react.useCallback(i=>{if(!p.has(i)){let h=URL.createObjectURL(i);p.set(i,h);}return p.get(i)},[p]),o=react.useCallback(i=>{let h=p.get(i);h&&(URL.revokeObjectURL(h),p.delete(i));},[p]);return react.useEffect(()=>()=>{e.forEach(i=>{i.url&&i.url.startsWith("blob:")&&URL.revokeObjectURL(i.url);}),p.forEach(i=>URL.revokeObjectURL(i));},[e,p]),jsxRuntime.jsx(tt.Provider,{value:{messages:e,setMessages:a},children:jsxRuntime.jsx(at.Provider,{value:{inputMessage:l,setInputMessage:r},children:jsxRuntime.jsx(lt.Provider,{value:{loadingMessage:s,setLoadingMessage:d},children:jsxRuntime.jsx(rt.Provider,{value:{hasUnreadMessages:u,setHasUnreadMessages:n},children:jsxRuntime.jsx(ot.Provider,{value:{getFileUrl:f,removeFileUrl:o},children:t})})})})})}function pn(){let t=react.useContext(tt);if(t===void 0)throw new Error("useMessages must be used within a ChatProvider");return t}function Ht(){let t=react.useContext(at);if(t===void 0)throw new Error("useInput must be used within a ChatProvider");return t}function gn(){let t=react.useContext(lt);if(t===void 0)throw new Error("useLoadingMessage must be used within a ChatProvider");return t}function fn(){let t=react.useContext(ot);if(t===void 0)throw new Error("useFileUrls must be used within a ChatProvider");return t}function hn(){let t=react.useContext(rt);if(t===void 0)throw new Error("useUnreadMessages must be used within a ChatProvider");return t}function $(){let t=react.useContext(tt),e=react.useContext(at),a=react.useContext(lt),l=react.useContext(rt),r=react.useContext(ot);if(t===void 0||e===void 0||a===void 0||l===void 0||r===void 0)throw new Error("useChat must be used within a ChatProvider");return {...t,...e,...a,...l,...r}}function wn(){let{loadingMessage:t}=$();return t?jsxRuntime.jsxs("div",{className:"chat-loading-message lua:flex lua:items-center lua:gap-2 lua:mx-4 lua:sm:mx-5",children:[jsxRuntime.jsx(luaniverse.Logo,{size:24,className:"chat-loading-logo lua:w-6 lua:h-6 lua:rounded-full lua:flex-shrink-0 lua:animate-spin",style:{animationDuration:"3s"}}),jsxRuntime.jsx("div",{className:"chat-loading-text lua:text-sm lua:opacity-40",children:t||"Lua is typing..."})]}):null}function Ot({buttons:t,onClick:e}){return jsxRuntime.jsx("div",{className:"chat-action-message lua:w-full",children:jsxRuntime.jsx("div",{className:"chat-action-buttons lua:flex lua:gap-2 lua:flex-wrap lua:mx-4 lua:sm:mx-5",children:t.map((a,l)=>jsxRuntime.jsx(luaniverse.Button,{variant:"tertiary",className:"chat-action-button lua:font-normal lua:rounded-lg lua:py-2 lua:h-auto",onClick:()=>e(a.text),children:a.text},l))})})}var $t=t=>{let e="::: actions",l=t.indexOf(e);if(l===-1)return [];let r=t.indexOf(":::",l+e.length);return r===-1?[]:t.slice(l+e.length,r).trim().replace(/\\n/g,`
15
+ `;}return f?e.push({type:"list-item",content:l.trim(),isComplete:false}):o?e.push({type:"payment",content:r.trim(),isComplete:false}):i?e.push({type:"actions",content:s.trim(),isComplete:false}):h?e.push({type:"images",content:d.trim(),isComplete:false}):c?e.push({type:"links",content:u.trim(),isComplete:false}):v?e.push({type:"navigate",content:n.trim(),isComplete:false}):g?e.push({type:"documents",content:p.trim(),isComplete:false}):a.trim()&&e.push({type:"text",content:a.trim()}),e},At=Qa;function Me({images:t}){let[e,a]=react.useState(false),[l,r]=react.useState(0),s=react.useRef(null),[d,u]=react.useState(false),[n,p]=react.useState(0),[f,o]=react.useState(0),[i,h]=react.useState(0),c=react.useCallback(w=>{s.current&&(u(true),p(w.pageX-s.current.offsetLeft),o(s.current.scrollLeft),h(0),w.preventDefault());},[]),v=react.useCallback(w=>{if(!d||!s.current)return;w.preventDefault();let U=w.pageX-s.current.offsetLeft,B=(U-n)*2;s.current.scrollLeft=f-B,h(Math.abs(U-n));},[d,n,f]),g=react.useCallback(()=>{u(false);},[]),C=react.useCallback(()=>{u(false);},[]),x=react.useCallback((w,U)=>{if(i>5){U.preventDefault();return}r(w),a(true);},[i]);return jsxRuntime.jsxs("div",{"data-testid":"image-carousel-message",className:"chat-image-carousel-message lua:w-full",children:[jsxRuntime.jsx("div",{ref:s,className:"chat-image-carousel markdown-image-carousel",style:{cursor:d?"grabbing":"grab"},onMouseDown:c,onMouseMove:v,onMouseUp:g,onMouseLeave:C,onDragStart:w=>{w.preventDefault(),w.stopPropagation();},onDragOver:w=>{w.preventDefault(),w.stopPropagation();},children:t.map((w,U)=>jsxRuntime.jsx("div",{className:"chat-carousel-image-item markdown-image-item",onClick:B=>x(U,B),children:jsxRuntime.jsx("img",{src:w.src,alt:w.alt,draggable:false,style:{userSelect:"none"}})},w.src))}),jsxRuntime.jsx(yt,{images:t,initialIndex:l,open:e,onClose:()=>a(false)})]})}function ze({message:t}){let[e,a]=react.useState(false);return t.url?jsxRuntime.jsxs("div",{"data-testid":"image-message",className:"chat-image-message lua:flex lua:flex-col lua:w-3/5 lua:mx-4 lua:sm:mx-5",children:[jsxRuntime.jsxs("div",{className:"chat-image-container lua:relative",children:[jsxRuntime.jsx("img",{src:t.url,alt:t.content,className:"chat-image lua:rounded-lg lua:w-full lua:cursor-pointer",onClick:()=>a(true)}),t.isUploading&&jsxRuntime.jsx("div",{className:"chat-image-upload-overlay lua:absolute lua:inset-0 lua:bg-black lua:bg-opacity-50 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsxs("div",{className:"lua:text-white lua:text-sm",children:["Uploading..."," ",t.uploadProgress?Math.round(t.uploadProgress):0,"%"]})})]}),!t.isUploading&&t.content.length>0&&jsxRuntime.jsx("div",{className:"chat-image-caption lua:w-full lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content}),jsxRuntime.jsx(vt,{url:t.url,alt:t.content,open:e,onClose:()=>a(false)})]}):null}function _e({url:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){let[r,s]=react.useState(null),[d,u]=react.useState(true),[n,p]=react.useState(null);return react.useEffect(()=>{t&&e&&!l&&(async()=>{try{u(!0),p(null);let o=a;if(!o)throw new Error("No auth token available");let i=await fetch(`${e}/chat/url-metadata?url=${encodeURIComponent(t)}`,{headers:{Authorization:`Bearer ${o}`}});if(!i.ok)throw new Error(`Failed to fetch preview: ${i.status}`);let h=await i.json();s(h);}catch(o){console.error("Error fetching link preview:",o),p(o instanceof Error?o.message:"Failed to load preview");}finally{u(false);}})();},[t,e]),l?jsxRuntime.jsx("div",{className:"lua:mb-5 lua:mx-[-30px]",children:jsxRuntime.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:jsxRuntime.jsx(luaniverse.Button,{variant:"muted",children:t})})}):d?jsxRuntime.jsxs("div",{className:"lua:animate-pulse",children:[jsxRuntime.jsx("div",{className:"lua:bg-gray-300 lua:h-4 lua:w-3/4 lua:mb-2 lua:rounded"}),jsxRuntime.jsx("div",{className:"lua:bg-gray-300 lua:h-3 lua:w-1/2 lua:rounded"})]}):n||!r?jsxRuntime.jsx("div",{className:"lua:mb-5 lua:mx-[-30px]",children:jsxRuntime.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:jsxRuntime.jsx(luaniverse.Button,{variant:"muted",children:t})})}):jsxRuntime.jsxs("a",{href:r.url||t,target:"_blank",rel:"noopener noreferrer",className:"lua:block lua:border lua:border-gray-200 lua:rounded-lg lua:p-3 lua:hover:bg-gray-50 lua:transition-colors lua:no-underline lua:max-w-sm",children:[r.image&&jsxRuntime.jsx("img",{src:r.image,alt:r.title,className:"lua:w-full lua:h-32 lua:object-cover lua:rounded lua:mb-2",onError:f=>{f.currentTarget.style.display="none";}}),jsxRuntime.jsx("div",{className:"lua:text-sm lua:font-medium lua:text-gray-900 lua:mb-1 lua:line-clamp-2",children:r.title}),r.description&&jsxRuntime.jsx("div",{className:"lua:text-xs lua:text-gray-600 lua:line-clamp-2",children:r.description}),jsxRuntime.jsx("div",{className:"lua:text-xs lua:text-gray-400 lua:mt-1 lua:truncate",children:new URL(r.url||t).hostname})]})}function Te({links:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){return jsxRuntime.jsx("div",{"data-testid":"link-list-message",className:"chat-link-list-message lua:w-full",children:jsxRuntime.jsx("div",{className:"chat-links-container lua:space-y-2 lua:mx-4 lua:sm:mx-5",children:t.map(r=>jsxRuntime.jsx(_e,{url:r,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l},r))})})}function We({location:t}){let e=[t.latitude,t.longitude];return jsxRuntime.jsx("div",{className:"lua:w-full lua:h-48 lua:rounded-lg lua:overflow-hidden lua:border lua:border-gray-200",children:jsxRuntime.jsxs(reactLeaflet.MapContainer,{center:e,zoom:15,scrollWheelZoom:false,className:"lua:w-full lua:h-full",children:[jsxRuntime.jsx(reactLeaflet.TileLayer,{attribution:'\xA9 <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"}),jsxRuntime.jsx(reactLeaflet.Marker,{position:e,children:t.address&&jsxRuntime.jsx(reactLeaflet.Popup,{children:jsxRuntime.jsx("div",{children:t.address})})})]})})}function Xe({location:t}){return jsxRuntime.jsx("div",{className:"lua:w-full lua:h-full lua:bg-gray-200 lua:rounded-lg lua:flex lua:items-center lua:justify-center lua:flex-col",children:t.address&&jsxRuntime.jsx(We,{location:t})})}function Ge({location:t}){return jsxRuntime.jsx("div",{className:"lua:w-full lua:h-60 lua:rounded-lg","data-testid":"location-preview",children:jsxRuntime.jsx(Xe,{location:t})})}function Ke({message:t}){return jsxRuntime.jsx("div",{"data-testid":"location-message",className:"chat-location-message lua:flex lua:flex-col lua:w-11/12 sm:lua:w-3/5 lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:p-3 lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsxs("div",{className:"chat-location-preview-container location-preview-container lua:relative",children:[t.location&&jsxRuntime.jsx(Ge,{location:t.location}),t.isUploading&&jsxRuntime.jsx("div",{className:"chat-location-upload-overlay lua:absolute lua:inset-0 lua:bg-black lua:bg-opacity-50 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("div",{className:"lua:text-white lua:text-sm",children:"Sharing location..."})}),jsxRuntime.jsxs("div",{className:"chat-location-info lua:flex lua:items-center lua:gap-2 lua:mt-3",children:[jsxRuntime.jsx(luaniverse.MapPin,{fill:"black"}),jsxRuntime.jsx("div",{className:"lua:flex-1",children:jsxRuntime.jsx("div",{className:"lua:text-sm",children:t.content})})]})]})})}function Qe({url:t,onNavigate:e}){let[a,l]=react.useState(false);return react.useEffect(()=>{if(e&&!a){l(true);let r=we(t);e(r.pathname,{...r.queryParams&&{query:r.queryParams}});}},[a,e]),null}function Ye({message:t}){return jsxRuntime.jsxs("div",{"data-testid":"video-message",className:"chat-video-message lua:flex lua:flex-col lua:w-3/5 lua:mx-4 lua:sm:mx-5",children:[jsxRuntime.jsxs("div",{className:"chat-video-container lua:relative",children:[jsxRuntime.jsx("video",{src:t.url,controls:true,className:"chat-video lua:rounded-lg lua:w-full"}),t.isUploading&&jsxRuntime.jsx("div",{className:"chat-video-upload-overlay lua:absolute lua:inset-0 lua:bg-black lua:bg-opacity-50 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsxs("div",{className:"lua:text-white lua:text-sm",children:["Uploading..."," ",t.uploadProgress?Math.round(t.uploadProgress):0,"%"]})})]}),!t.isUploading&&t.content&&jsxRuntime.jsx("div",{className:"chat-video-caption lua:w-full lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content})]})}function cl(t){return new Date(t).toLocaleTimeString()}function dl(t){return {icon:()=>null}}var nn=react.memo(function({message:e,onSelect:a,luaApiUrl:l,authToken:r,disablePreviewOnLinks:s=false,onNavigate:d}){let u=react.useCallback(f=>{let o=f.match(/^#\s+(.+)$/m),i=f.match(/^##\s+(.+)$/m),h=o?o[1]:"",c=i?i[1]:"",v=`${h}. ${c}`;a&&a(v);},[a]),n=react.useCallback(f=>{if(!a)return;let o=Pt(f).trim();a(o);},[a]),p=react.useCallback(()=>{if(e.type==="location")return jsxRuntime.jsx(Ke,{message:e});if(e.mimeType?.startsWith("video"))return e.url?jsxRuntime.jsx(Ye,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mimeType?.startsWith("image"))return e.url?jsxRuntime.jsx(ze,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mimeType?.startsWith("audio"))return jsxRuntime.jsx(Lt,{message:e});if(e.type==="file"&&e.mimeType){let h=dl(new File([],"",{type:e.mimeType})).icon;return jsxRuntime.jsx("a",{"data-testid":"chat-file-message",href:e.url,target:"_blank",rel:"noopener noreferrer",className:"chat-file-message lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsxs("div",{className:"lua:flex lua:flex-col lua:gap-8",children:[jsxRuntime.jsxs("div",{className:"chat-file-card lua:flex lua:items-center lua:justify-start lua:p-3 lua:border lua:border-gray-200 lua:rounded-lg lua:bg-white lua:w-80",children:[jsxRuntime.jsx(h,{className:"lua:w-12 lua:h-12 lua:text-gray-500"}),jsxRuntime.jsxs("div",{className:"lua:flex lua:flex-col lua:gap-1 lua:pl-2",children:["File",jsxRuntime.jsx("span",{className:"lua:text-gray-500 lua:text-sm",children:e.mimeType})]})]}),e.content&&jsxRuntime.jsx("div",{className:"chat-file-content lua:bg-gray-100 lua:rounded-2xl lua:px-4 lua:py-2 lua:w-80",children:jsxRuntime.jsx("div",{className:"lua:text-sm lua:text-gray-900",children:e.content})})]})})}if(e.role==="user")return e.content;if(e.content==="...")return null;let f=At(e.content),o=be(n);return jsxRuntime.jsx("div",{className:"chat-markdown-content lua:prose lua:prose-sm lua:max-w-none",children:jsxRuntime.jsx("div",{className:"lua:flex lua:flex-wrap lua:gap-4",children:(()=>{if(f.filter(c=>c.type==="list-item").length>1){let c=[],v=[];return f.forEach(g=>{g.type==="list-item"?v.push(g):(v.length>0&&(c.push(v),v=[]),c.push([g]));}),v.length>0&&c.push(v),c.map((g,C)=>g.length>1&&g[0].type==="list-item"?jsxRuntime.jsx(kt,{group:g,onCardClick:u,onListItemClick:n,onNavigate:d},C):g.map((x,N)=>{if(x.type==="list-item")return jsxRuntime.jsx(re,{block:x,onCardClick:u,onListItemClick:n,onNavigate:d},N);if(x.type==="actions")return Se(x.content).length>0&&x.isComplete,null;if(x.type==="images"){let m=Fe(x.content);if(m.length>0)return jsxRuntime.jsx(Me,{images:m},N)}if(x.type==="links"){let m=He(x.content);return m.length>0&&x.isComplete?jsxRuntime.jsx(Te,{links:m,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:s},N):null}if(x.type==="navigate"){let m=Be(x.content);return m&&x.isComplete?jsxRuntime.jsx(Qe,{text:m.text,url:m.url,onNavigate:d},N):null}if(x.type==="documents"){let m=De(x.content);return jsxRuntime.jsx(Ne,{documents:m},N)}if(x.type==="payment"){let m=Oe(x.content);return m?jsxRuntime.jsx("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsx(Ee,{url:m})},N):null}return jsxRuntime.jsx("div",{className:"chat-markdown-block lua:w-full",children:jsxRuntime.jsx(St__default.default,{components:o,children:x.content})},N)}))}return f.map((c,v)=>{if(c.type==="list-item")return jsxRuntime.jsx(re,{block:c,onCardClick:u,onListItemClick:n,onNavigate:d},v);if(c.type==="actions")return Se(c.content).length>0&&c.isComplete,null;if(c.type==="images"){let g=Fe(c.content);if(g.length>0)return jsxRuntime.jsx(Me,{images:g},v)}if(c.type==="navigate"){let g=Be(c.content);return g&&c.isComplete?jsxRuntime.jsx(Qe,{text:g.text,url:g.url,onNavigate:d},v):null}if(c.type==="documents"){let g=De(c.content);return jsxRuntime.jsx(Ne,{documents:g},v)}if(c.type==="links"){let g=He(c.content);return g.length>0&&c.isComplete?jsxRuntime.jsx(Te,{links:g,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:s},v):null}if(c.type==="payment"){let g=Oe(c.content);return g?jsxRuntime.jsx("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5 lua:mb-5",children:jsxRuntime.jsx(Ee,{url:g})},v):null}return jsxRuntime.jsx("div",{className:"chat-markdown-block lua:w-full",children:jsxRuntime.jsx(St__default.default,{components:o,children:c.content})},v)})})()})})},[e,u,n]);return jsxRuntime.jsxs("div",{className:`chat-message-container lua:flex lua:flex-col ${e.role==="user"?"lua:items-end":"lua:items-start"} lua:gap-1`,children:[jsxRuntime.jsxs("div",{className:`lua:flex ${e.role==="user"?"lua:justify-end":"lua:justify-start"} lua:items-start lua:gap-2 lua:w-full`,children:[!["file","image","video","tool","location"].includes(e.type||"")&&e.content!=="..."&&jsxRuntime.jsx("div",{className:`chat-message-bubble ${e.role==="user"?"chat-message-bubble-user lua:max-w-full md:lua:max-w-3/5 lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:py-3 lua:mx-4 lua:sm:mx-5 lua:whitespace-pre-wrap":"chat-message-bubble-agent lua:w-full lua:bg-white lua:text-gray-800 lua:rounded-lg lua:py-3 lua:rounded-bl-none"}`,style:{wordBreak:"break-word"},children:p()}),["file","image","video","location"].includes(e.type||"")&&p()]}),jsxRuntime.jsx("div",{className:`lua-message-timestamp lua:text-xs lua:text-gray-400 lua:px-1 ${e.role==="user"?"lua:mr-4 sm:lua:mr-5":"lua:ml-4 sm:lua:ml-5"}`,children:cl(e.createdAt)})]})});var tt=react.createContext(void 0),at=react.createContext(void 0),lt=react.createContext(void 0),rt=react.createContext(void 0),ot=react.createContext(void 0);function mn({children:t}){let[e,a]=react.useState([]),[l,r]=react.useState(""),[s,d]=react.useState(null),[u,n]=react.useState(false),[p]=react.useState(new Map),f=react.useCallback(i=>{if(!p.has(i)){let h=URL.createObjectURL(i);p.set(i,h);}return p.get(i)},[p]),o=react.useCallback(i=>{let h=p.get(i);h&&(URL.revokeObjectURL(h),p.delete(i));},[p]);return react.useEffect(()=>()=>{e.forEach(i=>{i.url&&i.url.startsWith("blob:")&&URL.revokeObjectURL(i.url);}),p.forEach(i=>URL.revokeObjectURL(i));},[e,p]),jsxRuntime.jsx(tt.Provider,{value:{messages:e,setMessages:a},children:jsxRuntime.jsx(at.Provider,{value:{inputMessage:l,setInputMessage:r},children:jsxRuntime.jsx(lt.Provider,{value:{loadingMessage:s,setLoadingMessage:d},children:jsxRuntime.jsx(rt.Provider,{value:{hasUnreadMessages:u,setHasUnreadMessages:n},children:jsxRuntime.jsx(ot.Provider,{value:{getFileUrl:f,removeFileUrl:o},children:t})})})})})}function pn(){let t=react.useContext(tt);if(t===void 0)throw new Error("useMessages must be used within a ChatProvider");return t}function Ht(){let t=react.useContext(at);if(t===void 0)throw new Error("useInput must be used within a ChatProvider");return t}function gn(){let t=react.useContext(lt);if(t===void 0)throw new Error("useLoadingMessage must be used within a ChatProvider");return t}function fn(){let t=react.useContext(ot);if(t===void 0)throw new Error("useFileUrls must be used within a ChatProvider");return t}function hn(){let t=react.useContext(rt);if(t===void 0)throw new Error("useUnreadMessages must be used within a ChatProvider");return t}function $(){let t=react.useContext(tt),e=react.useContext(at),a=react.useContext(lt),l=react.useContext(rt),r=react.useContext(ot);if(t===void 0||e===void 0||a===void 0||l===void 0||r===void 0)throw new Error("useChat must be used within a ChatProvider");return {...t,...e,...a,...l,...r}}function wn(){let{loadingMessage:t}=$();return t?jsxRuntime.jsxs("div",{className:"chat-loading-message lua:flex lua:items-center lua:gap-2 lua:mx-4 lua:sm:mx-5",children:[jsxRuntime.jsx(luaniverse.Logo,{size:24,className:"chat-loading-logo lua:w-6 lua:h-6 lua:rounded-full lua:flex-shrink-0 lua:animate-spin",style:{animationDuration:"3s"}}),jsxRuntime.jsx("div",{className:"chat-loading-text lua:text-sm lua:opacity-40",children:t||"Lua is typing..."})]}):null}function Ot({buttons:t,onClick:e}){return jsxRuntime.jsx("div",{className:"chat-action-message lua:w-full",children:jsxRuntime.jsx("div",{className:"chat-action-buttons lua:flex lua:gap-2 lua:flex-wrap lua:mx-4 lua:sm:mx-5",children:t.map((a,l)=>jsxRuntime.jsx(luaniverse.Button,{variant:"tertiary",className:"chat-action-button lua:font-normal lua:rounded-lg lua:py-2 lua:h-auto",onClick:()=>e(a.text),children:a.text},l))})})}var $t=t=>{let e="::: actions",a=":::",l=t.indexOf(e);if(l===-1)return [];let r=t.indexOf(a,l+e.length);return r===-1?[]:t.slice(l+e.length,r).trim().replace(/\\n/g,`
16
16
  `).split(`
17
17
  `).map(f=>f.trim()).filter(f=>f&&f.startsWith("-")).map(f=>({text:f.replace(/^-[\s]?/,"").trim(),onClick:f.replace(/^-[\s]?/,"").trim()}))};function In({onSelect:t}){let{messages:e}=$();if(e.length===0)return null;let a=e[e.length-1],l=$t(a.content);return l.length===0?null:jsxRuntime.jsx(Ot,{buttons:l,onClick:t})}var ei=react.memo(function({onSend:e,disabled:a=false,onFilePaste:l}){let{inputMessage:r,setInputMessage:s}=Ht(),[d,u]=react.useState(false),n=react.useRef(null);react.useEffect(()=>{let o=()=>{u(window.matchMedia("(max-width: 768px)").matches||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return o(),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o);}},[]),react.useEffect(()=>{let o=n.current;o&&(a||(o.style.height="auto",o.style.height=`${o.scrollHeight}px`));},[r]);let p=o=>{if(o.key==="Enter"){if(d||o.shiftKey||o.metaKey||o.ctrlKey)return;o.preventDefault(),e();}},f=react.useCallback(o=>{let{items:i}=o.clipboardData;if(!i||!l)return;let h=[];for(let c=0;c<i.length;c++){let v=i[c];if(v.kind==="file"){let g=v.getAsFile();g&&h.push(g);}}h.length>0&&(o.preventDefault(),l(h));},[l]);return jsxRuntime.jsxs("div",{className:"lua:flex lua:gap-3 lua:py-2 lua:px-3 lua:items-start",children:[jsxRuntime.jsx(luaniverse.Logo,{size:32,className:"lua:w-8 lua:h-8 lua:rounded-full lua:flex-shrink-0 lua:m-1"}),jsxRuntime.jsx("div",{className:"lua:flex-1 lua:flex",children:jsxRuntime.jsx("textarea",{ref:n,disabled:a,value:r,onChange:o=>s(o.target.value),onKeyDown:p,onPaste:f,placeholder:a?"This conversation's chat window has already been closed":"Reply to user",className:`lua:w-full lua:pl-0 lua:pr-4 lua:py-2 lua:resize-none lua:overflow-y-auto lua:border-none lua:focus:outline-none lua:focus:ring-0 lua:text-gray-700 lua:min-h-10 lua:max-h-48 lua:bg-white${a?" lua:cursor-not-allowed lua:h-14":""}`,rows:1})})]})});function Nl(){return localStorage.getItem("authToken")}async function Q(t,e,a){let l=Nl();if(!l)throw new Error("No auth token found");return new Promise((r,s)=>{let d=new XMLHttpRequest,u=new FormData;u.append("file",t),d.upload.addEventListener("progress",n=>{if(n.lengthComputable&&a){let p=n.loaded/n.total*100;a(p);}}),d.addEventListener("load",()=>{if(d.status>=200&&d.status<300)try{let n=JSON.parse(d.responseText);r(n);}catch{s(new Error("Failed to parse response"));}else s(new Error(`Failed to upload file: ${d.status}`));}),d.addEventListener("error",()=>{s(new Error("Network error occurred"));}),d.open("POST",`${e}/upload`),d.setRequestHeader("Authorization",`Bearer ${l}`),d.send(u);})}function Tl(t){let e=t.type,a="File";return e.startsWith("image/")?a="Image":e.startsWith("video/")?a="Video":e.startsWith("audio/")&&(a="Audio"),{icon:()=>null,label:a}}function ut({file:t,onRemove:e,cdnUrl:a,initialUrl:l,onUploadComplete:r}){let s=Tl(t),d=s.icon,[u,n]=react.useState(false),[p,f]=react.useState(0),[o,i]=react.useState(l||null),h=react.useRef(false);return react.useEffect(()=>{if(o||h.current)return;(async()=>{n(true),h.current=true;try{let{fileId:v}=await Q(t,a,C=>{f(C);}),g=`${a}/${v}`;i(g),n(!1),r&&r(t,g);}catch(v){console.error("Upload failed for file:",t.name,v),n(false),h.current=false;}})();},[t,a,r,o]),jsxRuntime.jsxs("div",{className:"lua:flex lua:items-center lua:gap-4 lua:p-3 lua:bg-white lua:border lua:border-gray-200 lua:rounded-lg",children:[jsxRuntime.jsx("div",{className:"lua:flex-shrink-0",children:u?jsxRuntime.jsxs("div",{className:"lua:w-8 lua:h-8 lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsxRuntime.jsx("div",{className:"lua:w-6 lua:h-6 lua:border-2 lua:border-t-blue-500 lua:border-r-transparent lua:border-b-transparent lua:border-l-transparent lua:rounded-full lua:animate-spin"}),jsxRuntime.jsxs("div",{className:"lua:mt-1 lua:text-xs lua:text-gray-600 lua:font-medium",children:[Math.round(p),"%"]})]}):jsxRuntime.jsx(d,{className:"lua:w-8 lua:h-8 lua:text-gray-600"})}),jsxRuntime.jsxs("div",{className:"lua:flex-grow lua:min-w-0",children:[jsxRuntime.jsx("p",{className:"lua:text-sm lua:font-medium lua:text-gray-900 lua:truncate",children:t.name}),jsxRuntime.jsx("p",{className:"lua:text-xs lua:text-gray-500",children:s.label})]}),jsxRuntime.jsx("button",{onClick:e,className:"lua:flex-shrink-0 lua:w-6 lua:h-6 lua:flex lua:items-center lua:justify-center lua:rounded-full lua:bg-black lua:text-white lua:hover:bg-gray-800 lua:transition-colors",children:jsxRuntime.jsx(luaniverse.XIcon,{className:"lua:w-4 lua:h-4"})})]})}function ct({file:t,onRemove:e,cdnUrl:a,initialUrl:l,onUploadComplete:r}){let{getFileUrl:s}=$(),[d,u]=react.useState(false),[n,p]=react.useState(0),[f,o]=react.useState(l||null),[i,h]=react.useState(false);react.useEffect(()=>{if(l||i)return;(async()=>{u(true),h(true);try{let{fileId:g}=await Q(t,a,x=>{p(x);}),C=`${a}/${g}`;o(C),u(!1),r&&r(t,C);}catch(g){console.error("Upload failed:",g),u(false);}})();},[t,l,a,i,r]);let c=f||(d?void 0:s(t));return jsxRuntime.jsxs("div",{className:"lua:relative lua:flex-shrink-0",children:[d?jsxRuntime.jsxs("div",{className:"lua:w-32 lua:h-32 lua:bg-gray-100 lua:rounded-lg lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsxRuntime.jsx("div",{className:"lua:w-8 lua:h-8 lua:border-2 lua:border-t-blue-500 lua:border-r-transparent lua:border-b-transparent lua:border-l-transparent lua:rounded-full lua:animate-spin"}),jsxRuntime.jsxs("div",{className:"lua:mt-2 lua:text-xs lua:text-gray-600 lua:font-medium",children:[Math.round(n),"%"]})]}):c?jsxRuntime.jsx("img",{"data-testid":"image-thumbnail",src:c,alt:t.name,className:"lua:w-32 lua:h-32 lua:object-cover lua:rounded-lg"}):jsxRuntime.jsx("div",{className:"lua:w-32 lua:h-32 lua:bg-gray-200 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("span",{className:"lua:text-gray-500",children:"No preview"})}),jsxRuntime.jsxs("div",{className:"lua:absolute lua:bottom-1 lua:left-1 lua:px-1.5 lua:py-0.5 lua:rounded lua:bg-black/50 lua:text-white lua:text-xs",children:[Math.floor(t.size/1024/1024),"MB"]}),jsxRuntime.jsx("button",{onClick:()=>e(),className:"lua:absolute lua:top-1 lua:right-1 lua:w-6 lua:h-6 lua:flex lua:items-center lua:justify-center lua:rounded-full lua:bg-black lua:text-white lua:hover:bg-gray-800 lua:transition-colors",children:jsxRuntime.jsx("span",{className:"lua:text-sm",children:"\xD7"})})]})}function dt({file:t,onRemove:e,cdnUrl:a,initialUrl:l,thumbnailUrl:r,onUploadComplete:s}){let{getFileUrl:d}=$(),[u,n]=react.useState(false),[p,f]=react.useState(0),[o,i]=react.useState(l||null),[h,c]=react.useState(false),[v,g]=react.useState(r||null);return react.useEffect(()=>{if(!r&&!v){let C=d(t),x=document.createElement("video");x.src=C;let N=()=>{try{x.currentTime=0,setTimeout(()=>{let m=document.createElement("canvas");m.width=x.videoWidth,m.height=x.videoHeight;let w=m.getContext("2d");if(!w){console.error("Could not get canvas context");return}w.drawImage(x,0,0);let U=m.toDataURL("image/jpeg",.8);g(U);},100);}catch(m){console.error("Error generating thumbnail:",m);}finally{URL.revokeObjectURL(C),x.removeEventListener("canplay",N);}};x.addEventListener("canplay",N),x.load();}},[t,r,v]),react.useEffect(()=>{if(l||h)return;(async()=>{n(true),c(true);try{let{fileId:x}=await Q(t,a,m=>{f(m);}),N=`${a}/${x}`;i(N),n(!1),s&&s(t,N);}catch(x){console.error("Upload failed:",x),n(false);}})();},[t,l,a,h,s]),jsxRuntime.jsxs("div",{className:"lua:relative lua:flex-shrink-0",children:[u?jsxRuntime.jsxs("div",{className:"lua:w-32 lua:h-32 lua:bg-gray-100 lua:rounded-lg lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsxRuntime.jsx("div",{className:"lua:w-8 lua:h-8 lua:border-2 lua:border-t-blue-500 lua:border-r-transparent lua:border-b-transparent lua:border-l-transparent lua:rounded-full lua:animate-spin"}),jsxRuntime.jsxs("div",{className:"lua:mt-2 lua:text-xs lua:text-gray-600 lua:font-medium",children:[Math.round(p),"%"]})]}):jsxRuntime.jsxs("div",{className:"lua:relative",children:[jsxRuntime.jsx("img",{"data-testid":"video-thumbnail",src:v||o||"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",alt:t.name,className:"lua:w-32 lua:h-32 lua:object-cover lua:rounded-lg lua:bg-gray-100"}),jsxRuntime.jsx("div",{className:"lua:absolute lua:inset-0 lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("div",{className:"lua:w-10 lua:h-10 lua:rounded-full lua:bg-black/50 lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsxRuntime.jsx("path",{d:"M5 3L19 12L5 21V3Z",fill:"white"})})})})]}),jsxRuntime.jsxs("div",{className:"lua:absolute lua:bottom-1 lua:left-1 lua:px-1.5 lua:py-0.5 lua:rounded lua:bg-black/50 lua:text-white lua:text-xs",children:[Math.floor(t.size/1024/1024),"MB"]}),jsxRuntime.jsx("button",{onClick:()=>e(),className:"lua:absolute lua:top-1 lua:right-1 lua:w-6 lua:h-6 lua:flex lua:items-center lua:justify-center lua:rounded-full lua:bg-black lua:text-white lua:hover:bg-gray-800 lua:transition-colors",children:jsxRuntime.jsx("span",{className:"lua:text-sm",children:"\xD7"})})]})}function qt(t){let e=t.type,a="other",l="File";return e.startsWith("image/")?(a="image",l="Image"):e.startsWith("video/")?(a="video",l="Video"):e.startsWith("audio/")&&(a="audio",l="Audio"),{category:a,icon:()=>null,label:l}}function Ni({files:t,onRemove:e,cdnUrl:a,fileMetadata:l=[],onFileUploadComplete:r}){let[s,d]=react.useState({});return react.useEffect(()=>{t.forEach((u,n)=>{let p=qt(u),f=l.find(o=>o.file===u);if(p.category==="video"&&!s[n]&&!f){let o=URL.createObjectURL(u),i=document.createElement("video");i.src=o;let h=()=>{try{i.currentTime=0,setTimeout(()=>{let c=document.createElement("canvas");c.width=i.videoWidth,c.height=i.videoHeight;let v=c.getContext("2d");if(!v){console.error("Could not get canvas context");return}v.drawImage(i,0,0);let g=c.toDataURL("image/jpeg",.8);d(C=>({...C,[n]:g}));},100);}catch(c){console.error("Error generating thumbnail:",c);}finally{URL.revokeObjectURL(o),i.removeEventListener("canplay",h);}};i.addEventListener("canplay",h),i.load();}});},[t,l]),t.length===0?null:jsxRuntime.jsx("div",{className:"lua:px-4 lua:py-2 lua:border-b lua:border-gray-200",children:jsxRuntime.jsx("div",{className:"lua:flex lua:gap-2 lua:overflow-x-auto scrollbar-hide",children:t.map((u,n)=>{let p=qt(u),f=l.find(o=>o.file===u);return t.length>1?jsxRuntime.jsx("div",{className:"lua:flex-shrink-0 lua:w-64",children:jsxRuntime.jsx(ut,{file:u,onRemove:()=>e(n),cdnUrl:a,onUploadComplete:(o,i)=>{r&&r(o,i);}})},n):p.category==="image"?jsxRuntime.jsx(ct,{file:u,onRemove:()=>e(n),cdnUrl:a,initialUrl:f?.url,onUploadComplete:(o,i)=>{r&&r(o,i);}},u.name):p.category==="video"?jsxRuntime.jsx(dt,{file:u,onRemove:()=>e(n),cdnUrl:a,initialUrl:f?.url,thumbnailUrl:s[n],onUploadComplete:(o,i)=>{r&&r(o,i);}},u.name):jsxRuntime.jsx("div",{className:"lua:flex-shrink-0 lua:w-64",children:jsxRuntime.jsx(ut,{file:u,onRemove:()=>e(n),cdnUrl:a,onUploadComplete:(o,i)=>{r&&r(o,i);}})},n)})})})}var Y={CHAT:{TOOLBAR_ACTION:{FILE_UPLOAD:"file_upload",CAMERA:"camera",VIDEO:"video",AUDIO:"audio",LOCATION:"location"},MESSAGE_SENT:"message_sent"}};function ee(t){console.log("Analytics event:",t);}function Ti({loading:t,onFileClick:e,onCameraClick:a,onVideoClick:l,onAudioClick:r,onLocationClick:s,onSendClick:d}){return jsxRuntime.jsxs("div",{className:"lua:flex lua:items-center lua:justify-between lua:border-t lua:border-gray-200 lua:bg-gray-50 lua:px-3 lua:py-2",children:[jsxRuntime.jsxs("div",{className:"lua:flex lua:items-center lua:gap-2",children:[jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.FILE_UPLOAD),e();},disabled:t,"data-testid":"file-upload-button",children:jsxRuntime.jsx(luaniverse.Paperclip,{color:"#00000099"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Attach files"})]})]}),jsxRuntime.jsx("div",{className:"lua:w-px lua:h-5 lua:bg-gray-200"}),jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.CAMERA),a();},disabled:t,"data-testid":"camera-button",children:jsxRuntime.jsx(luaniverse.Camera,{color:"#00000099"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Take a picture"})]})]}),jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.VIDEO),l();},disabled:t,"data-testid":"video-button",children:jsxRuntime.jsx(luaniverse.VideoCamera,{color:"#00000099"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Record video"})]})]}),jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.AUDIO),r();},disabled:t,"data-testid":"audio-button",children:jsxRuntime.jsx(luaniverse.Microphone,{color:"#00000099"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Record voice message"})]})]}),jsxRuntime.jsx("div",{className:"lua:w-px lua:h-5 lua:bg-gray-200"}),jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.LOCATION),s();},disabled:t,"data-testid":"location-button",children:jsxRuntime.jsx(luaniverse.MapPin,{color:"#00000099"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Share location"})]})]})]}),jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-full",onClick:()=>{ee(Y.CHAT.MESSAGE_SENT),d();},disabled:t,"data-testid":"send-button",children:jsxRuntime.jsx(luaniverse.ArrowUp,{color:"#FFFFFF"})})]})}
18
18
  exports.ActionMessage=Ot;exports.AudioPreview=Lt;exports.AudioRecorder=$l;exports.CameraDialog=ir;exports.CarouselImageDialog=yt;exports.ChatActions=In;exports.ChatInput=ei;exports.ChatMessage=nn;exports.ChatProvider=mn;exports.CodeBlock=Ct;exports.FilePreview=Ni;exports.FilePreviewCard=ut;exports.ImageDialog=vt;exports.LoadingMessage=wn;exports.LocationDialog=cr;exports.PaymentPreview=Ee;exports.Toolbar=Ti;exports.VideoDialog=Xl;exports.markdownStyles=L;exports.parseActions=$t;exports.uploadFile=Q;exports.useChat=$;exports.useFileUrls=fn;exports.useInput=Ht;exports.useLoadingMessage=gn;exports.useMessages=pn;exports.useUnreadMessages=hn;//# sourceMappingURL=index.js.map