shopify-chatbot-widget 0.8.0 → 0.8.3
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.
|
@@ -649,7 +649,7 @@ html body {
|
|
|
649
649
|
<div class="cursor" part="cursor"></div>
|
|
650
650
|
</div>
|
|
651
651
|
</div>
|
|
652
|
-
`,[t,a]}setOptions(t){if(this.options.container!==t.container){const a=this.parentFromOptionsContainer(t.container);a.appendChild(this.container),this.parent=a}t.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||this.initDrag(),this.options=t,this.reRender()}getWrapper(){return this.wrapper}getWidth(){return this.scrollContainer.clientWidth}getScroll(){return this.scrollContainer.scrollLeft}setScroll(t){this.scrollContainer.scrollLeft=t}setScrollPercentage(t){const{scrollWidth:a}=this.scrollContainer,r=a*t;this.setScroll(r)}destroy(){var t,a;this.subscriptions.forEach(r=>r()),this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(a=this.unsubscribeOnScroll)===null||a===void 0||a.forEach(r=>r()),this.unsubscribeOnScroll=[]}createDelay(t=10){let a,r;const o=()=>{a&&clearTimeout(a),r&&r()};return this.timeouts.push(o),()=>new Promise((c,f)=>{o(),r=f,a=setTimeout(()=>{a=void 0,r=void 0,c()},t)})}convertColorValues(t){if(!Array.isArray(t))return t||"";if(t.length<2)return t[0]||"";const a=document.createElement("canvas"),r=a.getContext("2d"),o=a.height*(window.devicePixelRatio||1),c=r.createLinearGradient(0,0,0,o),f=1/(t.length-1);return t.forEach((m,g)=>{const p=g*f;c.addColorStop(p,m)}),c}getPixelRatio(){return Math.max(1,window.devicePixelRatio||1)}renderBarWaveform(t,a,r,o){const c=t[0],f=t[1]||t[0],m=c.length,{width:g,height:p}=r.canvas,y=p/2,S=this.getPixelRatio(),E=a.barWidth?a.barWidth*S:1,T=a.barGap?a.barGap*S:a.barWidth?E/2:0,O=a.barRadius||0,M=g/(E+T)/m,A=O&&"roundRect"in r?"roundRect":"rect";r.beginPath();let D=0,_=0,j=0;for(let L=0;L<=m;L++){const N=Math.round(L*M);if(N>D){const z=Math.round(_*y*o),U=z+Math.round(j*y*o)||1;let H=y-z;a.barAlign==="top"?H=0:a.barAlign==="bottom"&&(H=p-U),r[A](D*(E+T),H,E,U,O),D=N,_=0,j=0}const V=Math.abs(c[L]||0),B=Math.abs(f[L]||0);V>_&&(_=V),B>j&&(j=B)}r.fill(),r.closePath()}renderLineWaveform(t,a,r,o){const c=f=>{const m=t[f]||t[0],g=m.length,{height:p}=r.canvas,y=p/2,S=r.canvas.width/g;r.moveTo(0,y);let E=0,T=0;for(let O=0;O<=g;O++){const M=Math.round(O*S);if(M>E){const D=y+(Math.round(T*y*o)||1)*(f===0?-1:1);r.lineTo(E,D),E=M,T=0}const A=Math.abs(m[O]||0);A>T&&(T=A)}r.lineTo(E,y)};r.beginPath(),c(0),c(1),r.fill(),r.closePath()}renderWaveform(t,a,r){if(r.fillStyle=this.convertColorValues(a.waveColor),a.renderFunction)return void a.renderFunction(t,r);let o=a.barHeight||1;if(a.normalize){const c=Array.from(t[0]).reduce((f,m)=>Math.max(f,Math.abs(m)),0);o=c?1/c:1}a.barWidth||a.barGap||a.barAlign?this.renderBarWaveform(t,a,r,o):this.renderLineWaveform(t,a,r,o)}renderSingleCanvas(t,a,r,o,c,f,m){const g=this.getPixelRatio(),p=document.createElement("canvas");p.width=Math.round(r*g),p.height=Math.round(o*g),p.style.width=`${r}px`,p.style.height=`${o}px`,p.style.left=`${Math.round(c)}px`,f.appendChild(p);const y=p.getContext("2d");if(this.renderWaveform(t,a,y),p.width>0&&p.height>0){const S=p.cloneNode(),E=S.getContext("2d");E.drawImage(p,0,0),E.globalCompositeOperation="source-in",E.fillStyle=this.convertColorValues(a.progressColor),E.fillRect(0,0,p.width,p.height),m.appendChild(S)}}renderMultiCanvas(t,a,r,o,c,f){const m=this.getPixelRatio(),{clientWidth:g}=this.scrollContainer,p=r/m;let y=Math.min(lp.MAX_CANVAS_WIDTH,g,p),S={};if(a.barWidth||a.barGap){const A=a.barWidth||.5,D=A+(a.barGap||A/2);y%D!=0&&(y=Math.floor(y/D)*D)}if(y===0)return;const E=A=>{if(A<0||A>=T||S[A])return;S[A]=!0;const D=A*y;let _=Math.min(p-D,y);if(a.barWidth||a.barGap){const L=a.barWidth||.5,N=L+(a.barGap||L/2);_=Math.floor(_/N)*N}if(_<=0)return;const j=t.map(L=>{const N=Math.floor(D/p*L.length),V=Math.floor((D+_)/p*L.length);return L.slice(N,V)});this.renderSingleCanvas(j,a,_,o,D,c,f)},T=Math.ceil(p/y);if(!this.isScrollable){for(let A=0;A<T;A++)E(A);return}const O=this.scrollContainer.scrollLeft/p,M=Math.floor(O*T);if(E(M-1),E(M),E(M+1),T>1){const A=this.on("scroll",()=>{const{scrollLeft:D}=this.scrollContainer,_=Math.floor(D/p*T);Object.keys(S).length>lp.MAX_NODES&&(c.innerHTML="",f.innerHTML="",S={}),E(_-1),E(_),E(_+1)});this.unsubscribeOnScroll.push(A)}}renderChannel(t,a,r,o){var{overlay:c}=a,f=function(y,S){var E={};for(var T in y)Object.prototype.hasOwnProperty.call(y,T)&&S.indexOf(T)<0&&(E[T]=y[T]);if(y!=null&&typeof Object.getOwnPropertySymbols=="function"){var O=0;for(T=Object.getOwnPropertySymbols(y);O<T.length;O++)S.indexOf(T[O])<0&&Object.prototype.propertyIsEnumerable.call(y,T[O])&&(E[T[O]]=y[T[O]])}return E}(a,["overlay"]);const m=document.createElement("div"),g=this.getHeight(f.height,f.splitChannels);m.style.height=`${g}px`,c&&o>0&&(m.style.marginTop=`-${g}px`),this.canvasWrapper.style.minHeight=`${g}px`,this.canvasWrapper.appendChild(m);const p=m.cloneNode();this.progressWrapper.appendChild(p),this.renderMultiCanvas(t,f,r,g,m,p)}render(t){return li(this,void 0,void 0,function*(){var a;this.timeouts.forEach(g=>g()),this.timeouts=[],this.canvasWrapper.innerHTML="",this.progressWrapper.innerHTML="",this.options.width!=null&&(this.scrollContainer.style.width=typeof this.options.width=="number"?`${this.options.width}px`:this.options.width);const r=this.getPixelRatio(),o=this.scrollContainer.clientWidth,c=Math.ceil(t.duration*(this.options.minPxPerSec||0));this.isScrollable=c>o;const f=this.options.fillParent&&!this.isScrollable,m=(f?o:c)*r;if(this.wrapper.style.width=f?"100%":`${c}px`,this.scrollContainer.style.overflowX=this.isScrollable?"auto":"hidden",this.scrollContainer.classList.toggle("noScrollbar",!!this.options.hideScrollbar),this.cursor.style.backgroundColor=`${this.options.cursorColor||this.options.progressColor}`,this.cursor.style.width=`${this.options.cursorWidth}px`,this.audioData=t,this.emit("render"),this.options.splitChannels)for(let g=0;g<t.numberOfChannels;g++){const p=Object.assign(Object.assign({},this.options),(a=this.options.splitChannels)===null||a===void 0?void 0:a[g]);this.renderChannel([t.getChannelData(g)],p,m,g)}else{const g=[t.getChannelData(0)];t.numberOfChannels>1&&g.push(t.getChannelData(1)),this.renderChannel(g,this.options,m,0)}Promise.resolve().then(()=>this.emit("rendered"))})}reRender(){if(this.unsubscribeOnScroll.forEach(r=>r()),this.unsubscribeOnScroll=[],!this.audioData)return;const{scrollWidth:t}=this.scrollContainer,{right:a}=this.progressWrapper.getBoundingClientRect();if(this.render(this.audioData),this.isScrollable&&t!==this.scrollContainer.scrollWidth){const{right:r}=this.progressWrapper.getBoundingClientRect();let o=r-a;o*=2,o=o<0?Math.floor(o):Math.ceil(o),o/=2,this.scrollContainer.scrollLeft+=o}}zoom(t){this.options.minPxPerSec=t,this.reRender()}scrollIntoView(t,a=!1){const{scrollLeft:r,scrollWidth:o,clientWidth:c}=this.scrollContainer,f=t*o,m=r,g=r+c,p=c/2;if(this.isDragging)f+30>g?this.scrollContainer.scrollLeft+=30:f-30<m&&(this.scrollContainer.scrollLeft-=30);else{(f<m||f>g)&&(this.scrollContainer.scrollLeft=f-(this.options.autoCenter?p:0));const y=f-r-p;a&&this.options.autoCenter&&y>0&&(this.scrollContainer.scrollLeft+=Math.min(y,10))}{const y=this.scrollContainer.scrollLeft,S=y/o,E=(y+c)/o;this.emit("scroll",S,E,y,y+c)}}renderProgress(t,a){if(isNaN(t))return;const r=100*t;this.canvasWrapper.style.clipPath=`polygon(${r}% 0%, 100% 0%, 100% 100%, ${r}% 100%)`,this.progressWrapper.style.width=`${r}%`,this.cursor.style.left=`${r}%`,this.cursor.style.transform=`translateX(-${Math.round(r)===100?this.options.cursorWidth:0}px)`,this.isScrollable&&this.options.autoScroll&&this.scrollIntoView(t,a)}exportImage(t,a,r){return li(this,void 0,void 0,function*(){const o=this.canvasWrapper.querySelectorAll("canvas");if(!o.length)throw new Error("No waveform data");if(r==="dataURL"){const c=Array.from(o).map(f=>f.toDataURL(t,a));return Promise.resolve(c)}return Promise.all(Array.from(o).map(c=>new Promise((f,m)=>{c.toBlob(g=>{g?f(g):m(new Error("Could not export image"))},t,a)})))})}}lp.MAX_CANVAS_WIDTH=8e3,lp.MAX_NODES=10;class Vte extends L0{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",()=>{requestAnimationFrame(()=>{this.emit("tick")})}),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}class VR extends L0{constructor(t=new AudioContext){super(),this.bufferNode=null,this.playStartTime=0,this.playedDuration=0,this._muted=!1,this._playbackRate=1,this._duration=void 0,this.buffer=null,this.currentSrc="",this.paused=!0,this.crossOrigin=null,this.seeking=!1,this.autoplay=!1,this.addEventListener=this.on,this.removeEventListener=this.un,this.audioContext=t,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}load(){return li(this,void 0,void 0,function*(){})}get src(){return this.currentSrc}set src(t){if(this.currentSrc=t,this._duration=void 0,!t)return this.buffer=null,void this.emit("emptied");fetch(t).then(a=>{if(a.status>=400)throw new Error(`Failed to fetch ${t}: ${a.status} (${a.statusText})`);return a.arrayBuffer()}).then(a=>this.currentSrc!==t?null:this.audioContext.decodeAudioData(a)).then(a=>{this.currentSrc===t&&(this.buffer=a,this.emit("loadedmetadata"),this.emit("canplay"),this.autoplay&&this.play())})}_play(){var t;if(!this.paused)return;this.paused=!1,(t=this.bufferNode)===null||t===void 0||t.disconnect(),this.bufferNode=this.audioContext.createBufferSource(),this.buffer&&(this.bufferNode.buffer=this.buffer),this.bufferNode.playbackRate.value=this._playbackRate,this.bufferNode.connect(this.gainNode);let a=this.playedDuration*this._playbackRate;(a>=this.duration||a<0)&&(a=0,this.playedDuration=0),this.bufferNode.start(this.audioContext.currentTime,a),this.playStartTime=this.audioContext.currentTime,this.bufferNode.onended=()=>{this.currentTime>=this.duration&&(this.pause(),this.emit("ended"))}}_pause(){var t;this.paused=!0,(t=this.bufferNode)===null||t===void 0||t.stop(),this.playedDuration+=this.audioContext.currentTime-this.playStartTime}play(){return li(this,void 0,void 0,function*(){this.paused&&(this._play(),this.emit("play"))})}pause(){this.paused||(this._pause(),this.emit("pause"))}stopAt(t){const a=t-this.currentTime,r=this.bufferNode;r?.stop(this.audioContext.currentTime+a),r?.addEventListener("ended",()=>{r===this.bufferNode&&(this.bufferNode=null,this.pause())},{once:!0})}setSinkId(t){return li(this,void 0,void 0,function*(){return this.audioContext.setSinkId(t)})}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t,this.bufferNode&&(this.bufferNode.playbackRate.value=t)}get currentTime(){return(this.paused?this.playedDuration:this.playedDuration+(this.audioContext.currentTime-this.playStartTime))*this._playbackRate}set currentTime(t){const a=!this.paused;a&&this._pause(),this.playedDuration=t/this._playbackRate,a&&this._play(),this.emit("seeking"),this.emit("timeupdate")}get duration(){var t,a;return(t=this._duration)!==null&&t!==void 0?t:((a=this.buffer)===null||a===void 0?void 0:a.duration)||0}set duration(t){this._duration=t}get volume(){return this.gainNode.gain.value}set volume(t){this.gainNode.gain.value=t,this.emit("volumechange")}get muted(){return this._muted}set muted(t){this._muted!==t&&(this._muted=t,this._muted?this.gainNode.disconnect():this.gainNode.connect(this.audioContext.destination))}canPlayType(t){return/^(audio|video)\//.test(t)}getGainNode(){return this.gainNode}getChannelData(){const t=[];if(!this.buffer)return t;const a=this.buffer.numberOfChannels;for(let r=0;r<a;r++)t.push(this.buffer.getChannelData(r));return t}}const Hte={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3};class sp extends Lte{static create(t){return new sp(t)}constructor(t){const a=t.media||(t.backend==="WebAudio"?new VR:void 0);super({media:a,mediaControls:t.mediaControls,autoplay:t.autoplay,playbackRate:t.audioRate}),this.plugins=[],this.decodedData=null,this.stopAtPosition=null,this.subscriptions=[],this.mediaSubscriptions=[],this.abortController=null,this.options=Object.assign({},Hte,t),this.timer=new Vte;const r=a?void 0:this.getMediaElement();this.renderer=new lp(this.options,r),this.initPlayerEvents(),this.initRendererEvents(),this.initTimerEvents(),this.initPlugins();const o=this.options.url||this.getSrc()||"";Promise.resolve().then(()=>{this.emit("init");const{peaks:c,duration:f}=this.options;(o||c&&f)&&this.load(o,c,f).catch(()=>null)})}updateProgress(t=this.getCurrentTime()){return this.renderer.renderProgress(t/this.getDuration(),this.isPlaying()),t}initTimerEvents(){this.subscriptions.push(this.timer.on("tick",()=>{if(!this.isSeeking()){const t=this.updateProgress();this.emit("timeupdate",t),this.emit("audioprocess",t),this.stopAtPosition!=null&&this.isPlaying()&&t>=this.stopAtPosition&&this.pause()}}))}initPlayerEvents(){this.isPlaying()&&(this.emit("play"),this.timer.start()),this.mediaSubscriptions.push(this.onMediaEvent("timeupdate",()=>{const t=this.updateProgress();this.emit("timeupdate",t)}),this.onMediaEvent("play",()=>{this.emit("play"),this.timer.start()}),this.onMediaEvent("pause",()=>{this.emit("pause"),this.timer.stop(),this.stopAtPosition=null}),this.onMediaEvent("emptied",()=>{this.timer.stop(),this.stopAtPosition=null}),this.onMediaEvent("ended",()=>{this.emit("timeupdate",this.getDuration()),this.emit("finish"),this.stopAtPosition=null}),this.onMediaEvent("seeking",()=>{this.emit("seeking",this.getCurrentTime())}),this.onMediaEvent("error",()=>{var t;this.emit("error",(t=this.getMediaElement().error)!==null&&t!==void 0?t:new Error("Media error")),this.stopAtPosition=null}))}initRendererEvents(){this.subscriptions.push(this.renderer.on("click",(t,a)=>{this.options.interact&&(this.seekTo(t),this.emit("interaction",t*this.getDuration()),this.emit("click",t,a))}),this.renderer.on("dblclick",(t,a)=>{this.emit("dblclick",t,a)}),this.renderer.on("scroll",(t,a,r,o)=>{const c=this.getDuration();this.emit("scroll",t*c,a*c,r,o)}),this.renderer.on("render",()=>{this.emit("redraw")}),this.renderer.on("rendered",()=>{this.emit("redrawcomplete")}),this.renderer.on("dragstart",t=>{this.emit("dragstart",t)}),this.renderer.on("dragend",t=>{this.emit("dragend",t)}));{let t;this.subscriptions.push(this.renderer.on("drag",a=>{if(!this.options.interact)return;let r;this.renderer.renderProgress(a),clearTimeout(t),this.isPlaying()?r=0:this.options.dragToSeek===!0?r=200:typeof this.options.dragToSeek=="object"&&this.options.dragToSeek!==void 0&&(r=this.options.dragToSeek.debounceTime),t=setTimeout(()=>{this.seekTo(a)},r),this.emit("interaction",a*this.getDuration()),this.emit("drag",a)}))}}initPlugins(){var t;!((t=this.options.plugins)===null||t===void 0)&&t.length&&this.options.plugins.forEach(a=>{this.registerPlugin(a)})}unsubscribePlayerEvents(){this.mediaSubscriptions.forEach(t=>t()),this.mediaSubscriptions=[]}setOptions(t){this.options=Object.assign({},this.options,t),t.duration&&!t.peaks&&(this.decodedData=yx.createBuffer(this.exportPeaks(),t.duration)),t.peaks&&t.duration&&(this.decodedData=yx.createBuffer(t.peaks,t.duration)),this.renderer.setOptions(this.options),t.audioRate&&this.setPlaybackRate(t.audioRate),t.mediaControls!=null&&(this.getMediaElement().controls=t.mediaControls)}registerPlugin(t){t._init(this),this.plugins.push(t);const a=t.once("destroy",()=>{this.plugins=this.plugins.filter(r=>r!==t),this.subscriptions=this.subscriptions.filter(r=>r!==a)});return this.subscriptions.push(a),t}getWrapper(){return this.renderer.getWrapper()}getWidth(){return this.renderer.getWidth()}getScroll(){return this.renderer.getScroll()}setScroll(t){return this.renderer.setScroll(t)}setScrollTime(t){const a=t/this.getDuration();this.renderer.setScrollPercentage(a)}getActivePlugins(){return this.plugins}loadAudio(t,a,r,o){return li(this,void 0,void 0,function*(){var c;if(this.emit("load",t),!this.options.media&&this.isPlaying()&&this.pause(),this.decodedData=null,this.stopAtPosition=null,!a&&!r){const m=this.options.fetchParams||{};window.AbortController&&!m.signal&&(this.abortController=new AbortController,m.signal=(c=this.abortController)===null||c===void 0?void 0:c.signal);const g=y=>this.emit("loading",y);a=yield jte.fetchBlob(t,g,m);const p=this.options.blobMimeType;p&&(a=new Blob([a],{type:p}))}this.setSrc(t,a);const f=yield new Promise(m=>{const g=o||this.getDuration();g?m(g):this.mediaSubscriptions.push(this.onMediaEvent("loadedmetadata",()=>m(this.getDuration()),{once:!0}))});if(!t&&!a){const m=this.getMediaElement();m instanceof VR&&(m.duration=f)}if(r)this.decodedData=yx.createBuffer(r,f||0);else if(a){const m=yield a.arrayBuffer();this.decodedData=yield yx.decode(m,this.options.sampleRate)}this.decodedData&&(this.emit("decode",this.getDuration()),this.renderer.render(this.decodedData)),this.emit("ready",this.getDuration())})}load(t,a,r){return li(this,void 0,void 0,function*(){try{return yield this.loadAudio(t,void 0,a,r)}catch(o){throw this.emit("error",o),o}})}loadBlob(t,a,r){return li(this,void 0,void 0,function*(){try{return yield this.loadAudio("",t,a,r)}catch(o){throw this.emit("error",o),o}})}zoom(t){if(!this.decodedData)throw new Error("No audio loaded");this.renderer.zoom(t),this.emit("zoom",t)}getDecodedData(){return this.decodedData}exportPeaks({channels:t=2,maxLength:a=8e3,precision:r=1e4}={}){if(!this.decodedData)throw new Error("The audio has not been decoded yet");const o=Math.min(t,this.decodedData.numberOfChannels),c=[];for(let f=0;f<o;f++){const m=this.decodedData.getChannelData(f),g=[],p=m.length/a;for(let y=0;y<a;y++){const S=m.slice(Math.floor(y*p),Math.ceil((y+1)*p));let E=0;for(let T=0;T<S.length;T++){const O=S[T];Math.abs(O)>Math.abs(E)&&(E=O)}g.push(Math.round(E*r)/r)}c.push(g)}return c}getDuration(){let t=super.getDuration()||0;return t!==0&&t!==1/0||!this.decodedData||(t=this.decodedData.duration),t}toggleInteraction(t){this.options.interact=t}setTime(t){this.stopAtPosition=null,super.setTime(t),this.updateProgress(t),this.emit("timeupdate",t)}seekTo(t){const a=this.getDuration()*t;this.setTime(a)}play(t,a){const r=Object.create(null,{play:{get:()=>super.play}});return li(this,void 0,void 0,function*(){t!=null&&this.setTime(t);const o=yield r.play.call(this);return a!=null&&(this.media instanceof VR?this.media.stopAt(a):this.stopAtPosition=a),o})}playPause(){return li(this,void 0,void 0,function*(){return this.isPlaying()?this.pause():this.play()})}stop(){this.pause(),this.setTime(0)}skip(t){this.setTime(this.getCurrentTime()+t)}empty(){this.load("",[[0]],.001)}setMediaElement(t){this.unsubscribePlayerEvents(),super.setMediaElement(t),this.initPlayerEvents()}exportImage(){return li(this,arguments,void 0,function*(t="image/png",a=1,r="dataURL"){return this.renderer.exportImage(t,a,r)})}destroy(){var t;this.emit("destroy"),(t=this.abortController)===null||t===void 0||t.abort(),this.plugins.forEach(a=>a.destroy()),this.subscriptions.forEach(a=>a()),this.unsubscribePlayerEvents(),this.timer.destroy(),this.renderer.destroy(),super.destroy()}}sp.BasePlugin=class extends L0{constructor(e){super(),this.subscriptions=[],this.options=e}onInit(){}_init(e){this.wavesurfer=e,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach(e=>e())}},sp.dom=zte;const Bte=({userMessage:e,setUserMessage:t,handleSendMessage:a,handleSendImage:r,handleSendVoice:o,selectedImage:c,setSelectedImage:f,audioBlob:m,setAudioBlob:g,isSending:p})=>{const{t:y}=_H(),[S,E]=x.useState(!1),[T,O]=x.useState(!1),M=x.useRef(null),A=x.useRef(null),D=x.useRef([]),_=x.useRef(null),j=x.useRef(null),L=U=>{const H=U.target.files?.[0];H&&f(H)},N=()=>{f(null)},V=async()=>{if(!navigator.mediaDevices?.getUserMedia){alert(y("chatInput.voice.notSupported"));return}if(S)M.current?.stop();else try{const U=await navigator.mediaDevices.getUserMedia({audio:!0}),H=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",ee=new MediaRecorder(U,{mimeType:H});M.current=ee,D.current=[],ee.ondataavailable=Y=>{Y.data.size>0&&D.current.push(Y.data)},ee.onstop=()=>{const Y=new Blob(D.current,{type:H});g(Y),E(!1),U.getTracks().forEach(Z=>Z.stop())},ee.start(),E(!0)}catch(U){console.error(U),alert(y("chatInput.voice.permissionError"))}};x.useEffect(()=>{if(m&&_.current){j.current?.destroy();const U=URL.createObjectURL(m);j.current=sp.create({container:_.current,waveColor:"#ccc",progressColor:"#7F28F8",cursorWidth:0,barWidth:3,barHeight:1.5,barGap:2,height:40,interact:!0}),j.current.load(U),j.current.on("finish",()=>O(!1))}},[m]);const B=()=>{j.current&&(j.current.playPause(),O(U=>!U))},z=()=>{E(!1),g(null),j.current?.destroy()};return J.jsxs("div",{style:{display:"flex",alignItems:"center",backgroundColor:"white",border:"1px solid #d1d5db",borderRadius:"9999px",padding:"0.5rem 0.75rem",boxShadow:"0 1px 3px rgba(0,0,0,0.1)",width:"95%",height:"56px"},children:[J.jsx("button",{style:{color:"#6b7280",background:"none",border:"none",margin:"0 0.5rem",cursor:"pointer",padding:"0"},onClick:()=>A.current?.click(),children:c?J.jsxs("div",{style:{position:"relative"},children:[J.jsx("img",{src:URL.createObjectURL(c),alt:y("chatInput.image.selectedAlt"),style:{width:"2rem",height:"2rem",borderRadius:"9999px",objectFit:"cover",padding:"0"}}),J.jsx(y0,{style:{position:"absolute",top:"-0.5rem",right:"-0.5rem",fontSize:"14px",color:"#ef4444",background:"white",borderRadius:"9999px",cursor:"pointer"},onClick:U=>{U.stopPropagation(),N()}})]}):J.jsx(S6,{style:{fontSize:"20px"}})}),J.jsx("input",{disabled:p,type:"file",accept:"image/*",ref:A,onChange:L,style:{display:"none",padding:"0"}}),J.jsx(Ld,{title:S?"Stop Recording":"Send Audio",children:J.jsx("button",{onClick:V,style:{color:S?"#ef4444":"#6b7280",background:"none",border:"none",margin:"0 0.5rem",cursor:"pointer",padding:"0"},children:S?J.jsx(E6,{style:{fontSize:"20px"}}):J.jsx(p6,{style:{fontSize:"20px"}})})}),J.jsx("div",{style:{flex:1,margin:"0 0.5rem",minWidth:0,maxWidth:"100%",display:"flex",alignItems:"center"},children:m?J.jsxs("div",{style:{display:"flex",alignItems:"center",width:"100%",backgroundColor:"#f3f4f6",padding:"0.5rem 1rem",borderRadius:"0.5rem"},children:[J.jsx("button",{style:{background:"none",border:"none",marginRight:"0.75rem",color:"#7f28f8",cursor:"pointer",padding:"0"},onClick:B,children:T?J.jsx(uO,{style:{fontSize:"24px"}}):J.jsx(cO,{style:{fontSize:"24px"}})}),J.jsx("div",{ref:_,style:{width:"100%",height:"2rem"}}),J.jsx(y0,{style:{fontSize:"18px",color:"#ef4444",marginLeft:"0.75rem",cursor:"pointer"},onClick:z})]}):S?J.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f3f4f6",padding:"0.5rem 1rem",borderRadius:"0.5rem",animation:"pulse 2s infinite"},children:J.jsx("span",{children:"Recording"})}):J.jsx(Vd,{type:"text",value:e,onChange:U=>t(U.target.value),placeholder:"Message...",style:{width:"100%",border:"none",fontSize:"16px",margin:0,lineHeight:1.5,color:"#374151",padding:"0"},onKeyDown:U=>{U.key==="Enter"&&(U.preventDefault(),c?(r(c,e),N(),t("")):e.trim()&&(a(),t("")))}})}),J.jsx("button",{disabled:p,onClick:()=>{const U=!!c,H=!!e.trim();U?(r(c,e),N(),t("")):!!m?(o(m),z()):H&&(a(),t(""))},"aria-label":y("chatInput.send"),style:{color:"#6b7280",background:"none",border:"none",margin:"0 0.5rem",cursor:"pointer",padding:"0"},children:J.jsx(x6,{style:{fontSize:"20px"}})})]})};function Pte({suggestions:e,colorCode:t,sendMessageSuggestion:a}){return J.jsx("div",{style:{overflowX:"auto",overflowY:"hidden",whiteSpace:"nowrap",paddingTop:"4px",paddingBottom:"8px",width:"100%",boxSizing:"border-box",marginLeft:"4%",marginTop:"4px",marginBottom:"4px"},children:J.jsx("div",{style:{display:"inline-flex",gap:"0.5rem"},children:e?.map((r,o)=>J.jsx("button",{onClick:()=>a(r),style:{whiteSpace:"nowrap",padding:"0.5rem 1rem",border:`1px solid ${t}`,borderRadius:"9999px",backgroundColor:"white",cursor:"pointer",fontSize:"14px",color:t,flexShrink:0},onMouseEnter:c=>{c.currentTarget.style.backgroundColor="#f3f3f3"},onMouseLeave:c=>{c.currentTarget.style.backgroundColor="white"},children:r},o))})})}function Ute(){return J.jsxs("div",{className:"jawebcss-powered-container",children:[J.jsx("span",{className:"jawebcss-powered-label",children:"Powered by"}),J.jsx("a",{href:"https://jaweb.me/",target:"_blank",className:"jawebcss-powered-link",rel:"noopener noreferrer",children:"Jaweb"})]})}const Ite=({color:e,size:t=5})=>J.jsxs("div",{className:"typing-boxes",children:[J.jsx("span",{style:{backgroundColor:e,width:t,height:t}}),J.jsx("span",{style:{backgroundColor:e,width:t,height:t}}),J.jsx("span",{style:{backgroundColor:e,width:t,height:t}})]}),kte=({productImage:e})=>{const[t,a]=x.useState(null),[r,o]=x.useState(null),[c,f]=x.useState(!1),m=async p=>{f(!0),o(null);const y=new FileReader;y.onload=async()=>{const S=y.result;try{const T=await(await fetch(`${ii.apiUrl}ark-tryon/`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userImageUrl:S,productImageUrl:e})})).json();T.resultImage?o(T.resultImage):console.error("Ark API error:",T)}catch(E){console.error("Error calling Ark API:",E)}finally{f(!1)}},y.readAsDataURL(p)},g=p=>{p.target.files&&p.target.files[0]&&(a(URL.createObjectURL(p.target.files[0])),m(p.target.files[0]))};return J.jsxs("div",{className:"mt-4 border rounded-lg p-4 bg-gray-50",children:[!t&&!r&&!c&&J.jsxs("label",{className:"flex flex-col items-center justify-center border-2 border-dashed border-gray-400 rounded-lg w-full h-40 cursor-pointer hover:bg-gray-100 transition",children:[J.jsx(g6,{style:{fontSize:28,marginBottom:8}}),J.jsx("span",{className:"text-gray-500",children:"Click or Drop your photo here"}),J.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:g})]}),c&&J.jsxs("div",{className:"flex flex-col items-center justify-center h-40",children:[J.jsx(Wu,{indicator:J.jsx(Ks,{style:{fontSize:32},spin:!0})}),J.jsx("p",{className:"mt-2 text-gray-600",children:"Generating your try-on..."})]}),!c&&r&&J.jsxs("div",{className:"flex flex-col items-center",children:[J.jsx("p",{className:"mb-2 text-sm font-medium",children:"✨ Try-On Result"}),J.jsx("img",{src:r,alt:"Result",className:"max-h-64 object-contain rounded-md border"}),J.jsx(Kr,{style:{margin:"4px"},type:"default",className:"mt-3",onClick:()=>{a(null),o(null)},children:"Try Another"})]})]})},Fte=({groupedProducts:e,selectedVariants:t,setSelectedVariants:a,counts:r,setCounts:o,handleAddToCart:c,handleRemoveFromCart:f,colorCode:m="#7F28F8",shortenName:g,sliderRef:p,totalSlides:y,disableCheckout:S=!1})=>{if(!y||y===0)return null;const[E,T]=x.useState(null);return J.jsx("section",{className:"sallaX",style:{"--sallaX-accent":m},"aria-label":"Recommended products",children:J.jsx("div",{ref:p,className:"keen-slider sallaX-slider",children:Object.entries(e).map(([O,M])=>{const A=t[O]||(M.length>0?M[0].variant_id:""),D=M.find(H=>H.variant_id===A)||M[0];if(!D)return null;const _=r[D.variant_id]||0,j=Array.from(new Set(M.map(H=>H.option?.trim()??"").filter(H=>H&&H.toLowerCase()!=="none"))),L=H=>{const ee=M.find(Y=>Y.option===H);ee&&a(Y=>({...Y,[O]:ee.variant_id}))},N=D.option??j[0]??"",V=async()=>{o(H=>({...H,[D.variant_id]:(H[D.variant_id]||0)+1}));try{await c(D.variant_id,D.name,1)}catch(H){console.warn("Add to cart failed:",H.message),o(ee=>({...ee,[D.variant_id]:(ee[D.variant_id]||0)-1}))}},B=async()=>{_!==0&&(o(H=>({...H,[D.variant_id]:Math.max(0,(H[D.variant_id]||0)-1)})),await f(D.variant_id,1))},z=E===D.variant_id,U=D.tag?D.tag.toLowerCase()==="clothing":!0;return J.jsxs("article",{className:"keen-slider__slide sallaX-card",role:"group","aria-roledescription":"slide",children:[J.jsxs("div",{className:"sallaX-media",onClick:()=>window.open(D.link,"_blank"),children:[J.jsx("img",{src:D.image,alt:D.name,className:"sallaX-img",loading:"lazy"}),J.jsx("a",{href:D.link,target:"_blank",rel:"noopener noreferrer",className:"sallaX-visit","aria-label":"Open product page",onClick:H=>H.stopPropagation(),children:"View"})]}),J.jsxs("div",{className:"sallaX-body",children:[J.jsx("a",{href:D.link,target:"_blank",rel:"noopener noreferrer",className:"sallaX-name",title:D.name,children:g(D.name)}),J.jsx("div",{className:"sallaX-row",children:J.jsx("span",{className:"sallaX-price","aria-label":"Price",children:D.price})}),j.length>1&&J.jsxs("div",{className:"sallaX-selectWrap",children:[J.jsx("label",{htmlFor:`sallaX-select-${O}`,className:"sallaX-selectLabel",children:"Choose an option"}),J.jsx("select",{id:`sallaX-select-${O}`,className:"sallaX-select","aria-label":"Choose an option",value:N,onChange:H=>L(H.target.value),children:j.map(H=>J.jsx("option",{value:H,children:H},H))})]}),J.jsxs("div",{className:"flex items-center justify-between w-full space-x-4",children:[!S&&J.jsxs("div",{className:"sallaX-cta","aria-label":"Quantity controls",children:[J.jsx("button",{type:"button",className:"sallaX-qty sallaX-qty--minus",onClick:B,"aria-label":"Decrease quantity",disabled:_===0,children:"–"}),J.jsx("output",{className:"sallaX-qtyCount","aria-live":"polite","aria-atomic":"true",children:_}),J.jsx("button",{type:"button",className:"sallaX-qty sallaX-qty--plus",onClick:V,"aria-label":"Increase quantity",children:"+"})]}),U&&J.jsx(Kr,{style:{backgroundColor:m,color:"white"},className:"px-6 py-2 rounded-lg shadow-md transition",onClick:()=>T(z?null:D.variant_id),children:z?"Close Try On":"Try On"})]}),U&&z&&J.jsx("div",{className:"mt-4",children:J.jsx(kte,{productImage:D.image})})]})]},O)})})})};var bx={},j5;function qte(){if(j5)return bx;j5=1,Object.defineProperty(bx,"__esModule",{value:!0});var e=Ed();function t(z){return Array.prototype.slice.call(z)}function a(z,U){var H=Math.floor(z);return H===U||H+1===U?z:U}function r(){return Date.now()}function o(z,U,H){if(U="data-keen-slider-"+U,H===null)return z.removeAttribute(U);z.setAttribute(U,H||"")}function c(z,U){return U=U||document,typeof z=="function"&&(z=z(U)),Array.isArray(z)?z:typeof z=="string"?t(U.querySelectorAll(z)):z instanceof HTMLElement?[z]:z instanceof NodeList?t(z):[]}function f(z){z.raw&&(z=z.raw),z.cancelable&&!z.defaultPrevented&&z.preventDefault()}function m(z){z.raw&&(z=z.raw),z.stopPropagation&&z.stopPropagation()}function g(){var z=[];return{add:function(U,H,ee,Y){U.addListener?U.addListener(ee):U.addEventListener(H,ee,Y),z.push([U,H,ee,Y])},input:function(U,H,ee,Y){this.add(U,H,function(Z){return function(W){W.nativeEvent&&(W=W.nativeEvent);var ie=W.changedTouches||[],G=W.targetTouches||[],k=W.detail&&W.detail.x?W.detail:null;return Z({id:k?k.identifier?k.identifier:"i":G[0]?G[0]?G[0].identifier:"e":"d",idChanged:k?k.identifier?k.identifier:"i":ie[0]?ie[0]?ie[0].identifier:"e":"d",raw:W,x:k&&k.x?k.x:G[0]?G[0].screenX:k?k.x:W.pageX,y:k&&k.y?k.y:G[0]?G[0].screenY:k?k.y:W.pageY})}}(ee),Y)},purge:function(){z.forEach(function(U){U[0].removeListener?U[0].removeListener(U[2]):U[0].removeEventListener(U[1],U[2],U[3])}),z=[]}}}function p(z,U,H){return Math.min(Math.max(z,U),H)}function y(z){return(z>0?1:0)-(z<0?1:0)||+z}function S(z){var U=z.getBoundingClientRect();return{height:a(U.height,z.offsetHeight),width:a(U.width,z.offsetWidth)}}function E(z,U,H,ee){var Y=z&&z[U];return Y==null?H:ee&&typeof Y=="function"?Y():Y}function T(z){return Math.round(1e6*z)/1e6}function O(z,U){if(z===U)return!0;var H=typeof z;if(H!==typeof U)return!1;if(H!=="object"||z===null||U===null)return H==="function"&&z.toString()===U.toString();if(z.length!==U.length||Object.getOwnPropertyNames(z).length!==Object.getOwnPropertyNames(U).length)return!1;for(var ee in z)if(!O(z[ee],U[ee]))return!1;return!0}var M=function(){return M=Object.assign||function(z){for(var U,H=1,ee=arguments.length;H<ee;H++)for(var Y in U=arguments[H])Object.prototype.hasOwnProperty.call(U,Y)&&(z[Y]=U[Y]);return z},M.apply(this,arguments)};function A(z,U,H){for(var ee,Y=0,Z=U.length;Y<Z;Y++)!ee&&Y in U||(ee||(ee=Array.prototype.slice.call(U,0,Y)),ee[Y]=U[Y]);return z.concat(ee||Array.prototype.slice.call(U))}function D(z){var U,H,ee,Y,Z,W;function ie(q){W||(W=q),G(!0);var F=q-W;F>ee&&(F=ee);var te=Y[H];if(te[3]<F)return H++,ie(q);var ae=te[2],oe=te[4],le=te[0],ue=te[1]*(0,te[5])(oe===0?1:(F-ae)/oe);if(ue&&z.track.to(le+ue),F<ee)return Q();W=null,G(!1),k(null),z.emit("animationEnded")}function G(q){U.active=q}function k(q){U.targetIdx=q}function Q(){var q;q=ie,Z=window.requestAnimationFrame(q)}function se(){var q;q=Z,window.cancelAnimationFrame(q),G(!1),k(null),W&&z.emit("animationStopped"),W=null}return U={active:!1,start:function(q){if(se(),z.track.details){var F=0,te=z.track.details.position;H=0,ee=0,Y=q.map(function(ae){var oe,le=Number(te),ue=(oe=ae.earlyExit)!==null&&oe!==void 0?oe:ae.duration,Ee=ae.easing,je=ae.distance*Ee(ue/ae.duration)||0;te+=je;var Ne=ee;return ee+=ue,F+=je,[le,ae.distance,Ne,ee,ae.duration,Ee]}),k(z.track.distToIdx(F)),Q(),z.emit("animationStarted")}},stop:se,targetIdx:null}}function _(z){var U,H,ee,Y,Z,W,ie,G,k,Q,se,q,F,te,ae=1/0,oe=[],le=null,ue=0;function Ee(Oe){Se(ue+Oe)}function je(Oe){var Re=Ne(ue+Oe).abs;return me(Re)?Re:null}function Ne(Oe){var Re=Math.floor(Math.abs(T(Oe/H))),Ae=T((Oe%H+H)%H);Ae===H&&(Ae=0);var we=y(Oe),_e=ie.indexOf(A([],ie).reduce(function(ze,it){return Math.abs(it-Ae)<Math.abs(ze-Ae)?it:ze})),Ve=_e;return we<0&&Re++,_e===W&&(Ve=0,Re+=we>0?1:-1),{abs:Ve+Re*W*we,origin:_e,rel:Ve}}function ke(Oe,Re,Ae){var we;if(Re||!Qe())return ye(Oe,Ae);if(!me(Oe))return null;var _e=Ne(Ae??ue),Ve=_e.abs,ze=Oe-_e.rel,it=Ve+ze;we=ye(it);var ut=ye(it-W*y(ze));return(ut!==null&&Math.abs(ut)<Math.abs(we)||we===null)&&(we=ut),T(we)}function ye(Oe,Re){if(Re==null&&(Re=T(ue)),!me(Oe)||Oe===null)return null;Oe=Math.round(Oe);var Ae=Ne(Re),we=Ae.abs,_e=Ae.rel,Ve=Ae.origin,ze=he(Oe),it=(Re%H+H)%H,ut=ie[Ve],vt=Math.floor((Oe-(we-_e))/W)*H;return T(ut-it-ut+ie[ze]+vt+(Ve===W?H:0))}function me(Oe){return Le(Oe)===Oe}function Le(Oe){return p(Oe,k,Q)}function Qe(){return Y.loop}function he(Oe){return(Oe%W+W)%W}function Se(Oe){var Re;Re=Oe-ue,oe.push({distance:Re,timestamp:r()}),oe.length>6&&(oe=oe.slice(-6)),ue=T(Oe);var Ae=ve().abs;if(Ae!==le){var we=le!==null;le=Ae,we&&z.emit("slideChanged")}}function ve(Oe){var Re=Oe?null:function(){if(W){var Ae=Qe(),we=Ae?(ue%H+H)%H:ue,_e=(Ae?ue%H:ue)-Z[0][2],Ve=0-(_e<0&&Ae?H-Math.abs(_e):_e),ze=0,it=Ne(ue),ut=it.abs,vt=it.rel,At=Z[vt][2],ht=Z.map(function(Lt,Vt){var _t=Ve+ze;(_t<0-Lt[0]||_t>1)&&(_t+=(Math.abs(_t)>H-1&&Ae?H:0)*y(-_t));var Tt=Vt-vt,ct=y(Tt),gt=Tt+ut;Ae&&(ct===-1&&_t>At&&(gt+=W),ct===1&&_t<At&&(gt-=W),se!==null&><se&&(_t+=H),q!==null&>>q&&(_t-=H));var at=_t+Lt[0]+Lt[1],lt=Math.max(_t>=0&&at<=1?1:at<0||_t>1?0:_t<0?Math.min(1,(Lt[0]+_t)/Lt[0]):(1-_t)/Lt[0],0);return ze+=Lt[0]+Lt[1],{abs:gt,distance:Y.rtl?-1*_t+1-Lt[0]:_t,portion:lt,size:Lt[0]}});return ut=Le(ut),vt=he(ut),{abs:Le(ut),length:ee,max:te,maxIdx:Q,min:F,minIdx:k,position:ue,progress:Ae?we/H:ue/ee,rel:vt,slides:ht,slidesLength:H}}}();return U.details=Re,z.emit("detailsChanged"),Re}return U={absToRel:he,add:Ee,details:null,distToIdx:je,idxToDist:ke,init:function(Oe){if(function(){if(Y=z.options,Z=(Y.trackConfig||[]).map(function(_e){return[E(_e,"size",1),E(_e,"spacing",0),E(_e,"origin",0)]}),W=Z.length){H=T(Z.reduce(function(_e,Ve){return _e+Ve[0]+Ve[1]},0));var Ae,we=W-1;ee=T(H+Z[0][2]-Z[we][0]-Z[we][2]-Z[we][1]),ie=Z.reduce(function(_e,Ve){if(!_e)return[0];var ze=Z[_e.length-1],it=_e[_e.length-1]+(ze[0]+ze[2])+ze[1];return it-=Ve[2],_e[_e.length-1]>it&&(it=_e[_e.length-1]),it=T(it),_e.push(it),(!Ae||Ae<it)&&(G=_e.length-1),Ae=it,_e},null),ee===0&&(G=0),ie.push(T(H))}}(),!W)return ve(!0);var Re;(function(){var Ae=z.options.range,we=z.options.loop;se=k=we?E(we,"min",-1/0):0,q=Q=we?E(we,"max",ae):G;var _e=E(Ae,"min",null),Ve=E(Ae,"max",null);_e!==null&&(k=_e),Ve!==null&&(Q=Ve),F=k===-1/0?k:z.track.idxToDist(k||0,!0,0),te=Q===ae?Q:ke(Q,!0,0),Ve===null&&(q=Q),E(Ae,"align",!1)&&Q!==ae&&Z[he(Q)][2]===0&&(te-=1-Z[he(Q)][0],Q=je(te-ue)),F=T(F),te=T(te)})(),Re=Oe,Number(Re)===Re?Ee(ye(Le(Oe))):ve()},to:Se,velocity:function(){var Oe=r(),Re=oe.reduce(function(Ae,we){var _e=we.distance,Ve=we.timestamp;return Oe-Ve>200||(y(_e)!==y(Ae.distance)&&Ae.distance&&(Ae={distance:0,lastTimestamp:0,time:0}),Ae.time&&(Ae.distance+=_e),Ae.lastTimestamp&&(Ae.time+=Ve-Ae.lastTimestamp),Ae.lastTimestamp=Ve),Ae},{distance:0,lastTimestamp:0,time:0});return Re.distance/Re.time||0}}}function j(z){var U,H,ee,Y,Z,W,ie,G;function k(le){return 2*le}function Q(le){return p(le,ie,G)}function se(le){return 1-Math.pow(1-le,3)}function q(){return ee?z.track.velocity():0}function F(){oe();var le=z.options.mode==="free-snap",ue=z.track,Ee=q();Y=y(Ee);var je=z.track.details,Ne=[];if(Ee||!le){var ke=te(Ee),ye=ke.dist,me=ke.dur;if(me=k(me),ye*=Y,le){var Le=ue.idxToDist(ue.distToIdx(ye),!0);Le&&(ye=Le)}Ne.push({distance:ye,duration:me,easing:se});var Qe=je.position,he=Qe+ye;if(he<Z||he>W){var Se=he<Z?Z-Qe:W-Qe,ve=0,Oe=Ee;if(y(Se)===Y){var Re=Math.min(Math.abs(Se)/Math.abs(ye),1),Ae=function(Ve){return 1-Math.pow(1-Ve,1/3)}(Re)*me;Ne[0].earlyExit=Ae,Oe=Ee*(1-Re)}else Ne[0].earlyExit=0,ve+=Se;var we=te(Oe,100),_e=we.dist*Y;z.options.rubberband&&(Ne.push({distance:_e,duration:k(we.dur),easing:se}),Ne.push({distance:-_e+ve,duration:500,easing:se}))}z.animator.start(Ne)}else z.moveToIdx(Q(je.abs),!0,{duration:500,easing:function(Ve){return 1+--Ve*Ve*Ve*Ve*Ve}})}function te(le,ue){ue===void 0&&(ue=1e3);var Ee=147e-9+(le=Math.abs(le))/ue;return{dist:Math.pow(le,2)/Ee,dur:le/Ee}}function ae(){var le=z.track.details;le&&(Z=le.min,W=le.max,ie=le.minIdx,G=le.maxIdx)}function oe(){z.animator.stop()}z.on("updated",ae),z.on("optionsChanged",ae),z.on("created",ae),z.on("dragStarted",function(){ee=!1,oe(),U=H=z.track.details.abs}),z.on("dragChecked",function(){ee=!0}),z.on("dragEnded",function(){var le=z.options.mode;le==="snap"&&function(){var ue=z.track,Ee=z.track.details,je=Ee.position,Ne=y(q());(je>W||je<Z)&&(Ne=0);var ke=U+Ne;Ee.slides[ue.absToRel(ke)].portion===0&&(ke-=Ne),U!==H&&(ke=H),y(ue.idxToDist(ke,!0))!==Ne&&(ke+=Ne),ke=Q(ke);var ye=ue.idxToDist(ke,!0);z.animator.start([{distance:ye,duration:500,easing:function(me){return 1+--me*me*me*me*me}}])}(),le!=="free"&&le!=="free-snap"||F()}),z.on("dragged",function(){H=z.track.details.abs})}function L(z){var U,H,ee,Y,Z,W,ie,G,k,Q,se,q,F,te,ae,oe,le,ue,Ee=g();function je(ve){if(W&&G===ve.id){var Oe=me(ve);if(k){if(!ye(ve))return ke(ve);Q=Oe,k=!1,z.emit("dragChecked")}if(oe)return Q=Oe;f(ve);var Re=function(we){if(le===-1/0&&ue===1/0)return we;var _e=z.track.details,Ve=_e.length,ze=_e.position,it=p(we,le-ze,ue-ze);if(Ve===0)return 0;if(!z.options.rubberband)return it;if(ze<=ue&&ze>=le||ze<le&&H>0||ze>ue&&H<0)return we;var ut=(ze<le?ze-le:ze-ue)/Ve,vt=Y*Ve,At=Math.abs(ut*vt),ht=Math.max(0,1-At/Z*2);return ht*ht*we}(ie(Q-Oe)/Y*ee);H=y(Re);var Ae=z.track.details.position;(Ae>le&&Ae<ue||Ae===le&&H>0||Ae===ue&&H<0)&&m(ve),se+=Re,!q&&Math.abs(se*Y)>5&&(q=!0),z.track.add(Re),Q=Oe,z.emit("dragged")}}function Ne(ve){!W&&z.track.details&&z.track.details.length&&(se=0,W=!0,q=!1,k=!0,G=ve.id,ye(ve),Q=me(ve),z.emit("dragStarted"))}function ke(ve){W&&G===ve.idChanged&&(W=!1,z.emit("dragEnded"))}function ye(ve){var Oe=Le(),Re=Oe?ve.y:ve.x,Ae=Oe?ve.x:ve.y,we=F!==void 0&&te!==void 0&&Math.abs(te-Ae)<=Math.abs(F-Re);return F=Re,te=Ae,we}function me(ve){return Le()?ve.y:ve.x}function Le(){return z.options.vertical}function Qe(){Y=z.size,Z=Le()?window.innerHeight:window.innerWidth;var ve=z.track.details;ve&&(le=ve.min,ue=ve.max)}function he(ve){q&&(m(ve),f(ve))}function Se(){if(Ee.purge(),z.options.drag&&!z.options.disabled){var ve;ve=z.options.dragSpeed||1,ie=typeof ve=="function"?ve:function(Re){return Re*ve},ee=z.options.rtl?-1:1,Qe(),U=z.container,function(){var Re="data-keen-slider-clickable";c("[".concat(Re,"]:not([").concat(Re,"=false])"),U).map(function(Ae){Ee.add(Ae,"dragstart",m),Ee.add(Ae,"mousedown",m),Ee.add(Ae,"touchstart",m)})}(),Ee.add(U,"dragstart",function(Re){f(Re)}),Ee.add(U,"click",he,{capture:!0}),Ee.input(U,"ksDragStart",Ne),Ee.input(U,"ksDrag",je),Ee.input(U,"ksDragEnd",ke),Ee.input(U,"mousedown",Ne),Ee.input(U,"mousemove",je),Ee.input(U,"mouseleave",ke),Ee.input(U,"mouseup",ke),Ee.input(U,"touchstart",Ne,{passive:!0}),Ee.input(U,"touchmove",je,{passive:!1}),Ee.input(U,"touchend",ke),Ee.input(U,"touchcancel",ke),Ee.add(window,"wheel",function(Re){W&&f(Re)});var Oe="data-keen-slider-scrollable";c("[".concat(Oe,"]:not([").concat(Oe,"=false])"),z.container).map(function(Re){return function(Ae){var we;Ee.input(Ae,"touchstart",function(_e){we=me(_e),oe=!0,ae=!0},{passive:!0}),Ee.input(Ae,"touchmove",function(_e){var Ve=Le(),ze=Ve?Ae.scrollHeight-Ae.clientHeight:Ae.scrollWidth-Ae.clientWidth,it=we-me(_e),ut=Ve?Ae.scrollTop:Ae.scrollLeft,vt=Ve&&Ae.style.overflowY==="scroll"||!Ve&&Ae.style.overflowX==="scroll";if(we=me(_e),(it<0&&ut>0||it>0&&ut<ze)&&ae&&vt)return oe=!0;ae=!1,f(_e),oe=!1}),Ee.input(Ae,"touchend",function(){oe=!1})}(Re)})}}z.on("updated",Qe),z.on("optionsChanged",Se),z.on("created",Se),z.on("destroyed",Ee.purge)}function N(z){var U,H,ee=null;function Y(F,te,ae){z.animator.active?W(F,te,ae):requestAnimationFrame(function(){return W(F,te,ae)})}function Z(){Y(!1,!1,H)}function W(F,te,ae){var oe=0,le=z.size,ue=z.track.details;if(ue&&U){var Ee=ue.slides;U.forEach(function(je,Ne){if(F)!ee&&te&&G(je,null,ae),k(je,null,ae);else{if(!Ee[Ne])return;var ke=Ee[Ne].size*le;!ee&&te&&G(je,ke,ae),k(je,Ee[Ne].distance*le-oe,ae),oe+=ke}})}}function ie(F){return z.options.renderMode==="performance"?Math.round(F):F}function G(F,te,ae){var oe=ae?"height":"width";te!==null&&(te=ie(te)+"px"),F.style["min-"+oe]=te,F.style["max-"+oe]=te}function k(F,te,ae){if(te!==null){te=ie(te);var oe=ae?te:0;te="translate3d(".concat(ae?0:te,"px, ").concat(oe,"px, 0)")}F.style.transform=te,F.style["-webkit-transform"]=te}function Q(){U&&(W(!0,!0,H),U=null),z.on("detailsChanged",Z,!0)}function se(){Y(!1,!0,H)}function q(){Q(),H=z.options.vertical,z.options.disabled||z.options.renderMode==="custom"||(ee=E(z.options.slides,"perView",null)==="auto",z.on("detailsChanged",Z),(U=z.slides).length&&se())}z.on("created",q),z.on("optionsChanged",q),z.on("beforeOptionsChanged",function(){Q()}),z.on("updated",se),z.on("destroyed",Q)}function V(z,U){return function(H){var ee,Y,Z,W,ie,G=g();function k(ye){var me;o(H.container,"reverse",(me=H.container,window.getComputedStyle(me,null).getPropertyValue("direction")!=="rtl"||ye?null:"")),o(H.container,"v",H.options.vertical&&!ye?"":null),o(H.container,"disabled",H.options.disabled&&!ye?"":null)}function Q(){se()&&oe()}function se(){var ye=null;if(W.forEach(function(Le){Le.matches&&(ye=Le.__media)}),ye===ee)return!1;ee||H.emit("beforeOptionsChanged"),ee=ye;var me=ye?Z.breakpoints[ye]:Z;return H.options=M(M({},Z),me),k(),Ne(),ke(),ue(),!0}function q(ye){var me=S(ye);return(H.options.vertical?me.height:me.width)/H.size||1}function F(){return H.options.trackConfig.length}function te(ye){for(var me in ee=!1,Z=M(M({},U),ye),G.purge(),Y=H.size,W=[],Z.breakpoints||[]){var Le=window.matchMedia(me);Le.__media=me,W.push(Le),G.add(Le,"change",Q)}G.add(window,"orientationchange",je),G.add(window,"resize",Ee),se()}function ae(ye){H.animator.stop();var me=H.track.details;H.track.init(ye??(me?me.abs:0))}function oe(ye){ae(ye),H.emit("optionsChanged")}function le(ye,me){if(ye)return te(ye),void oe(me);Ne(),ke();var Le=F();ue(),F()!==Le?oe(me):ae(me),H.emit("updated")}function ue(){var ye=H.options.slides;if(typeof ye=="function")return H.options.trackConfig=ye(H.size,H.slides);for(var me=H.slides,Le=me.length,Qe=typeof ye=="number"?ye:E(ye,"number",Le,!0),he=[],Se=E(ye,"perView",1,!0),ve=E(ye,"spacing",0,!0)/H.size||0,Oe=Se==="auto"?ve:ve/Se,Re=E(ye,"origin","auto"),Ae=0,we=0;we<Qe;we++){var _e=Se==="auto"?q(me[we]):1/Se-ve+Oe,Ve=Re==="center"?.5-_e/2:Re==="auto"?0:Re;he.push({origin:Ve,size:_e,spacing:ve}),Ae+=_e}if(Ae+=ve*(Qe-1),Re==="auto"&&!H.options.loop&&Se!==1){var ze=0;he.map(function(it){var ut=Ae-ze;return ze+=it.size+ve,ut>=1||(it.origin=1-ut-(Ae>1?0:1-Ae)),it})}H.options.trackConfig=he}function Ee(){Ne();var ye=H.size;H.options.disabled||ye===Y||(Y=ye,le())}function je(){Ee(),setTimeout(Ee,500),setTimeout(Ee,2e3)}function Ne(){var ye=S(H.container);H.size=(H.options.vertical?ye.height:ye.width)||1}function ke(){H.slides=c(H.options.selector,H.container)}H.container=(ie=c(z,document)).length?ie[0]:null,H.destroy=function(){G.purge(),H.emit("destroyed"),k(!0)},H.prev=function(){H.moveToIdx(H.track.details.abs-1,!0)},H.next=function(){H.moveToIdx(H.track.details.abs+1,!0)},H.update=le,te(H.options)}}var B=function(z,U,H){try{return function(ee,Y){var Z,W={};return Z={emit:function(ie){W[ie]&&W[ie].forEach(function(k){k(Z)});var G=Z.options&&Z.options[ie];G&&G(Z)},moveToIdx:function(ie,G,k){var Q=Z.track.idxToDist(ie,G);if(Q){var se=Z.options.defaultAnimation;Z.animator.start([{distance:Q,duration:E(k||se,"duration",500),easing:E(k||se,"easing",function(q){return 1+--q*q*q*q*q})}])}},on:function(ie,G,k){k===void 0&&(k=!1),W[ie]||(W[ie]=[]);var Q=W[ie].indexOf(G);Q>-1?k&&delete W[ie][Q]:k||W[ie].push(G)},options:ee},function(){if(Z.track=_(Z),Z.animator=D(Z),Y)for(var ie=0,G=Y;ie<G.length;ie++)(0,G[ie])(Z);Z.track.init(Z.options.initial||0),Z.emit("created")}(),Z}(U,A([V(z,{drag:!0,mode:"snap",renderMode:"precision",rubberband:!0,selector:".keen-slider__slide"}),N,L,j],H||[],!0))}catch(ee){console.error(ee)}};return bx.useKeenSlider=function(z,U){var H=e.useRef(null),ee=e.useRef(!1),Y=e.useRef(z),Z=e.useCallback(function(W){W?(Y.current=z,H.current=new B(W,z,U),ee.current=!1):(H.current&&H.current.destroy&&H.current.destroy(),H.current=null)},[]);return e.useEffect(function(){O(Y.current,z)||(Y.current=z,H.current&&H.current.update(Y.current))},[z]),[Z,H]},bx}var HR=qte();const Gte=({message:e,colorCode:t,disableCheckout:a,handleAddToCart:r,handleRemoveFromCart:o})=>{const[c,f]=x.useState({}),[m,g]=x.useState({}),p=j=>{const L=/(https?:\/\/[^\s]+)/g;return j.split(L).map((N,V)=>L.test(N)?J.jsx("a",{href:N.trim(),style:{color:"#00b3bc"},target:"_blank",rel:"noopener noreferrer",className:"underline break-words",children:N},V):J.jsx("span",{children:N},V))},y=j=>{const L=j.trim();if(!L.includes("Name:")||!L.includes("VariantId"))return null;const N=L.match(/Name\s*[:\-]\s*(.+)/i),V=L.match(/Price\s*[:\-]\s*(.+)/i),B=L.match(/Link\s*[:\-]\s*(https?:\/\/[^\s]+)/i),z=L.match(/VariantId\s*[:\-]\s*(.+)/i),U=L.match(/variant_tag_name\s*[:\-]\s*(.+)/i),H=L.match(/options\s*[:\-]\s*([^|\r\n]+)/i),ee=L.match(/tag\s*[:\-]\s*(.+)/i);return!N||!V||!B||!z||!U?null:{name:N[1].trim(),price:V[1].trim(),link:B[1].trim(),image:"",variant_id:z[1].trim(),variant_tag_name:U[1].trim(),option:H?.[1]?.trim(),tag:ee?.[1]?.trim()}},S=x.useMemo(()=>{const j=e.split("|||").map(V=>V.trim()).filter(Boolean),L=[];let N=null;return j.forEach(V=>{if(V.startsWith("img - ")){const B=V.replace(/^img\s*[-:]\s*/,"").trim();if(N)N.image=B;else{const z=[...L].reverse().find(U=>U.type==="product");z&&(z.data.image=B)}}else if(V.includes("Name:")&&V.includes("VariantId")){const B=y(V);B&&(L.push({type:"product",data:B}),N=B)}else L.push({type:"text",data:V}),N=null}),L},[e]),E=x.useMemo(()=>{const j={};return S.forEach(L=>{if(L.type==="product"){const N=L.data;j[N.variant_tag_name]=j[N.variant_tag_name]||[],j[N.variant_tag_name].push(N)}}),j},[S]),T=(j,L=22)=>j.length>L?j.slice(0,L)+"...":j,[O,M]=x.useState(0),A=Object.keys(E).length,[D,_]=HR.useKeenSlider({loop:!1,mode:"free",slides:{perView:1,spacing:16},slideChanged(j){M(j.track.details.rel)}});return J.jsxs("div",{className:"space-y-6 mt-4 h-fit",children:[S.filter(j=>j.type==="text").map((j,L)=>J.jsx("p",{className:"whitespace-pre-wrap break-words",children:p(j.data)},L)),Object.keys(E).length>0&&J.jsxs(J.Fragment,{children:[Object.keys(E).length>1&&J.jsxs("div",{style:{display:"flex",margin:0,marginBottom:"6px",justifyContent:"space-between",paddingInline:"4px"},children:[J.jsx(Kr,{shape:"circle",icon:J.jsx(Xm,{}),onClick:()=>_.current?.prev(),disabled:O===0}),J.jsx(Kr,{shape:"circle",icon:J.jsx(K1,{}),onClick:()=>_.current?.next(),disabled:O===A-1})]}),J.jsx("div",{ref:D,className:"keen-slider",children:J.jsx(Fte,{groupedProducts:E,selectedVariants:m,setSelectedVariants:g,counts:c,setCounts:f,handleAddToCart:r,handleRemoveFromCart:o,colorCode:t,shortenName:T,sliderInstance:_,currentSlide:O,totalSlides:A,sliderRef:D,disableCheckout:a})})]})]})},L5=({message:e})=>{const t=e.find(r=>r.type==="image_url")?.image_url?.url,a=e?.isBusiness;return J.jsx("div",{children:J.jsx("div",{children:t&&J.jsx("div",{className:"mb-2 bg-transparent text-white ",children:J.jsx("img",{src:t,alt:"Chat image",style:{width:200},className:`rounded-md bg-transparent mt-2 max-w-xs ${a?"border border-gray-300 shadow-sm":""}`})})})})},Xte=({message:e,colorCode:t})=>{const a=e.find(o=>o.type==="text")?.text,r=o=>{const c=/(https?:\/\/[^\s]+)/g;return o.split(c).map((f,m)=>c.test(f)?J.jsx("a",{href:f.trim(),style:{color:t},target:"_blank",rel:"noopener noreferrer",className:"underline break-words",children:f},m):J.jsx("span",{children:f},m))};return J.jsx(J.Fragment,{children:a&&J.jsx("div",{style:{color:"white",border:1,backgroundColor:t,paddingTop:10,paddingBottom:10,paddingInline:14,maxWidth:"85%",lineHeight:1.4,borderRadius:"16px",wordBreak:"break-word"},children:J.jsx("p",{children:r(a)})})})},Yte=({link:e,colorCode:t,transcription:a})=>{const r=x.useRef(null),o=x.useRef(null),[c,f]=x.useState(!1),[m,g]=x.useState(!1);x.useEffect(()=>{if(r.current)return o.current?.destroy(),o.current=sp.create({container:r.current,waveColor:"white",progressColor:"white",cursorWidth:0,barWidth:3,barHeight:1.5,barGap:2,height:40,interact:!0}),o.current.load(e),o.current.on("finish",()=>f(!1)),()=>{o.current?.destroy()}},[e,t]);const p=()=>{o.current&&(o.current.playPause(),f(y=>!y))};return J.jsxs("div",{style:{backgroundColor:t,padding:"12px",borderRadius:"20px",color:"white",maxWidth:"350px",marginBottom:"16px"},children:[J.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[J.jsx("button",{onClick:p,style:{background:"transparent",border:"none",color:"white",marginRight:"12px",cursor:"pointer"},children:c?J.jsx(uO,{style:{fontSize:"24px"}}):J.jsx(cO,{style:{fontSize:"24px"}})}),J.jsx("div",{ref:r,style:{width:"130px",height:"40px",overflow:"hidden",color:"white"}})]}),a&&J.jsxs("div",{style:{marginTop:"12px",fontSize:"14px",color:"rgba(255,255,255,0.85)"},children:[J.jsx("button",{onClick:()=>g(!m),style:{background:"none",border:"none",color:"white",textDecoration:"underline",fontSize:"13px",cursor:"pointer",padding:0},children:m?"Hide transcript":"Show transcript"}),m&&J.jsx("p",{style:{marginTop:"6px",lineHeight:"1.4"},children:a})]})]})},Wte=({status:e,user:t})=>{if(!e||!t)return null;let a=`${t} is ${e}`;return e==="typing"?a=`${t} is typing...`:a="",J.jsx(J.Fragment,{children:a&&J.jsx("div",{className:"flex justify-center mb-2",children:J.jsx("span",{className:"px-3 py-1 bg-gray-100 text-gray-500 text-sm rounded-full",children:a})})})},Zte=({message:e})=>{const t=r=>{const o=/(https?:\/\/[^\s]+)/g;return r?.split(o).map((c,f)=>o.test(c)?J.jsx("a",{href:c.trim(),style:{color:"#00b3bc"},target:"_blank",rel:"noopener noreferrer",className:"underline break-words",children:c},f):J.jsx("span",{children:c},f))};if(e?.startsWith("Add this to cart for me")&&e?.includes("name:")){const o=e?.match(/name:([^,]+)/i)?.[1]?.trim()||"Product";return J.jsxs("div",{style:{backgroundColor:"#E8F5E9",border:"1px solid #C8E6C9",borderRadius:"12px",padding:"12px 16px",color:"#2E7D32",fontWeight:500,fontSize:"15px",maxWidth:"360px",margin:"0 auto",textAlign:"center"},children:["✅ ",J.jsx("strong",{children:o})," has been added to your cart."]})}return J.jsx("p",{style:{color:"white"},children:t(e)})};/**
|
|
652
|
+
`,[t,a]}setOptions(t){if(this.options.container!==t.container){const a=this.parentFromOptionsContainer(t.container);a.appendChild(this.container),this.parent=a}t.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||this.initDrag(),this.options=t,this.reRender()}getWrapper(){return this.wrapper}getWidth(){return this.scrollContainer.clientWidth}getScroll(){return this.scrollContainer.scrollLeft}setScroll(t){this.scrollContainer.scrollLeft=t}setScrollPercentage(t){const{scrollWidth:a}=this.scrollContainer,r=a*t;this.setScroll(r)}destroy(){var t,a;this.subscriptions.forEach(r=>r()),this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(a=this.unsubscribeOnScroll)===null||a===void 0||a.forEach(r=>r()),this.unsubscribeOnScroll=[]}createDelay(t=10){let a,r;const o=()=>{a&&clearTimeout(a),r&&r()};return this.timeouts.push(o),()=>new Promise((c,f)=>{o(),r=f,a=setTimeout(()=>{a=void 0,r=void 0,c()},t)})}convertColorValues(t){if(!Array.isArray(t))return t||"";if(t.length<2)return t[0]||"";const a=document.createElement("canvas"),r=a.getContext("2d"),o=a.height*(window.devicePixelRatio||1),c=r.createLinearGradient(0,0,0,o),f=1/(t.length-1);return t.forEach((m,g)=>{const p=g*f;c.addColorStop(p,m)}),c}getPixelRatio(){return Math.max(1,window.devicePixelRatio||1)}renderBarWaveform(t,a,r,o){const c=t[0],f=t[1]||t[0],m=c.length,{width:g,height:p}=r.canvas,y=p/2,S=this.getPixelRatio(),E=a.barWidth?a.barWidth*S:1,T=a.barGap?a.barGap*S:a.barWidth?E/2:0,O=a.barRadius||0,M=g/(E+T)/m,A=O&&"roundRect"in r?"roundRect":"rect";r.beginPath();let D=0,_=0,j=0;for(let L=0;L<=m;L++){const N=Math.round(L*M);if(N>D){const z=Math.round(_*y*o),U=z+Math.round(j*y*o)||1;let H=y-z;a.barAlign==="top"?H=0:a.barAlign==="bottom"&&(H=p-U),r[A](D*(E+T),H,E,U,O),D=N,_=0,j=0}const V=Math.abs(c[L]||0),B=Math.abs(f[L]||0);V>_&&(_=V),B>j&&(j=B)}r.fill(),r.closePath()}renderLineWaveform(t,a,r,o){const c=f=>{const m=t[f]||t[0],g=m.length,{height:p}=r.canvas,y=p/2,S=r.canvas.width/g;r.moveTo(0,y);let E=0,T=0;for(let O=0;O<=g;O++){const M=Math.round(O*S);if(M>E){const D=y+(Math.round(T*y*o)||1)*(f===0?-1:1);r.lineTo(E,D),E=M,T=0}const A=Math.abs(m[O]||0);A>T&&(T=A)}r.lineTo(E,y)};r.beginPath(),c(0),c(1),r.fill(),r.closePath()}renderWaveform(t,a,r){if(r.fillStyle=this.convertColorValues(a.waveColor),a.renderFunction)return void a.renderFunction(t,r);let o=a.barHeight||1;if(a.normalize){const c=Array.from(t[0]).reduce((f,m)=>Math.max(f,Math.abs(m)),0);o=c?1/c:1}a.barWidth||a.barGap||a.barAlign?this.renderBarWaveform(t,a,r,o):this.renderLineWaveform(t,a,r,o)}renderSingleCanvas(t,a,r,o,c,f,m){const g=this.getPixelRatio(),p=document.createElement("canvas");p.width=Math.round(r*g),p.height=Math.round(o*g),p.style.width=`${r}px`,p.style.height=`${o}px`,p.style.left=`${Math.round(c)}px`,f.appendChild(p);const y=p.getContext("2d");if(this.renderWaveform(t,a,y),p.width>0&&p.height>0){const S=p.cloneNode(),E=S.getContext("2d");E.drawImage(p,0,0),E.globalCompositeOperation="source-in",E.fillStyle=this.convertColorValues(a.progressColor),E.fillRect(0,0,p.width,p.height),m.appendChild(S)}}renderMultiCanvas(t,a,r,o,c,f){const m=this.getPixelRatio(),{clientWidth:g}=this.scrollContainer,p=r/m;let y=Math.min(lp.MAX_CANVAS_WIDTH,g,p),S={};if(a.barWidth||a.barGap){const A=a.barWidth||.5,D=A+(a.barGap||A/2);y%D!=0&&(y=Math.floor(y/D)*D)}if(y===0)return;const E=A=>{if(A<0||A>=T||S[A])return;S[A]=!0;const D=A*y;let _=Math.min(p-D,y);if(a.barWidth||a.barGap){const L=a.barWidth||.5,N=L+(a.barGap||L/2);_=Math.floor(_/N)*N}if(_<=0)return;const j=t.map(L=>{const N=Math.floor(D/p*L.length),V=Math.floor((D+_)/p*L.length);return L.slice(N,V)});this.renderSingleCanvas(j,a,_,o,D,c,f)},T=Math.ceil(p/y);if(!this.isScrollable){for(let A=0;A<T;A++)E(A);return}const O=this.scrollContainer.scrollLeft/p,M=Math.floor(O*T);if(E(M-1),E(M),E(M+1),T>1){const A=this.on("scroll",()=>{const{scrollLeft:D}=this.scrollContainer,_=Math.floor(D/p*T);Object.keys(S).length>lp.MAX_NODES&&(c.innerHTML="",f.innerHTML="",S={}),E(_-1),E(_),E(_+1)});this.unsubscribeOnScroll.push(A)}}renderChannel(t,a,r,o){var{overlay:c}=a,f=function(y,S){var E={};for(var T in y)Object.prototype.hasOwnProperty.call(y,T)&&S.indexOf(T)<0&&(E[T]=y[T]);if(y!=null&&typeof Object.getOwnPropertySymbols=="function"){var O=0;for(T=Object.getOwnPropertySymbols(y);O<T.length;O++)S.indexOf(T[O])<0&&Object.prototype.propertyIsEnumerable.call(y,T[O])&&(E[T[O]]=y[T[O]])}return E}(a,["overlay"]);const m=document.createElement("div"),g=this.getHeight(f.height,f.splitChannels);m.style.height=`${g}px`,c&&o>0&&(m.style.marginTop=`-${g}px`),this.canvasWrapper.style.minHeight=`${g}px`,this.canvasWrapper.appendChild(m);const p=m.cloneNode();this.progressWrapper.appendChild(p),this.renderMultiCanvas(t,f,r,g,m,p)}render(t){return li(this,void 0,void 0,function*(){var a;this.timeouts.forEach(g=>g()),this.timeouts=[],this.canvasWrapper.innerHTML="",this.progressWrapper.innerHTML="",this.options.width!=null&&(this.scrollContainer.style.width=typeof this.options.width=="number"?`${this.options.width}px`:this.options.width);const r=this.getPixelRatio(),o=this.scrollContainer.clientWidth,c=Math.ceil(t.duration*(this.options.minPxPerSec||0));this.isScrollable=c>o;const f=this.options.fillParent&&!this.isScrollable,m=(f?o:c)*r;if(this.wrapper.style.width=f?"100%":`${c}px`,this.scrollContainer.style.overflowX=this.isScrollable?"auto":"hidden",this.scrollContainer.classList.toggle("noScrollbar",!!this.options.hideScrollbar),this.cursor.style.backgroundColor=`${this.options.cursorColor||this.options.progressColor}`,this.cursor.style.width=`${this.options.cursorWidth}px`,this.audioData=t,this.emit("render"),this.options.splitChannels)for(let g=0;g<t.numberOfChannels;g++){const p=Object.assign(Object.assign({},this.options),(a=this.options.splitChannels)===null||a===void 0?void 0:a[g]);this.renderChannel([t.getChannelData(g)],p,m,g)}else{const g=[t.getChannelData(0)];t.numberOfChannels>1&&g.push(t.getChannelData(1)),this.renderChannel(g,this.options,m,0)}Promise.resolve().then(()=>this.emit("rendered"))})}reRender(){if(this.unsubscribeOnScroll.forEach(r=>r()),this.unsubscribeOnScroll=[],!this.audioData)return;const{scrollWidth:t}=this.scrollContainer,{right:a}=this.progressWrapper.getBoundingClientRect();if(this.render(this.audioData),this.isScrollable&&t!==this.scrollContainer.scrollWidth){const{right:r}=this.progressWrapper.getBoundingClientRect();let o=r-a;o*=2,o=o<0?Math.floor(o):Math.ceil(o),o/=2,this.scrollContainer.scrollLeft+=o}}zoom(t){this.options.minPxPerSec=t,this.reRender()}scrollIntoView(t,a=!1){const{scrollLeft:r,scrollWidth:o,clientWidth:c}=this.scrollContainer,f=t*o,m=r,g=r+c,p=c/2;if(this.isDragging)f+30>g?this.scrollContainer.scrollLeft+=30:f-30<m&&(this.scrollContainer.scrollLeft-=30);else{(f<m||f>g)&&(this.scrollContainer.scrollLeft=f-(this.options.autoCenter?p:0));const y=f-r-p;a&&this.options.autoCenter&&y>0&&(this.scrollContainer.scrollLeft+=Math.min(y,10))}{const y=this.scrollContainer.scrollLeft,S=y/o,E=(y+c)/o;this.emit("scroll",S,E,y,y+c)}}renderProgress(t,a){if(isNaN(t))return;const r=100*t;this.canvasWrapper.style.clipPath=`polygon(${r}% 0%, 100% 0%, 100% 100%, ${r}% 100%)`,this.progressWrapper.style.width=`${r}%`,this.cursor.style.left=`${r}%`,this.cursor.style.transform=`translateX(-${Math.round(r)===100?this.options.cursorWidth:0}px)`,this.isScrollable&&this.options.autoScroll&&this.scrollIntoView(t,a)}exportImage(t,a,r){return li(this,void 0,void 0,function*(){const o=this.canvasWrapper.querySelectorAll("canvas");if(!o.length)throw new Error("No waveform data");if(r==="dataURL"){const c=Array.from(o).map(f=>f.toDataURL(t,a));return Promise.resolve(c)}return Promise.all(Array.from(o).map(c=>new Promise((f,m)=>{c.toBlob(g=>{g?f(g):m(new Error("Could not export image"))},t,a)})))})}}lp.MAX_CANVAS_WIDTH=8e3,lp.MAX_NODES=10;class Vte extends L0{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",()=>{requestAnimationFrame(()=>{this.emit("tick")})}),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}class VR extends L0{constructor(t=new AudioContext){super(),this.bufferNode=null,this.playStartTime=0,this.playedDuration=0,this._muted=!1,this._playbackRate=1,this._duration=void 0,this.buffer=null,this.currentSrc="",this.paused=!0,this.crossOrigin=null,this.seeking=!1,this.autoplay=!1,this.addEventListener=this.on,this.removeEventListener=this.un,this.audioContext=t,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}load(){return li(this,void 0,void 0,function*(){})}get src(){return this.currentSrc}set src(t){if(this.currentSrc=t,this._duration=void 0,!t)return this.buffer=null,void this.emit("emptied");fetch(t).then(a=>{if(a.status>=400)throw new Error(`Failed to fetch ${t}: ${a.status} (${a.statusText})`);return a.arrayBuffer()}).then(a=>this.currentSrc!==t?null:this.audioContext.decodeAudioData(a)).then(a=>{this.currentSrc===t&&(this.buffer=a,this.emit("loadedmetadata"),this.emit("canplay"),this.autoplay&&this.play())})}_play(){var t;if(!this.paused)return;this.paused=!1,(t=this.bufferNode)===null||t===void 0||t.disconnect(),this.bufferNode=this.audioContext.createBufferSource(),this.buffer&&(this.bufferNode.buffer=this.buffer),this.bufferNode.playbackRate.value=this._playbackRate,this.bufferNode.connect(this.gainNode);let a=this.playedDuration*this._playbackRate;(a>=this.duration||a<0)&&(a=0,this.playedDuration=0),this.bufferNode.start(this.audioContext.currentTime,a),this.playStartTime=this.audioContext.currentTime,this.bufferNode.onended=()=>{this.currentTime>=this.duration&&(this.pause(),this.emit("ended"))}}_pause(){var t;this.paused=!0,(t=this.bufferNode)===null||t===void 0||t.stop(),this.playedDuration+=this.audioContext.currentTime-this.playStartTime}play(){return li(this,void 0,void 0,function*(){this.paused&&(this._play(),this.emit("play"))})}pause(){this.paused||(this._pause(),this.emit("pause"))}stopAt(t){const a=t-this.currentTime,r=this.bufferNode;r?.stop(this.audioContext.currentTime+a),r?.addEventListener("ended",()=>{r===this.bufferNode&&(this.bufferNode=null,this.pause())},{once:!0})}setSinkId(t){return li(this,void 0,void 0,function*(){return this.audioContext.setSinkId(t)})}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t,this.bufferNode&&(this.bufferNode.playbackRate.value=t)}get currentTime(){return(this.paused?this.playedDuration:this.playedDuration+(this.audioContext.currentTime-this.playStartTime))*this._playbackRate}set currentTime(t){const a=!this.paused;a&&this._pause(),this.playedDuration=t/this._playbackRate,a&&this._play(),this.emit("seeking"),this.emit("timeupdate")}get duration(){var t,a;return(t=this._duration)!==null&&t!==void 0?t:((a=this.buffer)===null||a===void 0?void 0:a.duration)||0}set duration(t){this._duration=t}get volume(){return this.gainNode.gain.value}set volume(t){this.gainNode.gain.value=t,this.emit("volumechange")}get muted(){return this._muted}set muted(t){this._muted!==t&&(this._muted=t,this._muted?this.gainNode.disconnect():this.gainNode.connect(this.audioContext.destination))}canPlayType(t){return/^(audio|video)\//.test(t)}getGainNode(){return this.gainNode}getChannelData(){const t=[];if(!this.buffer)return t;const a=this.buffer.numberOfChannels;for(let r=0;r<a;r++)t.push(this.buffer.getChannelData(r));return t}}const Hte={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3};class sp extends Lte{static create(t){return new sp(t)}constructor(t){const a=t.media||(t.backend==="WebAudio"?new VR:void 0);super({media:a,mediaControls:t.mediaControls,autoplay:t.autoplay,playbackRate:t.audioRate}),this.plugins=[],this.decodedData=null,this.stopAtPosition=null,this.subscriptions=[],this.mediaSubscriptions=[],this.abortController=null,this.options=Object.assign({},Hte,t),this.timer=new Vte;const r=a?void 0:this.getMediaElement();this.renderer=new lp(this.options,r),this.initPlayerEvents(),this.initRendererEvents(),this.initTimerEvents(),this.initPlugins();const o=this.options.url||this.getSrc()||"";Promise.resolve().then(()=>{this.emit("init");const{peaks:c,duration:f}=this.options;(o||c&&f)&&this.load(o,c,f).catch(()=>null)})}updateProgress(t=this.getCurrentTime()){return this.renderer.renderProgress(t/this.getDuration(),this.isPlaying()),t}initTimerEvents(){this.subscriptions.push(this.timer.on("tick",()=>{if(!this.isSeeking()){const t=this.updateProgress();this.emit("timeupdate",t),this.emit("audioprocess",t),this.stopAtPosition!=null&&this.isPlaying()&&t>=this.stopAtPosition&&this.pause()}}))}initPlayerEvents(){this.isPlaying()&&(this.emit("play"),this.timer.start()),this.mediaSubscriptions.push(this.onMediaEvent("timeupdate",()=>{const t=this.updateProgress();this.emit("timeupdate",t)}),this.onMediaEvent("play",()=>{this.emit("play"),this.timer.start()}),this.onMediaEvent("pause",()=>{this.emit("pause"),this.timer.stop(),this.stopAtPosition=null}),this.onMediaEvent("emptied",()=>{this.timer.stop(),this.stopAtPosition=null}),this.onMediaEvent("ended",()=>{this.emit("timeupdate",this.getDuration()),this.emit("finish"),this.stopAtPosition=null}),this.onMediaEvent("seeking",()=>{this.emit("seeking",this.getCurrentTime())}),this.onMediaEvent("error",()=>{var t;this.emit("error",(t=this.getMediaElement().error)!==null&&t!==void 0?t:new Error("Media error")),this.stopAtPosition=null}))}initRendererEvents(){this.subscriptions.push(this.renderer.on("click",(t,a)=>{this.options.interact&&(this.seekTo(t),this.emit("interaction",t*this.getDuration()),this.emit("click",t,a))}),this.renderer.on("dblclick",(t,a)=>{this.emit("dblclick",t,a)}),this.renderer.on("scroll",(t,a,r,o)=>{const c=this.getDuration();this.emit("scroll",t*c,a*c,r,o)}),this.renderer.on("render",()=>{this.emit("redraw")}),this.renderer.on("rendered",()=>{this.emit("redrawcomplete")}),this.renderer.on("dragstart",t=>{this.emit("dragstart",t)}),this.renderer.on("dragend",t=>{this.emit("dragend",t)}));{let t;this.subscriptions.push(this.renderer.on("drag",a=>{if(!this.options.interact)return;let r;this.renderer.renderProgress(a),clearTimeout(t),this.isPlaying()?r=0:this.options.dragToSeek===!0?r=200:typeof this.options.dragToSeek=="object"&&this.options.dragToSeek!==void 0&&(r=this.options.dragToSeek.debounceTime),t=setTimeout(()=>{this.seekTo(a)},r),this.emit("interaction",a*this.getDuration()),this.emit("drag",a)}))}}initPlugins(){var t;!((t=this.options.plugins)===null||t===void 0)&&t.length&&this.options.plugins.forEach(a=>{this.registerPlugin(a)})}unsubscribePlayerEvents(){this.mediaSubscriptions.forEach(t=>t()),this.mediaSubscriptions=[]}setOptions(t){this.options=Object.assign({},this.options,t),t.duration&&!t.peaks&&(this.decodedData=yx.createBuffer(this.exportPeaks(),t.duration)),t.peaks&&t.duration&&(this.decodedData=yx.createBuffer(t.peaks,t.duration)),this.renderer.setOptions(this.options),t.audioRate&&this.setPlaybackRate(t.audioRate),t.mediaControls!=null&&(this.getMediaElement().controls=t.mediaControls)}registerPlugin(t){t._init(this),this.plugins.push(t);const a=t.once("destroy",()=>{this.plugins=this.plugins.filter(r=>r!==t),this.subscriptions=this.subscriptions.filter(r=>r!==a)});return this.subscriptions.push(a),t}getWrapper(){return this.renderer.getWrapper()}getWidth(){return this.renderer.getWidth()}getScroll(){return this.renderer.getScroll()}setScroll(t){return this.renderer.setScroll(t)}setScrollTime(t){const a=t/this.getDuration();this.renderer.setScrollPercentage(a)}getActivePlugins(){return this.plugins}loadAudio(t,a,r,o){return li(this,void 0,void 0,function*(){var c;if(this.emit("load",t),!this.options.media&&this.isPlaying()&&this.pause(),this.decodedData=null,this.stopAtPosition=null,!a&&!r){const m=this.options.fetchParams||{};window.AbortController&&!m.signal&&(this.abortController=new AbortController,m.signal=(c=this.abortController)===null||c===void 0?void 0:c.signal);const g=y=>this.emit("loading",y);a=yield jte.fetchBlob(t,g,m);const p=this.options.blobMimeType;p&&(a=new Blob([a],{type:p}))}this.setSrc(t,a);const f=yield new Promise(m=>{const g=o||this.getDuration();g?m(g):this.mediaSubscriptions.push(this.onMediaEvent("loadedmetadata",()=>m(this.getDuration()),{once:!0}))});if(!t&&!a){const m=this.getMediaElement();m instanceof VR&&(m.duration=f)}if(r)this.decodedData=yx.createBuffer(r,f||0);else if(a){const m=yield a.arrayBuffer();this.decodedData=yield yx.decode(m,this.options.sampleRate)}this.decodedData&&(this.emit("decode",this.getDuration()),this.renderer.render(this.decodedData)),this.emit("ready",this.getDuration())})}load(t,a,r){return li(this,void 0,void 0,function*(){try{return yield this.loadAudio(t,void 0,a,r)}catch(o){throw this.emit("error",o),o}})}loadBlob(t,a,r){return li(this,void 0,void 0,function*(){try{return yield this.loadAudio("",t,a,r)}catch(o){throw this.emit("error",o),o}})}zoom(t){if(!this.decodedData)throw new Error("No audio loaded");this.renderer.zoom(t),this.emit("zoom",t)}getDecodedData(){return this.decodedData}exportPeaks({channels:t=2,maxLength:a=8e3,precision:r=1e4}={}){if(!this.decodedData)throw new Error("The audio has not been decoded yet");const o=Math.min(t,this.decodedData.numberOfChannels),c=[];for(let f=0;f<o;f++){const m=this.decodedData.getChannelData(f),g=[],p=m.length/a;for(let y=0;y<a;y++){const S=m.slice(Math.floor(y*p),Math.ceil((y+1)*p));let E=0;for(let T=0;T<S.length;T++){const O=S[T];Math.abs(O)>Math.abs(E)&&(E=O)}g.push(Math.round(E*r)/r)}c.push(g)}return c}getDuration(){let t=super.getDuration()||0;return t!==0&&t!==1/0||!this.decodedData||(t=this.decodedData.duration),t}toggleInteraction(t){this.options.interact=t}setTime(t){this.stopAtPosition=null,super.setTime(t),this.updateProgress(t),this.emit("timeupdate",t)}seekTo(t){const a=this.getDuration()*t;this.setTime(a)}play(t,a){const r=Object.create(null,{play:{get:()=>super.play}});return li(this,void 0,void 0,function*(){t!=null&&this.setTime(t);const o=yield r.play.call(this);return a!=null&&(this.media instanceof VR?this.media.stopAt(a):this.stopAtPosition=a),o})}playPause(){return li(this,void 0,void 0,function*(){return this.isPlaying()?this.pause():this.play()})}stop(){this.pause(),this.setTime(0)}skip(t){this.setTime(this.getCurrentTime()+t)}empty(){this.load("",[[0]],.001)}setMediaElement(t){this.unsubscribePlayerEvents(),super.setMediaElement(t),this.initPlayerEvents()}exportImage(){return li(this,arguments,void 0,function*(t="image/png",a=1,r="dataURL"){return this.renderer.exportImage(t,a,r)})}destroy(){var t;this.emit("destroy"),(t=this.abortController)===null||t===void 0||t.abort(),this.plugins.forEach(a=>a.destroy()),this.subscriptions.forEach(a=>a()),this.unsubscribePlayerEvents(),this.timer.destroy(),this.renderer.destroy(),super.destroy()}}sp.BasePlugin=class extends L0{constructor(e){super(),this.subscriptions=[],this.options=e}onInit(){}_init(e){this.wavesurfer=e,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach(e=>e())}},sp.dom=zte;const Bte=({userMessage:e,setUserMessage:t,handleSendMessage:a,handleSendImage:r,handleSendVoice:o,selectedImage:c,setSelectedImage:f,audioBlob:m,setAudioBlob:g,isSending:p})=>{const{t:y}=_H(),[S,E]=x.useState(!1),[T,O]=x.useState(!1),M=x.useRef(null),A=x.useRef(null),D=x.useRef([]),_=x.useRef(null),j=x.useRef(null),L=U=>{const H=U.target.files?.[0];H&&f(H)},N=()=>{f(null)},V=async()=>{if(!navigator.mediaDevices?.getUserMedia){alert(y("chatInput.voice.notSupported"));return}if(S)M.current?.stop();else try{const U=await navigator.mediaDevices.getUserMedia({audio:!0}),H=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",ee=new MediaRecorder(U,{mimeType:H});M.current=ee,D.current=[],ee.ondataavailable=Y=>{Y.data.size>0&&D.current.push(Y.data)},ee.onstop=()=>{const Y=new Blob(D.current,{type:H});g(Y),E(!1),U.getTracks().forEach(Z=>Z.stop())},ee.start(),E(!0)}catch(U){console.error(U),alert(y("chatInput.voice.permissionError"))}};x.useEffect(()=>{if(m&&_.current){j.current?.destroy();const U=URL.createObjectURL(m);j.current=sp.create({container:_.current,waveColor:"#ccc",progressColor:"#7F28F8",cursorWidth:0,barWidth:3,barHeight:1.5,barGap:2,height:40,interact:!0}),j.current.load(U),j.current.on("finish",()=>O(!1))}},[m]);const B=()=>{j.current&&(j.current.playPause(),O(U=>!U))},z=()=>{E(!1),g(null),j.current?.destroy()};return J.jsxs("div",{style:{display:"flex",alignItems:"center",backgroundColor:"white",border:"1px solid #d1d5db",borderRadius:"9999px",padding:"0.5rem 0.75rem",boxShadow:"0 1px 3px rgba(0,0,0,0.1)",width:"95%",height:"56px"},children:[J.jsx("button",{style:{color:"#6b7280",background:"none",border:"none",margin:"0 0.5rem",cursor:"pointer",padding:"0"},onClick:()=>A.current?.click(),children:c?J.jsxs("div",{style:{position:"relative"},children:[J.jsx("img",{src:URL.createObjectURL(c),alt:y("chatInput.image.selectedAlt"),style:{width:"2rem",height:"2rem",borderRadius:"9999px",objectFit:"cover",padding:"0"}}),J.jsx(y0,{style:{position:"absolute",top:"-0.5rem",right:"-0.5rem",fontSize:"14px",color:"#ef4444",background:"white",borderRadius:"9999px",cursor:"pointer"},onClick:U=>{U.stopPropagation(),N()}})]}):J.jsx(S6,{style:{fontSize:"20px"}})}),J.jsx("input",{disabled:p,type:"file",accept:"image/*",ref:A,onChange:L,style:{display:"none",padding:"0"}}),J.jsx(Ld,{title:S?"Stop Recording":"Send Audio",children:J.jsx("button",{onClick:V,style:{color:S?"#ef4444":"#6b7280",background:"none",border:"none",margin:"0 0.5rem",cursor:"pointer",padding:"0"},children:S?J.jsx(E6,{style:{fontSize:"20px"}}):J.jsx(p6,{style:{fontSize:"20px"}})})}),J.jsx("div",{style:{flex:1,margin:"0 0.5rem",minWidth:0,maxWidth:"100%",display:"flex",alignItems:"center"},children:m?J.jsxs("div",{style:{display:"flex",alignItems:"center",width:"100%",backgroundColor:"#f3f4f6",padding:"0.5rem 1rem",borderRadius:"0.5rem"},children:[J.jsx("button",{style:{background:"none",border:"none",marginRight:"0.75rem",color:"#7f28f8",cursor:"pointer",padding:"0"},onClick:B,children:T?J.jsx(uO,{style:{fontSize:"24px"}}):J.jsx(cO,{style:{fontSize:"24px"}})}),J.jsx("div",{ref:_,style:{width:"100%",height:"2rem"}}),J.jsx(y0,{style:{fontSize:"18px",color:"#ef4444",marginLeft:"0.75rem",cursor:"pointer"},onClick:z})]}):S?J.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f3f4f6",padding:"0.5rem 1rem",borderRadius:"0.5rem",animation:"pulse 2s infinite"},children:J.jsx("span",{children:"Recording"})}):J.jsx(Vd,{type:"text",value:e,onChange:U=>t(U.target.value),placeholder:"Message...",style:{width:"100%",border:"none",fontSize:"16px",margin:0,lineHeight:1.5,color:"#374151",padding:"0"},onKeyDown:U=>{U.key==="Enter"&&(U.preventDefault(),c?(r(c,e),N(),t("")):e.trim()&&(a(),t("")))}})}),J.jsx("button",{disabled:p,onClick:()=>{const U=!!c,H=!!e.trim();U?(r(c,e),N(),t("")):!!m?(o(m),z()):H&&(a(),t(""))},"aria-label":y("chatInput.send"),style:{color:"#6b7280",background:"none",border:"none",margin:"0 0.5rem",cursor:"pointer",padding:"0"},children:J.jsx(x6,{style:{fontSize:"20px"}})})]})};function Pte({suggestions:e,colorCode:t,sendMessageSuggestion:a}){return J.jsx("div",{style:{overflowX:"auto",overflowY:"hidden",whiteSpace:"nowrap",paddingTop:"4px",paddingBottom:"8px",width:"100%",boxSizing:"border-box",marginLeft:"4%",marginTop:"4px",marginBottom:"4px"},children:J.jsx("div",{style:{display:"inline-flex",gap:"0.5rem"},children:e?.map((r,o)=>J.jsx("button",{onClick:()=>a(r),style:{whiteSpace:"nowrap",padding:"0.5rem 1rem",border:`1px solid ${t}`,borderRadius:"9999px",backgroundColor:"white",cursor:"pointer",fontSize:"14px",color:t,flexShrink:0},onMouseEnter:c=>{c.currentTarget.style.backgroundColor="#f3f3f3"},onMouseLeave:c=>{c.currentTarget.style.backgroundColor="white"},children:r},o))})})}function Ute(){return J.jsxs("div",{className:"jawebcss-powered-container",children:[J.jsx("span",{className:"jawebcss-powered-label",children:"Powered by"}),J.jsx("a",{href:"https://jaweb.me/",target:"_blank",className:"jawebcss-powered-link",rel:"noopener noreferrer",children:"Jaweb"})]})}const Ite=({color:e,size:t=5})=>J.jsxs("div",{className:"typing-boxes",children:[J.jsx("span",{style:{backgroundColor:e,width:t,height:t}}),J.jsx("span",{style:{backgroundColor:e,width:t,height:t}}),J.jsx("span",{style:{backgroundColor:e,width:t,height:t}})]}),kte=({productImage:e,productID:t})=>{const[a,r]=x.useState(null),[o,c]=x.useState(null),[f,m]=x.useState(!1),g=async y=>{m(!0),c(null);const S=new FileReader;S.onload=async()=>{const E=S.result;try{const O=await(await fetch(`${ii.apiUrl}ark-tryon/`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userImageUrl:E,productImageUrl:e,productId:t,username:localStorage.getItem("company_username")})})).json();O.resultImage?c(O.resultImage):console.error("Ark API error:",O)}catch(T){console.error("Error calling Ark API:",T)}finally{m(!1)}},S.readAsDataURL(y)},p=y=>{y.target.files&&y.target.files[0]&&(r(URL.createObjectURL(y.target.files[0])),g(y.target.files[0]))};return J.jsxs("div",{className:"mt-4 border rounded-lg p-4 bg-gray-50",children:[!a&&!o&&!f&&J.jsxs("label",{className:"flex flex-col items-center justify-center border-2 border-dashed border-gray-400 rounded-lg w-full h-40 cursor-pointer hover:bg-gray-100 transition",children:[J.jsx(g6,{style:{fontSize:28,marginBottom:8}}),J.jsx("span",{className:"text-gray-500",children:"Click or Drop your photo here"}),J.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:p})]}),f&&J.jsxs("div",{className:"flex flex-col items-center justify-center h-40",children:[J.jsx(Wu,{indicator:J.jsx(Ks,{style:{fontSize:32},spin:!0})}),J.jsx("p",{className:"mt-2 text-gray-600",children:"Generating your try-on..."})]}),!f&&o&&J.jsxs("div",{className:"flex flex-col items-center",children:[J.jsx("p",{className:"mb-2 text-sm font-medium",children:"✨ Try-On Result"}),J.jsx("img",{src:o,alt:"Result",className:"max-h-64 object-contain rounded-md border"}),J.jsx(Kr,{style:{margin:"4px"},type:"default",className:"mt-3",onClick:()=>{r(null),c(null)},children:"Try Another"})]})]})},Fte=({groupedProducts:e,selectedVariants:t,setSelectedVariants:a,counts:r,setCounts:o,handleAddToCart:c,handleRemoveFromCart:f,colorCode:m="#7F28F8",shortenName:g,sliderRef:p,totalSlides:y,disableCheckout:S=!1})=>{if(!y||y===0)return null;const[E,T]=x.useState(null);return J.jsx("section",{className:"sallaX",style:{"--sallaX-accent":m},"aria-label":"Recommended products",children:J.jsx("div",{ref:p,className:"keen-slider sallaX-slider",children:Object.entries(e).map(([O,M])=>{const A=t[O]||(M.length>0?M[0].variant_id:""),D=M.find(H=>H.variant_id===A)||M[0];if(!D)return null;const _=r[D.variant_id]||0,j=Array.from(new Set(M.map(H=>H.option?.trim()??"").filter(H=>H&&H.toLowerCase()!=="none"))),L=H=>{const ee=M.find(Y=>Y.option===H);ee&&a(Y=>({...Y,[O]:ee.variant_id}))},N=D.option??j[0]??"",V=async()=>{o(H=>({...H,[D.variant_id]:(H[D.variant_id]||0)+1}));try{await c(D.variant_id,D.name,1)}catch(H){console.warn("Add to cart failed:",H.message),o(ee=>({...ee,[D.variant_id]:(ee[D.variant_id]||0)-1}))}},B=async()=>{_!==0&&(o(H=>({...H,[D.variant_id]:Math.max(0,(H[D.variant_id]||0)-1)})),await f(D.variant_id,1))},z=E===D.variant_id,U=D.tag?D.tag.toLowerCase()==="clothing":!0;return J.jsxs("article",{className:"keen-slider__slide sallaX-card",role:"group","aria-roledescription":"slide",children:[J.jsxs("div",{className:"sallaX-media",onClick:()=>window.open(D.link,"_blank"),children:[J.jsx("img",{src:D.image,alt:D.name,className:"sallaX-img",loading:"lazy"}),J.jsx("a",{href:D.link,target:"_blank",rel:"noopener noreferrer",className:"sallaX-visit","aria-label":"Open product page",onClick:H=>H.stopPropagation(),children:"View"})]}),J.jsxs("div",{className:"sallaX-body",children:[J.jsx("a",{href:D.link,target:"_blank",rel:"noopener noreferrer",className:"sallaX-name",title:D.name,children:g(D.name)}),J.jsx("div",{className:"sallaX-row",children:J.jsx("span",{className:"sallaX-price","aria-label":"Price",children:D.price})}),j.length>1&&J.jsxs("div",{className:"sallaX-selectWrap",children:[J.jsx("label",{htmlFor:`sallaX-select-${O}`,className:"sallaX-selectLabel",children:"Choose an option"}),J.jsx("select",{id:`sallaX-select-${O}`,className:"sallaX-select","aria-label":"Choose an option",value:N,onChange:H=>L(H.target.value),children:j.map(H=>J.jsx("option",{value:H,children:H},H))})]}),J.jsxs("div",{className:"flex items-center justify-between w-full space-x-4",children:[!S&&J.jsxs("div",{className:"sallaX-cta","aria-label":"Quantity controls",children:[J.jsx("button",{type:"button",className:"sallaX-qty sallaX-qty--minus",onClick:B,"aria-label":"Decrease quantity",disabled:_===0,children:"–"}),J.jsx("output",{className:"sallaX-qtyCount","aria-live":"polite","aria-atomic":"true",children:_}),J.jsx("button",{type:"button",className:"sallaX-qty sallaX-qty--plus",onClick:V,"aria-label":"Increase quantity",children:"+"})]}),U&&J.jsx(Kr,{style:{backgroundColor:m,color:"white"},className:"px-6 py-2 rounded-lg shadow-md transition",onClick:()=>T(z?null:D.variant_id),children:z?"Close Try On":"Try On"})]}),U&&z&&J.jsx("div",{className:"mt-4",children:J.jsx(kte,{productID:D.variant_id,productImage:D.image})})]})]},O)})})})};var bx={},j5;function qte(){if(j5)return bx;j5=1,Object.defineProperty(bx,"__esModule",{value:!0});var e=Ed();function t(z){return Array.prototype.slice.call(z)}function a(z,U){var H=Math.floor(z);return H===U||H+1===U?z:U}function r(){return Date.now()}function o(z,U,H){if(U="data-keen-slider-"+U,H===null)return z.removeAttribute(U);z.setAttribute(U,H||"")}function c(z,U){return U=U||document,typeof z=="function"&&(z=z(U)),Array.isArray(z)?z:typeof z=="string"?t(U.querySelectorAll(z)):z instanceof HTMLElement?[z]:z instanceof NodeList?t(z):[]}function f(z){z.raw&&(z=z.raw),z.cancelable&&!z.defaultPrevented&&z.preventDefault()}function m(z){z.raw&&(z=z.raw),z.stopPropagation&&z.stopPropagation()}function g(){var z=[];return{add:function(U,H,ee,Y){U.addListener?U.addListener(ee):U.addEventListener(H,ee,Y),z.push([U,H,ee,Y])},input:function(U,H,ee,Y){this.add(U,H,function(Z){return function(W){W.nativeEvent&&(W=W.nativeEvent);var ie=W.changedTouches||[],G=W.targetTouches||[],k=W.detail&&W.detail.x?W.detail:null;return Z({id:k?k.identifier?k.identifier:"i":G[0]?G[0]?G[0].identifier:"e":"d",idChanged:k?k.identifier?k.identifier:"i":ie[0]?ie[0]?ie[0].identifier:"e":"d",raw:W,x:k&&k.x?k.x:G[0]?G[0].screenX:k?k.x:W.pageX,y:k&&k.y?k.y:G[0]?G[0].screenY:k?k.y:W.pageY})}}(ee),Y)},purge:function(){z.forEach(function(U){U[0].removeListener?U[0].removeListener(U[2]):U[0].removeEventListener(U[1],U[2],U[3])}),z=[]}}}function p(z,U,H){return Math.min(Math.max(z,U),H)}function y(z){return(z>0?1:0)-(z<0?1:0)||+z}function S(z){var U=z.getBoundingClientRect();return{height:a(U.height,z.offsetHeight),width:a(U.width,z.offsetWidth)}}function E(z,U,H,ee){var Y=z&&z[U];return Y==null?H:ee&&typeof Y=="function"?Y():Y}function T(z){return Math.round(1e6*z)/1e6}function O(z,U){if(z===U)return!0;var H=typeof z;if(H!==typeof U)return!1;if(H!=="object"||z===null||U===null)return H==="function"&&z.toString()===U.toString();if(z.length!==U.length||Object.getOwnPropertyNames(z).length!==Object.getOwnPropertyNames(U).length)return!1;for(var ee in z)if(!O(z[ee],U[ee]))return!1;return!0}var M=function(){return M=Object.assign||function(z){for(var U,H=1,ee=arguments.length;H<ee;H++)for(var Y in U=arguments[H])Object.prototype.hasOwnProperty.call(U,Y)&&(z[Y]=U[Y]);return z},M.apply(this,arguments)};function A(z,U,H){for(var ee,Y=0,Z=U.length;Y<Z;Y++)!ee&&Y in U||(ee||(ee=Array.prototype.slice.call(U,0,Y)),ee[Y]=U[Y]);return z.concat(ee||Array.prototype.slice.call(U))}function D(z){var U,H,ee,Y,Z,W;function ie(q){W||(W=q),G(!0);var F=q-W;F>ee&&(F=ee);var te=Y[H];if(te[3]<F)return H++,ie(q);var ae=te[2],oe=te[4],le=te[0],ue=te[1]*(0,te[5])(oe===0?1:(F-ae)/oe);if(ue&&z.track.to(le+ue),F<ee)return Q();W=null,G(!1),k(null),z.emit("animationEnded")}function G(q){U.active=q}function k(q){U.targetIdx=q}function Q(){var q;q=ie,Z=window.requestAnimationFrame(q)}function se(){var q;q=Z,window.cancelAnimationFrame(q),G(!1),k(null),W&&z.emit("animationStopped"),W=null}return U={active:!1,start:function(q){if(se(),z.track.details){var F=0,te=z.track.details.position;H=0,ee=0,Y=q.map(function(ae){var oe,le=Number(te),ue=(oe=ae.earlyExit)!==null&&oe!==void 0?oe:ae.duration,Ee=ae.easing,je=ae.distance*Ee(ue/ae.duration)||0;te+=je;var Ne=ee;return ee+=ue,F+=je,[le,ae.distance,Ne,ee,ae.duration,Ee]}),k(z.track.distToIdx(F)),Q(),z.emit("animationStarted")}},stop:se,targetIdx:null}}function _(z){var U,H,ee,Y,Z,W,ie,G,k,Q,se,q,F,te,ae=1/0,oe=[],le=null,ue=0;function Ee(Oe){Se(ue+Oe)}function je(Oe){var Re=Ne(ue+Oe).abs;return me(Re)?Re:null}function Ne(Oe){var Re=Math.floor(Math.abs(T(Oe/H))),Ae=T((Oe%H+H)%H);Ae===H&&(Ae=0);var we=y(Oe),_e=ie.indexOf(A([],ie).reduce(function(ze,it){return Math.abs(it-Ae)<Math.abs(ze-Ae)?it:ze})),Ve=_e;return we<0&&Re++,_e===W&&(Ve=0,Re+=we>0?1:-1),{abs:Ve+Re*W*we,origin:_e,rel:Ve}}function ke(Oe,Re,Ae){var we;if(Re||!Qe())return ye(Oe,Ae);if(!me(Oe))return null;var _e=Ne(Ae??ue),Ve=_e.abs,ze=Oe-_e.rel,it=Ve+ze;we=ye(it);var ut=ye(it-W*y(ze));return(ut!==null&&Math.abs(ut)<Math.abs(we)||we===null)&&(we=ut),T(we)}function ye(Oe,Re){if(Re==null&&(Re=T(ue)),!me(Oe)||Oe===null)return null;Oe=Math.round(Oe);var Ae=Ne(Re),we=Ae.abs,_e=Ae.rel,Ve=Ae.origin,ze=he(Oe),it=(Re%H+H)%H,ut=ie[Ve],vt=Math.floor((Oe-(we-_e))/W)*H;return T(ut-it-ut+ie[ze]+vt+(Ve===W?H:0))}function me(Oe){return Le(Oe)===Oe}function Le(Oe){return p(Oe,k,Q)}function Qe(){return Y.loop}function he(Oe){return(Oe%W+W)%W}function Se(Oe){var Re;Re=Oe-ue,oe.push({distance:Re,timestamp:r()}),oe.length>6&&(oe=oe.slice(-6)),ue=T(Oe);var Ae=ve().abs;if(Ae!==le){var we=le!==null;le=Ae,we&&z.emit("slideChanged")}}function ve(Oe){var Re=Oe?null:function(){if(W){var Ae=Qe(),we=Ae?(ue%H+H)%H:ue,_e=(Ae?ue%H:ue)-Z[0][2],Ve=0-(_e<0&&Ae?H-Math.abs(_e):_e),ze=0,it=Ne(ue),ut=it.abs,vt=it.rel,At=Z[vt][2],ht=Z.map(function(Lt,Vt){var _t=Ve+ze;(_t<0-Lt[0]||_t>1)&&(_t+=(Math.abs(_t)>H-1&&Ae?H:0)*y(-_t));var Tt=Vt-vt,ct=y(Tt),gt=Tt+ut;Ae&&(ct===-1&&_t>At&&(gt+=W),ct===1&&_t<At&&(gt-=W),se!==null&><se&&(_t+=H),q!==null&>>q&&(_t-=H));var at=_t+Lt[0]+Lt[1],lt=Math.max(_t>=0&&at<=1?1:at<0||_t>1?0:_t<0?Math.min(1,(Lt[0]+_t)/Lt[0]):(1-_t)/Lt[0],0);return ze+=Lt[0]+Lt[1],{abs:gt,distance:Y.rtl?-1*_t+1-Lt[0]:_t,portion:lt,size:Lt[0]}});return ut=Le(ut),vt=he(ut),{abs:Le(ut),length:ee,max:te,maxIdx:Q,min:F,minIdx:k,position:ue,progress:Ae?we/H:ue/ee,rel:vt,slides:ht,slidesLength:H}}}();return U.details=Re,z.emit("detailsChanged"),Re}return U={absToRel:he,add:Ee,details:null,distToIdx:je,idxToDist:ke,init:function(Oe){if(function(){if(Y=z.options,Z=(Y.trackConfig||[]).map(function(_e){return[E(_e,"size",1),E(_e,"spacing",0),E(_e,"origin",0)]}),W=Z.length){H=T(Z.reduce(function(_e,Ve){return _e+Ve[0]+Ve[1]},0));var Ae,we=W-1;ee=T(H+Z[0][2]-Z[we][0]-Z[we][2]-Z[we][1]),ie=Z.reduce(function(_e,Ve){if(!_e)return[0];var ze=Z[_e.length-1],it=_e[_e.length-1]+(ze[0]+ze[2])+ze[1];return it-=Ve[2],_e[_e.length-1]>it&&(it=_e[_e.length-1]),it=T(it),_e.push(it),(!Ae||Ae<it)&&(G=_e.length-1),Ae=it,_e},null),ee===0&&(G=0),ie.push(T(H))}}(),!W)return ve(!0);var Re;(function(){var Ae=z.options.range,we=z.options.loop;se=k=we?E(we,"min",-1/0):0,q=Q=we?E(we,"max",ae):G;var _e=E(Ae,"min",null),Ve=E(Ae,"max",null);_e!==null&&(k=_e),Ve!==null&&(Q=Ve),F=k===-1/0?k:z.track.idxToDist(k||0,!0,0),te=Q===ae?Q:ke(Q,!0,0),Ve===null&&(q=Q),E(Ae,"align",!1)&&Q!==ae&&Z[he(Q)][2]===0&&(te-=1-Z[he(Q)][0],Q=je(te-ue)),F=T(F),te=T(te)})(),Re=Oe,Number(Re)===Re?Ee(ye(Le(Oe))):ve()},to:Se,velocity:function(){var Oe=r(),Re=oe.reduce(function(Ae,we){var _e=we.distance,Ve=we.timestamp;return Oe-Ve>200||(y(_e)!==y(Ae.distance)&&Ae.distance&&(Ae={distance:0,lastTimestamp:0,time:0}),Ae.time&&(Ae.distance+=_e),Ae.lastTimestamp&&(Ae.time+=Ve-Ae.lastTimestamp),Ae.lastTimestamp=Ve),Ae},{distance:0,lastTimestamp:0,time:0});return Re.distance/Re.time||0}}}function j(z){var U,H,ee,Y,Z,W,ie,G;function k(le){return 2*le}function Q(le){return p(le,ie,G)}function se(le){return 1-Math.pow(1-le,3)}function q(){return ee?z.track.velocity():0}function F(){oe();var le=z.options.mode==="free-snap",ue=z.track,Ee=q();Y=y(Ee);var je=z.track.details,Ne=[];if(Ee||!le){var ke=te(Ee),ye=ke.dist,me=ke.dur;if(me=k(me),ye*=Y,le){var Le=ue.idxToDist(ue.distToIdx(ye),!0);Le&&(ye=Le)}Ne.push({distance:ye,duration:me,easing:se});var Qe=je.position,he=Qe+ye;if(he<Z||he>W){var Se=he<Z?Z-Qe:W-Qe,ve=0,Oe=Ee;if(y(Se)===Y){var Re=Math.min(Math.abs(Se)/Math.abs(ye),1),Ae=function(Ve){return 1-Math.pow(1-Ve,1/3)}(Re)*me;Ne[0].earlyExit=Ae,Oe=Ee*(1-Re)}else Ne[0].earlyExit=0,ve+=Se;var we=te(Oe,100),_e=we.dist*Y;z.options.rubberband&&(Ne.push({distance:_e,duration:k(we.dur),easing:se}),Ne.push({distance:-_e+ve,duration:500,easing:se}))}z.animator.start(Ne)}else z.moveToIdx(Q(je.abs),!0,{duration:500,easing:function(Ve){return 1+--Ve*Ve*Ve*Ve*Ve}})}function te(le,ue){ue===void 0&&(ue=1e3);var Ee=147e-9+(le=Math.abs(le))/ue;return{dist:Math.pow(le,2)/Ee,dur:le/Ee}}function ae(){var le=z.track.details;le&&(Z=le.min,W=le.max,ie=le.minIdx,G=le.maxIdx)}function oe(){z.animator.stop()}z.on("updated",ae),z.on("optionsChanged",ae),z.on("created",ae),z.on("dragStarted",function(){ee=!1,oe(),U=H=z.track.details.abs}),z.on("dragChecked",function(){ee=!0}),z.on("dragEnded",function(){var le=z.options.mode;le==="snap"&&function(){var ue=z.track,Ee=z.track.details,je=Ee.position,Ne=y(q());(je>W||je<Z)&&(Ne=0);var ke=U+Ne;Ee.slides[ue.absToRel(ke)].portion===0&&(ke-=Ne),U!==H&&(ke=H),y(ue.idxToDist(ke,!0))!==Ne&&(ke+=Ne),ke=Q(ke);var ye=ue.idxToDist(ke,!0);z.animator.start([{distance:ye,duration:500,easing:function(me){return 1+--me*me*me*me*me}}])}(),le!=="free"&&le!=="free-snap"||F()}),z.on("dragged",function(){H=z.track.details.abs})}function L(z){var U,H,ee,Y,Z,W,ie,G,k,Q,se,q,F,te,ae,oe,le,ue,Ee=g();function je(ve){if(W&&G===ve.id){var Oe=me(ve);if(k){if(!ye(ve))return ke(ve);Q=Oe,k=!1,z.emit("dragChecked")}if(oe)return Q=Oe;f(ve);var Re=function(we){if(le===-1/0&&ue===1/0)return we;var _e=z.track.details,Ve=_e.length,ze=_e.position,it=p(we,le-ze,ue-ze);if(Ve===0)return 0;if(!z.options.rubberband)return it;if(ze<=ue&&ze>=le||ze<le&&H>0||ze>ue&&H<0)return we;var ut=(ze<le?ze-le:ze-ue)/Ve,vt=Y*Ve,At=Math.abs(ut*vt),ht=Math.max(0,1-At/Z*2);return ht*ht*we}(ie(Q-Oe)/Y*ee);H=y(Re);var Ae=z.track.details.position;(Ae>le&&Ae<ue||Ae===le&&H>0||Ae===ue&&H<0)&&m(ve),se+=Re,!q&&Math.abs(se*Y)>5&&(q=!0),z.track.add(Re),Q=Oe,z.emit("dragged")}}function Ne(ve){!W&&z.track.details&&z.track.details.length&&(se=0,W=!0,q=!1,k=!0,G=ve.id,ye(ve),Q=me(ve),z.emit("dragStarted"))}function ke(ve){W&&G===ve.idChanged&&(W=!1,z.emit("dragEnded"))}function ye(ve){var Oe=Le(),Re=Oe?ve.y:ve.x,Ae=Oe?ve.x:ve.y,we=F!==void 0&&te!==void 0&&Math.abs(te-Ae)<=Math.abs(F-Re);return F=Re,te=Ae,we}function me(ve){return Le()?ve.y:ve.x}function Le(){return z.options.vertical}function Qe(){Y=z.size,Z=Le()?window.innerHeight:window.innerWidth;var ve=z.track.details;ve&&(le=ve.min,ue=ve.max)}function he(ve){q&&(m(ve),f(ve))}function Se(){if(Ee.purge(),z.options.drag&&!z.options.disabled){var ve;ve=z.options.dragSpeed||1,ie=typeof ve=="function"?ve:function(Re){return Re*ve},ee=z.options.rtl?-1:1,Qe(),U=z.container,function(){var Re="data-keen-slider-clickable";c("[".concat(Re,"]:not([").concat(Re,"=false])"),U).map(function(Ae){Ee.add(Ae,"dragstart",m),Ee.add(Ae,"mousedown",m),Ee.add(Ae,"touchstart",m)})}(),Ee.add(U,"dragstart",function(Re){f(Re)}),Ee.add(U,"click",he,{capture:!0}),Ee.input(U,"ksDragStart",Ne),Ee.input(U,"ksDrag",je),Ee.input(U,"ksDragEnd",ke),Ee.input(U,"mousedown",Ne),Ee.input(U,"mousemove",je),Ee.input(U,"mouseleave",ke),Ee.input(U,"mouseup",ke),Ee.input(U,"touchstart",Ne,{passive:!0}),Ee.input(U,"touchmove",je,{passive:!1}),Ee.input(U,"touchend",ke),Ee.input(U,"touchcancel",ke),Ee.add(window,"wheel",function(Re){W&&f(Re)});var Oe="data-keen-slider-scrollable";c("[".concat(Oe,"]:not([").concat(Oe,"=false])"),z.container).map(function(Re){return function(Ae){var we;Ee.input(Ae,"touchstart",function(_e){we=me(_e),oe=!0,ae=!0},{passive:!0}),Ee.input(Ae,"touchmove",function(_e){var Ve=Le(),ze=Ve?Ae.scrollHeight-Ae.clientHeight:Ae.scrollWidth-Ae.clientWidth,it=we-me(_e),ut=Ve?Ae.scrollTop:Ae.scrollLeft,vt=Ve&&Ae.style.overflowY==="scroll"||!Ve&&Ae.style.overflowX==="scroll";if(we=me(_e),(it<0&&ut>0||it>0&&ut<ze)&&ae&&vt)return oe=!0;ae=!1,f(_e),oe=!1}),Ee.input(Ae,"touchend",function(){oe=!1})}(Re)})}}z.on("updated",Qe),z.on("optionsChanged",Se),z.on("created",Se),z.on("destroyed",Ee.purge)}function N(z){var U,H,ee=null;function Y(F,te,ae){z.animator.active?W(F,te,ae):requestAnimationFrame(function(){return W(F,te,ae)})}function Z(){Y(!1,!1,H)}function W(F,te,ae){var oe=0,le=z.size,ue=z.track.details;if(ue&&U){var Ee=ue.slides;U.forEach(function(je,Ne){if(F)!ee&&te&&G(je,null,ae),k(je,null,ae);else{if(!Ee[Ne])return;var ke=Ee[Ne].size*le;!ee&&te&&G(je,ke,ae),k(je,Ee[Ne].distance*le-oe,ae),oe+=ke}})}}function ie(F){return z.options.renderMode==="performance"?Math.round(F):F}function G(F,te,ae){var oe=ae?"height":"width";te!==null&&(te=ie(te)+"px"),F.style["min-"+oe]=te,F.style["max-"+oe]=te}function k(F,te,ae){if(te!==null){te=ie(te);var oe=ae?te:0;te="translate3d(".concat(ae?0:te,"px, ").concat(oe,"px, 0)")}F.style.transform=te,F.style["-webkit-transform"]=te}function Q(){U&&(W(!0,!0,H),U=null),z.on("detailsChanged",Z,!0)}function se(){Y(!1,!0,H)}function q(){Q(),H=z.options.vertical,z.options.disabled||z.options.renderMode==="custom"||(ee=E(z.options.slides,"perView",null)==="auto",z.on("detailsChanged",Z),(U=z.slides).length&&se())}z.on("created",q),z.on("optionsChanged",q),z.on("beforeOptionsChanged",function(){Q()}),z.on("updated",se),z.on("destroyed",Q)}function V(z,U){return function(H){var ee,Y,Z,W,ie,G=g();function k(ye){var me;o(H.container,"reverse",(me=H.container,window.getComputedStyle(me,null).getPropertyValue("direction")!=="rtl"||ye?null:"")),o(H.container,"v",H.options.vertical&&!ye?"":null),o(H.container,"disabled",H.options.disabled&&!ye?"":null)}function Q(){se()&&oe()}function se(){var ye=null;if(W.forEach(function(Le){Le.matches&&(ye=Le.__media)}),ye===ee)return!1;ee||H.emit("beforeOptionsChanged"),ee=ye;var me=ye?Z.breakpoints[ye]:Z;return H.options=M(M({},Z),me),k(),Ne(),ke(),ue(),!0}function q(ye){var me=S(ye);return(H.options.vertical?me.height:me.width)/H.size||1}function F(){return H.options.trackConfig.length}function te(ye){for(var me in ee=!1,Z=M(M({},U),ye),G.purge(),Y=H.size,W=[],Z.breakpoints||[]){var Le=window.matchMedia(me);Le.__media=me,W.push(Le),G.add(Le,"change",Q)}G.add(window,"orientationchange",je),G.add(window,"resize",Ee),se()}function ae(ye){H.animator.stop();var me=H.track.details;H.track.init(ye??(me?me.abs:0))}function oe(ye){ae(ye),H.emit("optionsChanged")}function le(ye,me){if(ye)return te(ye),void oe(me);Ne(),ke();var Le=F();ue(),F()!==Le?oe(me):ae(me),H.emit("updated")}function ue(){var ye=H.options.slides;if(typeof ye=="function")return H.options.trackConfig=ye(H.size,H.slides);for(var me=H.slides,Le=me.length,Qe=typeof ye=="number"?ye:E(ye,"number",Le,!0),he=[],Se=E(ye,"perView",1,!0),ve=E(ye,"spacing",0,!0)/H.size||0,Oe=Se==="auto"?ve:ve/Se,Re=E(ye,"origin","auto"),Ae=0,we=0;we<Qe;we++){var _e=Se==="auto"?q(me[we]):1/Se-ve+Oe,Ve=Re==="center"?.5-_e/2:Re==="auto"?0:Re;he.push({origin:Ve,size:_e,spacing:ve}),Ae+=_e}if(Ae+=ve*(Qe-1),Re==="auto"&&!H.options.loop&&Se!==1){var ze=0;he.map(function(it){var ut=Ae-ze;return ze+=it.size+ve,ut>=1||(it.origin=1-ut-(Ae>1?0:1-Ae)),it})}H.options.trackConfig=he}function Ee(){Ne();var ye=H.size;H.options.disabled||ye===Y||(Y=ye,le())}function je(){Ee(),setTimeout(Ee,500),setTimeout(Ee,2e3)}function Ne(){var ye=S(H.container);H.size=(H.options.vertical?ye.height:ye.width)||1}function ke(){H.slides=c(H.options.selector,H.container)}H.container=(ie=c(z,document)).length?ie[0]:null,H.destroy=function(){G.purge(),H.emit("destroyed"),k(!0)},H.prev=function(){H.moveToIdx(H.track.details.abs-1,!0)},H.next=function(){H.moveToIdx(H.track.details.abs+1,!0)},H.update=le,te(H.options)}}var B=function(z,U,H){try{return function(ee,Y){var Z,W={};return Z={emit:function(ie){W[ie]&&W[ie].forEach(function(k){k(Z)});var G=Z.options&&Z.options[ie];G&&G(Z)},moveToIdx:function(ie,G,k){var Q=Z.track.idxToDist(ie,G);if(Q){var se=Z.options.defaultAnimation;Z.animator.start([{distance:Q,duration:E(k||se,"duration",500),easing:E(k||se,"easing",function(q){return 1+--q*q*q*q*q})}])}},on:function(ie,G,k){k===void 0&&(k=!1),W[ie]||(W[ie]=[]);var Q=W[ie].indexOf(G);Q>-1?k&&delete W[ie][Q]:k||W[ie].push(G)},options:ee},function(){if(Z.track=_(Z),Z.animator=D(Z),Y)for(var ie=0,G=Y;ie<G.length;ie++)(0,G[ie])(Z);Z.track.init(Z.options.initial||0),Z.emit("created")}(),Z}(U,A([V(z,{drag:!0,mode:"snap",renderMode:"precision",rubberband:!0,selector:".keen-slider__slide"}),N,L,j],H||[],!0))}catch(ee){console.error(ee)}};return bx.useKeenSlider=function(z,U){var H=e.useRef(null),ee=e.useRef(!1),Y=e.useRef(z),Z=e.useCallback(function(W){W?(Y.current=z,H.current=new B(W,z,U),ee.current=!1):(H.current&&H.current.destroy&&H.current.destroy(),H.current=null)},[]);return e.useEffect(function(){O(Y.current,z)||(Y.current=z,H.current&&H.current.update(Y.current))},[z]),[Z,H]},bx}var HR=qte();const Gte=({message:e,colorCode:t,disableCheckout:a,handleAddToCart:r,handleRemoveFromCart:o})=>{const[c,f]=x.useState({}),[m,g]=x.useState({}),p=j=>{const L=/(https?:\/\/[^\s]+)/g;return j.split(L).map((N,V)=>L.test(N)?J.jsx("a",{href:N.trim(),style:{color:"#00b3bc"},target:"_blank",rel:"noopener noreferrer",className:"underline break-words",children:N},V):J.jsx("span",{children:N},V))},y=j=>{const L=j.trim();if(!L.includes("Name:")||!L.includes("VariantId"))return null;const N=L.match(/Name\s*[:\-]\s*(.+)/i),V=L.match(/Price\s*[:\-]\s*(.+)/i),B=L.match(/Link\s*[:\-]\s*(https?:\/\/[^\s]+)/i),z=L.match(/VariantId\s*[:\-]\s*(.+)/i),U=L.match(/variant_tag_name\s*[:\-]\s*(.+)/i),H=L.match(/options\s*[:\-]\s*([^|\r\n]+)/i),ee=L.match(/tag\s*[:\-]\s*(.+)/i);return!N||!V||!B||!z||!U?null:{name:N[1].trim(),price:V[1].trim(),link:B[1].trim(),image:"",variant_id:z[1].trim(),variant_tag_name:U[1].trim(),option:H?.[1]?.trim(),tag:ee?.[1]?.trim()}},S=x.useMemo(()=>{const j=e.split("|||").map(V=>V.trim()).filter(Boolean),L=[];let N=null;return j.forEach(V=>{if(V.startsWith("img - ")){const B=V.replace(/^img\s*[-:]\s*/,"").trim();if(N)N.image=B;else{const z=[...L].reverse().find(U=>U.type==="product");z&&(z.data.image=B)}}else if(V.includes("Name:")&&V.includes("VariantId")){const B=y(V);B&&(L.push({type:"product",data:B}),N=B)}else L.push({type:"text",data:V}),N=null}),L},[e]),E=x.useMemo(()=>{const j={};return S.forEach(L=>{if(L.type==="product"){const N=L.data;j[N.variant_tag_name]=j[N.variant_tag_name]||[],j[N.variant_tag_name].push(N)}}),j},[S]),T=(j,L=22)=>j.length>L?j.slice(0,L)+"...":j,[O,M]=x.useState(0),A=Object.keys(E).length,[D,_]=HR.useKeenSlider({loop:!1,mode:"free",slides:{perView:1,spacing:16},slideChanged(j){M(j.track.details.rel)}});return J.jsxs("div",{className:"space-y-6 mt-4 h-fit",children:[S.filter(j=>j.type==="text").map((j,L)=>J.jsx("p",{className:"whitespace-pre-wrap break-words",children:p(j.data)},L)),Object.keys(E).length>0&&J.jsxs(J.Fragment,{children:[Object.keys(E).length>1&&J.jsxs("div",{style:{display:"flex",margin:0,marginBottom:"6px",justifyContent:"space-between",paddingInline:"4px"},children:[J.jsx(Kr,{shape:"circle",icon:J.jsx(Xm,{}),onClick:()=>_.current?.prev(),disabled:O===0}),J.jsx(Kr,{shape:"circle",icon:J.jsx(K1,{}),onClick:()=>_.current?.next(),disabled:O===A-1})]}),J.jsx("div",{ref:D,className:"keen-slider",children:J.jsx(Fte,{groupedProducts:E,selectedVariants:m,setSelectedVariants:g,counts:c,setCounts:f,handleAddToCart:r,handleRemoveFromCart:o,colorCode:t,shortenName:T,sliderInstance:_,currentSlide:O,totalSlides:A,sliderRef:D,disableCheckout:a})})]})]})},L5=({message:e})=>{const t=e.find(r=>r.type==="image_url")?.image_url?.url,a=e?.isBusiness;return J.jsx("div",{children:J.jsx("div",{children:t&&J.jsx("div",{className:"mb-2 bg-transparent text-white ",children:J.jsx("img",{src:t,alt:"Chat image",style:{width:200},className:`rounded-md bg-transparent mt-2 max-w-xs ${a?"border border-gray-300 shadow-sm":""}`})})})})},Xte=({message:e,colorCode:t})=>{const a=e.find(o=>o.type==="text")?.text,r=o=>{const c=/(https?:\/\/[^\s]+)/g;return o.split(c).map((f,m)=>c.test(f)?J.jsx("a",{href:f.trim(),style:{color:t},target:"_blank",rel:"noopener noreferrer",className:"underline break-words",children:f},m):J.jsx("span",{children:f},m))};return J.jsx(J.Fragment,{children:a&&J.jsx("div",{style:{color:"white",border:1,backgroundColor:t,paddingTop:10,paddingBottom:10,paddingInline:14,maxWidth:"85%",lineHeight:1.4,borderRadius:"16px",wordBreak:"break-word"},children:J.jsx("p",{children:r(a)})})})},Yte=({link:e,colorCode:t,transcription:a})=>{const r=x.useRef(null),o=x.useRef(null),[c,f]=x.useState(!1),[m,g]=x.useState(!1);x.useEffect(()=>{if(r.current)return o.current?.destroy(),o.current=sp.create({container:r.current,waveColor:"white",progressColor:"white",cursorWidth:0,barWidth:3,barHeight:1.5,barGap:2,height:40,interact:!0}),o.current.load(e),o.current.on("finish",()=>f(!1)),()=>{o.current?.destroy()}},[e,t]);const p=()=>{o.current&&(o.current.playPause(),f(y=>!y))};return J.jsxs("div",{style:{backgroundColor:t,padding:"12px",borderRadius:"20px",color:"white",maxWidth:"350px",marginBottom:"16px"},children:[J.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[J.jsx("button",{onClick:p,style:{background:"transparent",border:"none",color:"white",marginRight:"12px",cursor:"pointer"},children:c?J.jsx(uO,{style:{fontSize:"24px"}}):J.jsx(cO,{style:{fontSize:"24px"}})}),J.jsx("div",{ref:r,style:{width:"130px",height:"40px",overflow:"hidden",color:"white"}})]}),a&&J.jsxs("div",{style:{marginTop:"12px",fontSize:"14px",color:"rgba(255,255,255,0.85)"},children:[J.jsx("button",{onClick:()=>g(!m),style:{background:"none",border:"none",color:"white",textDecoration:"underline",fontSize:"13px",cursor:"pointer",padding:0},children:m?"Hide transcript":"Show transcript"}),m&&J.jsx("p",{style:{marginTop:"6px",lineHeight:"1.4"},children:a})]})]})},Wte=({status:e,user:t})=>{if(!e||!t)return null;let a=`${t} is ${e}`;return e==="typing"?a=`${t} is typing...`:a="",J.jsx(J.Fragment,{children:a&&J.jsx("div",{className:"flex justify-center mb-2",children:J.jsx("span",{className:"px-3 py-1 bg-gray-100 text-gray-500 text-sm rounded-full",children:a})})})},Zte=({message:e})=>{const t=r=>{const o=/(https?:\/\/[^\s]+)/g;return r?.split(o).map((c,f)=>o.test(c)?J.jsx("a",{href:c.trim(),style:{color:"#00b3bc"},target:"_blank",rel:"noopener noreferrer",className:"underline break-words",children:c},f):J.jsx("span",{children:c},f))};if(e?.startsWith("Add this to cart for me")&&e?.includes("name:")){const o=e?.match(/name:([^,]+)/i)?.[1]?.trim()||"Product";return J.jsxs("div",{style:{backgroundColor:"#E8F5E9",border:"1px solid #C8E6C9",borderRadius:"12px",padding:"12px 16px",color:"#2E7D32",fontWeight:500,fontSize:"15px",maxWidth:"360px",margin:"0 auto",textAlign:"center"},children:["✅ ",J.jsx("strong",{children:o})," has been added to your cart."]})}return J.jsx("p",{style:{color:"white"},children:t(e)})};/**
|
|
653
653
|
* @license lucide-react v0.525.0 - ISC
|
|
654
654
|
*
|
|
655
655
|
* This source code is licensed under the ISC license.
|
|
@@ -681,4 +681,4 @@ html body {
|
|
|
681
681
|
userAgent: `).concat(navigator.userAgent,`
|
|
682
682
|
timeBetweenLoadAndGet: `).concat(o-a,`
|
|
683
683
|
visitorId: `).concat(f.visitorId,`
|
|
684
|
-
components: `).concat(f2(c),"\n```")),[2,f]}})})}}}function Mre(){if(!(window.__fpjs_d_m||Math.random()>=.001))try{var e=new XMLHttpRequest;e.open("get","https://m1.openfpcdn.io/fingerprintjs/v".concat(P5,"/npm-monitoring"),!0),e.send()}catch(t){console.error(t)}}function _re(e){var t;return e===void 0&&(e={}),nu(this,void 0,void 0,function(){var a,r,o;return au(this,function(c){switch(c.label){case 0:return(!((t=e.monitoring)!==null&&t!==void 0)||t)&&Mre(),a=e.delayFallback,r=e.debug,[4,Rre(a)];case 1:return c.sent(),o=Sre({cache:{},debug:r}),[2,Are(o,r)]}})})}var Dre={load:_re,hashComponents:d2,componentsToDebugString:f2};const Nre=()=>{const[e,t]=x.useState(!
|
|
684
|
+
components: `).concat(f2(c),"\n```")),[2,f]}})})}}}function Mre(){if(!(window.__fpjs_d_m||Math.random()>=.001))try{var e=new XMLHttpRequest;e.open("get","https://m1.openfpcdn.io/fingerprintjs/v".concat(P5,"/npm-monitoring"),!0),e.send()}catch(t){console.error(t)}}function _re(e){var t;return e===void 0&&(e={}),nu(this,void 0,void 0,function(){var a,r,o;return au(this,function(c){switch(c.label){case 0:return(!((t=e.monitoring)!==null&&t!==void 0)||t)&&Mre(),a=e.delayFallback,r=e.debug,[4,Rre(a)];case 1:return c.sent(),o=Sre({cache:{},debug:r}),[2,Are(o,r)]}})})}var Dre={load:_re,hashComponents:d2,componentsToDebugString:f2};const Nre=()=>{const[e,t]=x.useState(!1),[a,r]=x.useState("sessions"),[o,c]=x.useState(null),[f,m]=x.useState(!1),[g,p]=x.useState(""),[y,S]=x.useState(""),[E,T]=x.useState(!1),{chatbotLogo:O,colorCode:M,messagesSuggestions:A,disableForm:D,merchantPhone:_,userType:j,isFetchingDetails:L,calendly:N,disbleCheckout:V}=zH(),[B,z]=x.useState(null),U=J.jsx(Ks,{style:{fontSize:24,color:M||"#7F28F8"},spin:!0}),H=()=>{if(!D&&!f){r("create");return}else{const W=crypto.randomUUID();c(W),S(O),p("Ai Agent"),T(!0),r("messenger")}};x.useEffect(()=>{(async()=>{try{let ie=localStorage.getItem("visitor_id");ie||(ie=(await(await Dre.load()).get()).visitorId,localStorage.setItem("visitor_id",ie));const k=await(await fetch(`${ii.apiUrl}register-ip/`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({visitor_id:ie})})).json();k.visitor&&k.country?(localStorage.setItem("country",k.country),z({visitorId:k.visitor,country:k.country}),m(k.has_user_info||!1)):console.warn("Backend did not return country")}catch(ie){console.error("Failed to fetch or send visitor info",ie)}})()},[]);const ee=(W,ie,G)=>{c(W),p(ie),S(G),T(!1),r("messenger")};x.useEffect(()=>{const W=ie=>{const G=ie.data||{};G.type==="JAWEB_CHAT"&&(G.action==="open-ready"?t(!0):G.action==="closed"&&t(!1))};return window.addEventListener("message",W),()=>window.removeEventListener("message",W)},[]);const Y=()=>{window.parent?.postMessage({type:"JAWEB_CHAT",action:"open"},"*")},Z=()=>{window.parent?.postMessage({type:"JAWEB_CHAT",action:"close"},"*")};return x.useEffect(()=>{L||window.parent?.postMessage({type:"JAWEB_CHAT",action:"ready-confirm"},"*")},[L]),J.jsx("div",{children:e&&J.jsx("div",{className:"chatbot-box",children:L?J.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:300},children:J.jsx(Wu,{indicator:U,tip:"..."})}):J.jsxs(Jz,{mode:"sync",children:[a==="sessions"&&J.jsx(Yi.div,{initial:{opacity:0,x:-30},animate:{opacity:1,x:0},exit:{opacity:0,x:30},transition:{duration:.3},style:{height:"100%"},children:J.jsx(YZ,{chatbotLogo:O,Phone:_||"",colorCode:M,visitorId:B?.visitorId||"",Opened:e,setOpen:W=>W?Y():Z(),onNewSession:H,onSessionSelect:ee})},"sessions"),a==="create"&&J.jsx(Yi.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},exit:{opacity:0,y:-30},transition:{duration:.3},children:J.jsx(Nte,{colorCode:M,visitorId:B?.visitorId||"",country:B?.country||"",onBack:()=>r("sessions"),onCreate:W=>{c(W.session_id),m(W.hasInfo),r("messenger")}})},"create"),a==="messenger"&&o&&J.jsx(Yi.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.3},children:J.jsx(Sne,{sessionId:o,chatbotLogo:y||O,agentName:g||"Ai Assistant",colorCode:M,messagesSuggestions:A,newSession:E,disableForm:D,calendly:N??"",setOpen:W=>W?Y():Z(),setNewSession:T,Opened:e,setView:()=>r("sessions"),userType:j,disbleCheckout:V})},"messenger")]})})})},h2="jaweb-chatbot-container";if(!document.getElementById(h2)){const e=document.createElement("div");e.id=h2,document.body.appendChild(e),O8.createRoot(e).render(J.jsx(Nre,{}))}})();
|
package/package.json
CHANGED
package/src/Chatbot/Chatbot.tsx
CHANGED
|
@@ -11,7 +11,7 @@ import { Spin } from 'antd';
|
|
|
11
11
|
import { motion, AnimatePresence } from 'framer-motion';
|
|
12
12
|
|
|
13
13
|
const Chatbot: React.FC = () => {
|
|
14
|
-
const [open, setOpen] = useState(
|
|
14
|
+
const [open, setOpen] = useState(false);
|
|
15
15
|
const [viewMode, setViewMode] = useState<'sessions' | 'create' | 'messenger'>('sessions');
|
|
16
16
|
const [activeSessionId, setActiveSessionId] = useState<string | null>(null);
|
|
17
17
|
const [HasInfo, setHasInfo] = useState(false);
|
|
@@ -249,7 +249,7 @@ const ProductCarousel: FC<Props> = ({
|
|
|
249
249
|
{/* Try On panel */}
|
|
250
250
|
{canTryOn && isTryOnOpen && (
|
|
251
251
|
<div className="mt-4">
|
|
252
|
-
<TryOnBox productImage={currentVariant.image} />
|
|
252
|
+
<TryOnBox productID={currentVariant.variant_id} productImage={currentVariant.image} />
|
|
253
253
|
</div>
|
|
254
254
|
)}
|
|
255
255
|
</div>
|
|
@@ -5,9 +5,10 @@ import config from '../../../../hooks/config';
|
|
|
5
5
|
|
|
6
6
|
interface TryOnProps {
|
|
7
7
|
productImage: string; // product variant image URL
|
|
8
|
+
productID:string;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
const TryOnBox: React.FC<TryOnProps> = ({ productImage }) => {
|
|
11
|
+
const TryOnBox: React.FC<TryOnProps> = ({ productImage,productID }) => {
|
|
11
12
|
const [userImage, setUserImage] = useState<string | null>(null);
|
|
12
13
|
const [resultImage, setResultImage] = useState<string | null>(null);
|
|
13
14
|
const [loading, setLoading] = useState(false);
|
|
@@ -28,6 +29,8 @@ const TryOnBox: React.FC<TryOnProps> = ({ productImage }) => {
|
|
|
28
29
|
body: JSON.stringify({
|
|
29
30
|
userImageUrl: base64UserImage, // can also be a hosted URL
|
|
30
31
|
productImageUrl: productImage, // product image URL
|
|
32
|
+
productId:productID,
|
|
33
|
+
username:localStorage.getItem('company_username')
|
|
31
34
|
}),
|
|
32
35
|
});
|
|
33
36
|
|