tybotflow-widget 0.6.5 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -64157,6 +64157,7 @@ const bs = "https://api.tybotflow.com/api/v1", ouA = "https://api.tybotflow.com/
64157
64157
  );
64158
64158
  default:
64159
64159
  return /* @__PURE__ */ N.jsx(KQ, { remarkPlugins: [pQ], components: lE, children: V.text?.replace(/\n/g, `
64160
+
64160
64161
  `) });
64161
64162
  }
64162
64163
  else
@@ -64247,15 +64248,18 @@ const bs = "https://api.tybotflow.com/api/v1", ouA = "https://api.tybotflow.com/
64247
64248
  );
64248
64249
  default:
64249
64250
  return /* @__PURE__ */ N.jsx(KQ, { remarkPlugins: [pQ], components: lE, children: V.text?.replace(/\n/g, `
64251
+
64250
64252
  `) });
64251
64253
  }
64252
64254
  } catch {
64253
64255
  return /* @__PURE__ */ N.jsx(KQ, { remarkPlugins: [pQ], components: lE, children: V.text?.replace(/\n/g, `
64256
+
64254
64257
  `) });
64255
64258
  }
64256
64259
  case "single-choice":
64257
64260
  return /* @__PURE__ */ N.jsxs(N.Fragment, { children: [
64258
64261
  /* @__PURE__ */ N.jsx(KQ, { remarkPlugins: [pQ], components: lE, children: V.text?.replace(/\n/g, `
64262
+
64259
64263
  `) || "" }),
64260
64264
  /* @__PURE__ */ N.jsx("div", { className: "flex flex-wrap", dir: fE(V.text || "") ? "rtl" : "ltr", children: V.choices?.map((FA, WA) => /* @__PURE__ */ N.jsx(
64261
64265
  "button",
@@ -64301,6 +64305,7 @@ const bs = "https://api.tybotflow.com/api/v1", ouA = "https://api.tybotflow.com/
64301
64305
  case "dropdown":
64302
64306
  return /* @__PURE__ */ N.jsxs(N.Fragment, { children: [
64303
64307
  /* @__PURE__ */ N.jsx(KQ, { remarkPlugins: [pQ], components: lE, children: V.message?.replace(/\n/g, `
64308
+
64304
64309
  `) }),
64305
64310
  /* @__PURE__ */ N.jsx(
64306
64311
  IlA,
@@ -64400,6 +64405,7 @@ const bs = "https://api.tybotflow.com/api/v1", ouA = "https://api.tybotflow.com/
64400
64405
  switch (V.json?.type) {
64401
64406
  case "text":
64402
64407
  return /* @__PURE__ */ N.jsx(KQ, { remarkPlugins: [pQ], components: lE, children: V.json.content.replace(/\n/g, `
64408
+
64403
64409
  `) });
64404
64410
  case "image":
64405
64411
  return /* @__PURE__ */ N.jsx("div", { className: "relative group", children: /* @__PURE__ */ N.jsx(
@@ -65005,6 +65011,7 @@ Options:
65005
65011
  color: EA
65006
65012
  },
65007
65013
  children: /* @__PURE__ */ N.jsx(KQ, { remarkPlugins: [pQ], components: lE, children: typeof V.content == "string" ? V.content.replace(/\n/g, `
65014
+
65008
65015
  `) : "" })
65009
65016
  }
65010
65017
  ) : typeof V.content == "object" ? V.content.map((KA, FA) => KA.type === "image" ? /* @__PURE__ */ N.jsx("div", { className: "mb-1 w-72", children: wt(KA) }, FA) : /* @__PURE__ */ N.jsx(
@@ -65035,6 +65042,7 @@ Options:
65035
65042
  color: W
65036
65043
  },
65037
65044
  children: /* @__PURE__ */ N.jsx(KQ, { remarkPlugins: [pQ], components: lE, children: V.content.replace(/\n/g, `
65045
+
65038
65046
  `) })
65039
65047
  }
65040
65048
  ) : null,
package/dist/index.umd.js CHANGED
@@ -608,11 +608,17 @@ end`};A.events.push(["putFont",function(I){(function(B){var t=B.font,o=B.out,a=B
608
608
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
609
609
  PERFORMANCE OF THIS SOFTWARE.
610
610
  ***************************************************************************** */function YW(g,A){const[i,e]=gg.useState(null),E=gg.useMemo(()=>Object.entries(A).flat(),[A]);return gg.useEffect(()=>{if(!g?.current)return;const I=wS.create(Object.assign(Object.assign({},A),{container:g.current}));return e(I),()=>{I.destroy()}},[g,...E]),i}const GW=/^on([A-Z])/,XMA=g=>GW.test(g);function _MA(g,A){const i=gg.useMemo(()=>Object.entries(A).flat(),[A]);gg.useEffect(()=>{if(!g)return;const e=Object.entries(A);if(!e.length)return;const E=e.map(([I,B])=>{const t=I.replace(GW,(o,a)=>a.toLowerCase());return g.on(t,(...o)=>B(g,...o))});return()=>{E.forEach(I=>I())}},[g,...i])}gg.memo(g=>{const A=gg.useRef(null),[i,e]=function(E){return gg.useMemo(()=>{const I=Object.assign({},E),B=Object.assign({},E);for(const t in I)XMA(t)?delete I[t]:delete B[t];return[I,B]},[E])}(g);return _MA(YW(A,i),e),N.jsx("div",{ref:A})});function $MA(g){var{container:A}=g;const i=YW(A,function(E,I){var B={};for(var t in E)Object.prototype.hasOwnProperty.call(E,t)&&I.indexOf(t)<0&&(B[t]=E[t]);if(E!=null&&typeof Object.getOwnPropertySymbols=="function"){var o=0;for(t=Object.getOwnPropertySymbols(E);o<t.length;o++)I.indexOf(t[o])<0&&Object.prototype.propertyIsEnumerable.call(E,t[o])&&(B[t[o]]=E[t[o]])}return B}(g,["container"])),e=function(E){const[I,B]=gg.useState(!1),[t,o]=gg.useState(!1),[a,r]=gg.useState(!1),[s,w]=gg.useState(0);return gg.useEffect(()=>{if(!E)return;const M=[E.on("load",()=>{B(!1),o(!1),w(0)}),E.on("ready",()=>{B(!0),o(!1),r(!1),w(0)}),E.on("finish",()=>{r(!0)}),E.on("play",()=>{o(!0)}),E.on("pause",()=>{o(!1)}),E.on("timeupdate",()=>{w(E.getCurrentTime())}),E.on("destroy",()=>{B(!1),o(!1)})];return()=>{M.forEach(c=>c())}},[E]),gg.useMemo(()=>({isReady:I,isPlaying:t,hasFinished:a,currentTime:s}),[t,a,s,I])}(i);return gg.useMemo(()=>Object.assign(Object.assign({},e),{wavesurfer:i}),[e,i])}const FW=({src:g,mainColor:A,secondaryColor:i,controlsColor:e})=>{const E=gg.useRef(null),[I,B]=gg.useState(1),{wavesurfer:t,isPlaying:o}=$MA({container:E,waveColor:A,progressColor:i,barWidth:2,height:50,url:g}),a=()=>{t&&t.playPause()},r=()=>{const M=I===0?1:0;B(M),t?.setVolume(M)},s=()=>{t?.skip(-.096)},w=()=>{t?.skip(.096)};return N.jsxs("div",{className:"flex w-full flex-col items-center rounded-xl pt-1",children:[N.jsx("div",{ref:E,className:"w-full px-2"}),N.jsxs("div",{className:"flex w-full items-center justify-between",children:[N.jsx("div",{className:"relative flex items-center",children:N.jsx("button",{className:"transition-colors",style:{color:e},onClick:r,"aria-label":"Toggle volume",children:I===0?N.jsx(JiA,{size:20}):N.jsx(kiA,{size:20})})}),N.jsxs("div",{className:"-ml-9 flex flex-1 cursor-auto justify-center gap-2 rounded-full py-2 text-white",children:[N.jsx("button",{onClick:s,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:e},"aria-label":"Step back",children:N.jsx(SiA,{})}),N.jsx("button",{onClick:a,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:e},"aria-label":o?"Pause":"Play",children:o?N.jsx(YiA,{}):N.jsx(FiA,{})}),N.jsx("button",{onClick:w,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:e},"aria-label":"Step forward",children:N.jsx(KiA,{})})]})]})]})},AhA=({attachment:g,formatFileSize:A,mainColor:i,secondaryColor:e,controlsColor:E})=>{const{type:I,url:B,name:t,size:o}=g;switch(I){case"image":return N.jsxs("div",{className:"relative group",children:[N.jsx("img",{src:B,alt:t,className:"max-w-xs max-h-48 size-full rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(B,"_blank")}),N.jsx("div",{className:"absolute bottom-2 left-2 bg-black bg-opacity-60 text-white text-xs px-2 py-1 rounded",children:A(o)})]});case"video":return N.jsxs("div",{className:"max-w-xs",children:[N.jsx("video",{src:B,controls:!0,className:"w-full max-h-48 rounded-lg",preload:"metadata",onError:()=>{console.error("Video failed to load:",B)},children:"Your browser does not support the video tag."}),N.jsxs("div",{className:"flex text-xs text-white mt-1 w-full overflow-hidden whitespace-nowrap text-ellipsis",children:[N.jsx("span",{className:"block w-full overflow-hidden whitespace-nowrap text-ellipsis",title:t,children:t}),N.jsxs("span",{className:"ml-2",children:["• ",A(o)]})]})]});case"audio":return N.jsxs("div",{className:"bg-gray-800 bg-opacity-70 p-3 rounded-lg flex-1 w-full",children:[N.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[N.jsx(qu,{className:"w-4 h-4",style:{color:i}}),N.jsx("span",{className:"text-sm font-medium truncate text-white",title:t,children:t})]}),N.jsx(FW,{src:B,mainColor:i,secondaryColor:e,controlsColor:E}),N.jsx("p",{className:"text-xs text-gray-400 mt-1",children:A(o)})]});case"document":return N.jsx("div",{className:"bg-gray-800 bg-opacity-50 p-3 rounded-lg max-w-xs cursor-pointer hover:bg-opacity-70 transition-colors",onClick:()=>window.open(B,"_blank"),children:N.jsxs("div",{className:"flex items-center gap-3",children:[N.jsx("div",{className:"w-10 h-10 bg-purple-600 rounded-lg flex items-center justify-center",children:N.jsx(ns,{className:"w-5 h-5 text-white"})}),N.jsxs("div",{className:"flex-1 min-w-0",children:[N.jsx("p",{className:"text-sm font-medium truncate text-white",children:t}),N.jsx("p",{className:"text-xs text-gray-400",children:A(o)})]})]})});default:return null}},ghA=gg.memo(({attachment:g,onRemove:A})=>N.jsxs("div",{className:"relative group w-24 h-24 rounded-xl overflow-hidden bg-gray-900 shadow-md border border-gray-700",children:[g.type==="image"&&g.url?N.jsx("img",{src:g.url,alt:g.name,className:"w-full h-full object-cover"}):N.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center text-gray-300 px-1 text-center text-xs",children:[g.type==="video"&&N.jsx(ay,{className:"w-5 h-5 mb-1 text-red-400"}),g.type==="audio"&&N.jsx(qu,{className:"w-5 h-5 mb-1 text-green-400"}),g.type==="document"&&N.jsx(Cy,{className:"w-5 h-5 mb-1 text-yellow-400"}),N.jsx("span",{className:"w-full truncate",title:g.name,children:g.name})]}),N.jsx("button",{onClick:A,className:"absolute top-1 right-1 w-5 h-5 bg-black bg-opacity-50 rounded-full text-white flex items-center justify-center hover:bg-opacity-80",title:"Remove",children:N.jsx(ha,{className:"w-3 h-3"})})]})),Kt=Object.create(null);Kt.open="0",Kt.close="1",Kt.ping="2",Kt.pong="3",Kt.message="4",Kt.upgrade="5",Kt.noop="6";const gc=Object.create(null);Object.keys(Kt).forEach(g=>{gc[Kt[g]]=g});const cS={type:"error",data:"parser error"},mW=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",UW=typeof ArrayBuffer=="function",dW=g=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(g):g&&g.buffer instanceof ArrayBuffer,DS=({type:g,data:A},i,e)=>mW&&A instanceof Blob?i?e(A):SW(A,e):UW&&(A instanceof ArrayBuffer||dW(A))?i?e(A):SW(new Blob([A]),e):e(Kt[g]+(A||"")),SW=(g,A)=>{const i=new FileReader;return i.onload=function(){const e=i.result.split(",")[1];A("b"+(e||""))},i.readAsDataURL(g)};function KW(g){return g instanceof Uint8Array?g:g instanceof ArrayBuffer?new Uint8Array(g):new Uint8Array(g.buffer,g.byteOffset,g.byteLength)}let lS;function ihA(g,A){if(mW&&g.data instanceof Blob)return g.data.arrayBuffer().then(KW).then(A);if(UW&&(g.data instanceof ArrayBuffer||dW(g.data)))return A(KW(g.data));DS(g,!1,i=>{lS||(lS=new TextEncoder),A(lS.encode(i))})}const pW="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ws=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let g=0;g<pW.length;g++)Ws[pW.charCodeAt(g)]=g;const ehA=g=>{let A=g.length*.75,i=g.length,e,E=0,I,B,t,o;g[g.length-1]==="="&&(A--,g[g.length-2]==="="&&A--);const a=new ArrayBuffer(A),r=new Uint8Array(a);for(e=0;e<i;e+=4)I=Ws[g.charCodeAt(e)],B=Ws[g.charCodeAt(e+1)],t=Ws[g.charCodeAt(e+2)],o=Ws[g.charCodeAt(e+3)],r[E++]=I<<2|B>>4,r[E++]=(B&15)<<4|t>>2,r[E++]=(t&3)<<6|o&63;return a},EhA=typeof ArrayBuffer=="function",uS=(g,A)=>{if(typeof g!="string")return{type:"message",data:kW(g,A)};const i=g.charAt(0);return i==="b"?{type:"message",data:IhA(g.substring(1),A)}:gc[i]?g.length>1?{type:gc[i],data:g.substring(1)}:{type:gc[i]}:cS},IhA=(g,A)=>{if(EhA){const i=ehA(g);return kW(i,A)}else return{base64:!0,data:g}},kW=(g,A)=>{switch(A){case"blob":return g instanceof Blob?g:new Blob([g]);case"arraybuffer":default:return g instanceof ArrayBuffer?g:g.buffer}},JW="",BhA=(g,A)=>{const i=g.length,e=new Array(i);let E=0;g.forEach((I,B)=>{DS(I,!1,t=>{e[B]=t,++E===i&&A(e.join(JW))})})},ChA=(g,A)=>{const i=g.split(JW),e=[];for(let E=0;E<i.length;E++){const I=uS(i[E],A);if(e.push(I),I.type==="error")break}return e};function thA(){return new TransformStream({transform(g,A){ihA(g,i=>{const e=i.length;let E;if(e<126)E=new Uint8Array(1),new DataView(E.buffer).setUint8(0,e);else if(e<65536){E=new Uint8Array(3);const I=new DataView(E.buffer);I.setUint8(0,126),I.setUint16(1,e)}else{E=new Uint8Array(9);const I=new DataView(E.buffer);I.setUint8(0,127),I.setBigUint64(1,BigInt(e))}g.data&&typeof g.data!="string"&&(E[0]|=128),A.enqueue(E),A.enqueue(i)})}})}let RS;function ic(g){return g.reduce((A,i)=>A+i.length,0)}function ec(g,A){if(g[0].length===A)return g.shift();const i=new Uint8Array(A);let e=0;for(let E=0;E<A;E++)i[E]=g[0][e++],e===g[0].length&&(g.shift(),e=0);return g.length&&e<g[0].length&&(g[0]=g[0].slice(e)),i}function ohA(g,A){RS||(RS=new TextDecoder);const i=[];let e=0,E=-1,I=!1;return new TransformStream({transform(B,t){for(i.push(B);;){if(e===0){if(ic(i)<1)break;const o=ec(i,1);I=(o[0]&128)===128,E=o[0]&127,E<126?e=3:E===126?e=1:e=2}else if(e===1){if(ic(i)<2)break;const o=ec(i,2);E=new DataView(o.buffer,o.byteOffset,o.length).getUint16(0),e=3}else if(e===2){if(ic(i)<8)break;const o=ec(i,8),a=new DataView(o.buffer,o.byteOffset,o.length),r=a.getUint32(0);if(r>Math.pow(2,21)-1){t.enqueue(cS);break}E=r*Math.pow(2,32)+a.getUint32(4),e=3}else{if(ic(i)<E)break;const o=ec(i,E);t.enqueue(uS(I?o:RS.decode(o),A)),e=0}if(E===0||E>g){t.enqueue(cS);break}}}})}const NW=4;function HE(g){if(g)return QhA(g)}function QhA(g){for(var A in HE.prototype)g[A]=HE.prototype[A];return g}HE.prototype.on=HE.prototype.addEventListener=function(g,A){return this._callbacks=this._callbacks||{},(this._callbacks["$"+g]=this._callbacks["$"+g]||[]).push(A),this},HE.prototype.once=function(g,A){function i(){this.off(g,i),A.apply(this,arguments)}return i.fn=A,this.on(g,i),this},HE.prototype.off=HE.prototype.removeListener=HE.prototype.removeAllListeners=HE.prototype.removeEventListener=function(g,A){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var i=this._callbacks["$"+g];if(!i)return this;if(arguments.length==1)return delete this._callbacks["$"+g],this;for(var e,E=0;E<i.length;E++)if(e=i[E],e===A||e.fn===A){i.splice(E,1);break}return i.length===0&&delete this._callbacks["$"+g],this},HE.prototype.emit=function(g){this._callbacks=this._callbacks||{};for(var A=new Array(arguments.length-1),i=this._callbacks["$"+g],e=1;e<arguments.length;e++)A[e-1]=arguments[e];if(i){i=i.slice(0);for(var e=0,E=i.length;e<E;++e)i[e].apply(this,A)}return this},HE.prototype.emitReserved=HE.prototype.emit,HE.prototype.listeners=function(g){return this._callbacks=this._callbacks||{},this._callbacks["$"+g]||[]},HE.prototype.hasListeners=function(g){return!!this.listeners(g).length};const Ec=typeof Promise=="function"&&typeof Promise.resolve=="function"?A=>Promise.resolve().then(A):(A,i)=>i(A,0),eC=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),ahA="arraybuffer";function kSA(){}function OW(g,...A){return A.reduce((i,e)=>(g.hasOwnProperty(e)&&(i[e]=g[e]),i),{})}const rhA=eC.setTimeout,nhA=eC.clearTimeout;function Ic(g,A){A.useNativeTimers?(g.setTimeoutFn=rhA.bind(eC),g.clearTimeoutFn=nhA.bind(eC)):(g.setTimeoutFn=eC.setTimeout.bind(eC),g.clearTimeoutFn=eC.clearTimeout.bind(eC))}const shA=1.33;function MhA(g){return typeof g=="string"?hhA(g):Math.ceil((g.byteLength||g.size)*shA)}function hhA(g){let A=0,i=0;for(let e=0,E=g.length;e<E;e++)A=g.charCodeAt(e),A<128?i+=1:A<2048?i+=2:A<55296||A>=57344?i+=3:(e++,i+=4);return i}function yW(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function whA(g){let A="";for(let i in g)g.hasOwnProperty(i)&&(A.length&&(A+="&"),A+=encodeURIComponent(i)+"="+encodeURIComponent(g[i]));return A}function chA(g){let A={},i=g.split("&");for(let e=0,E=i.length;e<E;e++){let I=i[e].split("=");A[decodeURIComponent(I[0])]=decodeURIComponent(I[1])}return A}class DhA extends Error{constructor(A,i,e){super(A),this.description=i,this.context=e,this.type="TransportError"}}class YS extends HE{constructor(A){super(),this.writable=!1,Ic(this,A),this.opts=A,this.query=A.query,this.socket=A.socket,this.supportsBinary=!A.forceBase64}onError(A,i,e){return super.emitReserved("error",new DhA(A,i,e)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(A){this.readyState==="open"&&this.write(A)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(A){const i=uS(A,this.socket.binaryType);this.onPacket(i)}onPacket(A){super.emitReserved("packet",A)}onClose(A){this.readyState="closed",super.emitReserved("close",A)}pause(A){}createUri(A,i={}){return A+"://"+this._hostname()+this._port()+this.opts.path+this._query(i)}_hostname(){const A=this.opts.hostname;return A.indexOf(":")===-1?A:"["+A+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(A){const i=whA(A);return i.length?"?"+i:""}}class lhA extends YS{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(A){this.readyState="pausing";const i=()=>{this.readyState="paused",A()};if(this._polling||!this.writable){let e=0;this._polling&&(e++,this.once("pollComplete",function(){--e||i()})),this.writable||(e++,this.once("drain",function(){--e||i()}))}else i()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(A){const i=e=>{if(this.readyState==="opening"&&e.type==="open"&&this.onOpen(),e.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(e)};ChA(A,this.socket.binaryType).forEach(i),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){const A=()=>{this.write([{type:"close"}])};this.readyState==="open"?A():this.once("open",A)}write(A){this.writable=!1,BhA(A,i=>{this.doWrite(i,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const A=this.opts.secure?"https":"http",i=this.query||{};return this.opts.timestampRequests!==!1&&(i[this.opts.timestampParam]=yW()),!this.supportsBinary&&!i.sid&&(i.b64=1),this.createUri(A,i)}}let xW=!1;try{xW=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const uhA=xW;function RhA(){}class YhA extends lhA{constructor(A){if(super(A),typeof location<"u"){const i=location.protocol==="https:";let e=location.port;e||(e=i?"443":"80"),this.xd=typeof location<"u"&&A.hostname!==location.hostname||e!==A.port}}doWrite(A,i){const e=this.request({method:"POST",data:A});e.on("success",i),e.on("error",(E,I)=>{this.onError("xhr post error",E,I)})}doPoll(){const A=this.request();A.on("data",this.onData.bind(this)),A.on("error",(i,e)=>{this.onError("xhr poll error",i,e)}),this.pollXhr=A}}let Xr=class Ul extends HE{constructor(A,i,e){super(),this.createRequest=A,Ic(this,e),this._opts=e,this._method=e.method||"GET",this._uri=i,this._data=e.data!==void 0?e.data:null,this._create()}_create(){var A;const i=OW(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");i.xdomain=!!this._opts.xd;const e=this._xhr=this.createRequest(i);try{e.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){e.setDisableHeaderCheck&&e.setDisableHeaderCheck(!0);for(let E in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(E)&&e.setRequestHeader(E,this._opts.extraHeaders[E])}}catch{}if(this._method==="POST")try{e.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{e.setRequestHeader("Accept","*/*")}catch{}(A=this._opts.cookieJar)===null||A===void 0||A.addCookies(e),"withCredentials"in e&&(e.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(e.timeout=this._opts.requestTimeout),e.onreadystatechange=()=>{var E;e.readyState===3&&((E=this._opts.cookieJar)===null||E===void 0||E.parseCookies(e.getResponseHeader("set-cookie"))),e.readyState===4&&(e.status===200||e.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof e.status=="number"?e.status:0)},0))},e.send(this._data)}catch(E){this.setTimeoutFn(()=>{this._onError(E)},0);return}typeof document<"u"&&(this._index=Ul.requestsCount++,Ul.requests[this._index]=this)}_onError(A){this.emitReserved("error",A,this._xhr),this._cleanup(!0)}_cleanup(A){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=RhA,A)try{this._xhr.abort()}catch{}typeof document<"u"&&delete Ul.requests[this._index],this._xhr=null}}_onLoad(){const A=this._xhr.responseText;A!==null&&(this.emitReserved("data",A),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}};if(Xr.requestsCount=0,Xr.requests={},typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",VW);else if(typeof addEventListener=="function"){const g="onpagehide"in eC?"pagehide":"unload";addEventListener(g,VW,!1)}}function VW(){for(let g in Xr.requests)Xr.requests.hasOwnProperty(g)&&Xr.requests[g].abort()}const GhA=function(){const g=qW({xdomain:!1});return g&&g.responseType!==null}();class FhA extends YhA{constructor(A){super(A);const i=A&&A.forceBase64;this.supportsBinary=GhA&&!i}request(A={}){return Object.assign(A,{xd:this.xd},this.opts),new Xr(qW,this.uri(),A)}}function qW(g){const A=g.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!A||uhA))return new XMLHttpRequest}catch{}if(!A)try{return new eC[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}const HW=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class mhA extends YS{get name(){return"websocket"}doOpen(){const A=this.uri(),i=this.opts.protocols,e=HW?{}:OW(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(e.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(A,i,e)}catch(E){return this.emitReserved("error",E)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=A=>this.onClose({description:"websocket connection closed",context:A}),this.ws.onmessage=A=>this.onData(A.data),this.ws.onerror=A=>this.onError("websocket error",A)}write(A){this.writable=!1;for(let i=0;i<A.length;i++){const e=A[i],E=i===A.length-1;DS(e,this.supportsBinary,I=>{try{this.doWrite(e,I)}catch{}E&&Ec(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const A=this.opts.secure?"wss":"ws",i=this.query||{};return this.opts.timestampRequests&&(i[this.opts.timestampParam]=yW()),this.supportsBinary||(i.b64=1),this.createUri(A,i)}}const GS=eC.WebSocket||eC.MozWebSocket;class UhA extends mhA{createSocket(A,i,e){return HW?new GS(A,i,e):i?new GS(A,i):new GS(A)}doWrite(A,i){this.ws.send(i)}}class dhA extends YS{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(A){return this.emitReserved("error",A)}this._transport.closed.then(()=>{this.onClose()}).catch(A=>{this.onError("webtransport error",A)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(A=>{const i=ohA(Number.MAX_SAFE_INTEGER,this.socket.binaryType),e=A.readable.pipeThrough(i).getReader(),E=thA();E.readable.pipeTo(A.writable),this._writer=E.writable.getWriter();const I=()=>{e.read().then(({done:t,value:o})=>{t||(this.onPacket(o),I())}).catch(t=>{})};I();const B={type:"open"};this.query.sid&&(B.data=`{"sid":"${this.query.sid}"}`),this._writer.write(B).then(()=>this.onOpen())})})}write(A){this.writable=!1;for(let i=0;i<A.length;i++){const e=A[i],E=i===A.length-1;this._writer.write(e).then(()=>{E&&Ec(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var A;(A=this._transport)===null||A===void 0||A.close()}}const ShA={websocket:UhA,webtransport:dhA,polling:FhA},KhA=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,phA=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function FS(g){if(g.length>8e3)throw"URI too long";const A=g,i=g.indexOf("["),e=g.indexOf("]");i!=-1&&e!=-1&&(g=g.substring(0,i)+g.substring(i,e).replace(/:/g,";")+g.substring(e,g.length));let E=KhA.exec(g||""),I={},B=14;for(;B--;)I[phA[B]]=E[B]||"";return i!=-1&&e!=-1&&(I.source=A,I.host=I.host.substring(1,I.host.length-1).replace(/;/g,":"),I.authority=I.authority.replace("[","").replace("]","").replace(/;/g,":"),I.ipv6uri=!0),I.pathNames=khA(I,I.path),I.queryKey=JhA(I,I.query),I}function khA(g,A){const i=/\/{2,9}/g,e=A.replace(i,"/").split("/");return(A.slice(0,1)=="/"||A.length===0)&&e.splice(0,1),A.slice(-1)=="/"&&e.splice(e.length-1,1),e}function JhA(g,A){const i={};return A.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(e,E,I){E&&(i[E]=I)}),i}const mS=typeof addEventListener=="function"&&typeof removeEventListener=="function",Bc=[];mS&&addEventListener("offline",()=>{Bc.forEach(g=>g())},!1);class hQ extends HE{constructor(A,i){if(super(),this.binaryType=ahA,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,A&&typeof A=="object"&&(i=A,A=null),A){const e=FS(A);i.hostname=e.host,i.secure=e.protocol==="https"||e.protocol==="wss",i.port=e.port,e.query&&(i.query=e.query)}else i.host&&(i.hostname=FS(i.host).host);Ic(this,i),this.secure=i.secure!=null?i.secure:typeof location<"u"&&location.protocol==="https:",i.hostname&&!i.port&&(i.port=this.secure?"443":"80"),this.hostname=i.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=i.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},i.transports.forEach(e=>{const E=e.prototype.name;this.transports.push(E),this._transportsByName[E]=e}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},i),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=chA(this.opts.query)),mS&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},Bc.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(A){const i=Object.assign({},this.opts.query);i.EIO=NW,i.transport=A,this.id&&(i.sid=this.id);const e=Object.assign({},this.opts,{query:i,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[A]);return new this._transportsByName[A](e)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}const A=this.opts.rememberUpgrade&&hQ.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";const i=this.createTransport(A);i.open(),this.setTransport(i)}setTransport(A){this.transport&&this.transport.removeAllListeners(),this.transport=A,A.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",i=>this._onClose("transport close",i))}onOpen(){this.readyState="open",hQ.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(A){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",A),this.emitReserved("heartbeat"),A.type){case"open":this.onHandshake(JSON.parse(A.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const i=new Error("server error");i.code=A.data,this._onError(i);break;case"message":this.emitReserved("data",A.data),this.emitReserved("message",A.data);break}}onHandshake(A){this.emitReserved("handshake",A),this.id=A.sid,this.transport.query.sid=A.sid,this._pingInterval=A.pingInterval,this._pingTimeout=A.pingTimeout,this._maxPayload=A.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const A=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+A,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},A),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const A=this._getWritablePackets();this.transport.send(A),this._prevBufferLen=A.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let i=1;for(let e=0;e<this.writeBuffer.length;e++){const E=this.writeBuffer[e].data;if(E&&(i+=MhA(E)),e>0&&i>this._maxPayload)return this.writeBuffer.slice(0,e);i+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const A=Date.now()>this._pingTimeoutTime;return A&&(this._pingTimeoutTime=0,Ec(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),A}write(A,i,e){return this._sendPacket("message",A,i,e),this}send(A,i,e){return this._sendPacket("message",A,i,e),this}_sendPacket(A,i,e,E){if(typeof i=="function"&&(E=i,i=void 0),typeof e=="function"&&(E=e,e=null),this.readyState==="closing"||this.readyState==="closed")return;e=e||{},e.compress=e.compress!==!1;const I={type:A,data:i,options:e};this.emitReserved("packetCreate",I),this.writeBuffer.push(I),E&&this.once("flush",E),this.flush()}close(){const A=()=>{this._onClose("forced close"),this.transport.close()},i=()=>{this.off("upgrade",i),this.off("upgradeError",i),A()},e=()=>{this.once("upgrade",i),this.once("upgradeError",i)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?e():A()}):this.upgrading?e():A()),this}_onError(A){if(hQ.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",A),this._onClose("transport error",A)}_onClose(A,i){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),mS&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const e=Bc.indexOf(this._offlineEventListener);e!==-1&&Bc.splice(e,1)}this.readyState="closed",this.id=null,this.emitReserved("close",A,i),this.writeBuffer=[],this._prevBufferLen=0}}}hQ.protocol=NW;class NhA extends hQ{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let A=0;A<this._upgrades.length;A++)this._probe(this._upgrades[A])}_probe(A){let i=this.createTransport(A),e=!1;hQ.priorWebsocketSuccess=!1;const E=()=>{e||(i.send([{type:"ping",data:"probe"}]),i.once("packet",s=>{if(!e)if(s.type==="pong"&&s.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",i),!i)return;hQ.priorWebsocketSuccess=i.name==="websocket",this.transport.pause(()=>{e||this.readyState!=="closed"&&(r(),this.setTransport(i),i.send([{type:"upgrade"}]),this.emitReserved("upgrade",i),i=null,this.upgrading=!1,this.flush())})}else{const w=new Error("probe error");w.transport=i.name,this.emitReserved("upgradeError",w)}}))};function I(){e||(e=!0,r(),i.close(),i=null)}const B=s=>{const w=new Error("probe error: "+s);w.transport=i.name,I(),this.emitReserved("upgradeError",w)};function t(){B("transport closed")}function o(){B("socket closed")}function a(s){i&&s.name!==i.name&&I()}const r=()=>{i.removeListener("open",E),i.removeListener("error",B),i.removeListener("close",t),this.off("close",o),this.off("upgrading",a)};i.once("open",E),i.once("error",B),i.once("close",t),this.once("close",o),this.once("upgrading",a),this._upgrades.indexOf("webtransport")!==-1&&A!=="webtransport"?this.setTimeoutFn(()=>{e||i.open()},200):i.open()}onHandshake(A){this._upgrades=this._filterUpgrades(A.upgrades),super.onHandshake(A)}_filterUpgrades(A){const i=[];for(let e=0;e<A.length;e++)~this.transports.indexOf(A[e])&&i.push(A[e]);return i}}let OhA=class extends NhA{constructor(A,i={}){const e=typeof A=="object"?A:i;(!e.transports||e.transports&&typeof e.transports[0]=="string")&&(e.transports=(e.transports||["polling","websocket","webtransport"]).map(E=>ShA[E]).filter(E=>!!E)),super(A,e)}};function yhA(g,A="",i){let e=g;i=i||typeof location<"u"&&location,g==null&&(g=i.protocol+"//"+i.host),typeof g=="string"&&(g.charAt(0)==="/"&&(g.charAt(1)==="/"?g=i.protocol+g:g=i.host+g),/^(https?|wss?):\/\//.test(g)||(typeof i<"u"?g=i.protocol+"//"+g:g="https://"+g),e=FS(g)),e.port||(/^(http|ws)$/.test(e.protocol)?e.port="80":/^(http|ws)s$/.test(e.protocol)&&(e.port="443")),e.path=e.path||"/";const I=e.host.indexOf(":")!==-1?"["+e.host+"]":e.host;return e.id=e.protocol+"://"+I+":"+e.port+A,e.href=e.protocol+"://"+I+(i&&i.port===e.port?"":":"+e.port),e}const xhA=typeof ArrayBuffer=="function",VhA=g=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(g):g.buffer instanceof ArrayBuffer,jW=Object.prototype.toString,qhA=typeof Blob=="function"||typeof Blob<"u"&&jW.call(Blob)==="[object BlobConstructor]",HhA=typeof File=="function"||typeof File<"u"&&jW.call(File)==="[object FileConstructor]";function US(g){return xhA&&(g instanceof ArrayBuffer||VhA(g))||qhA&&g instanceof Blob||HhA&&g instanceof File}function Cc(g,A){if(!g||typeof g!="object")return!1;if(Array.isArray(g)){for(let i=0,e=g.length;i<e;i++)if(Cc(g[i]))return!0;return!1}if(US(g))return!0;if(g.toJSON&&typeof g.toJSON=="function"&&arguments.length===1)return Cc(g.toJSON(),!0);for(const i in g)if(Object.prototype.hasOwnProperty.call(g,i)&&Cc(g[i]))return!0;return!1}function jhA(g){const A=[],i=g.data,e=g;return e.data=dS(i,A),e.attachments=A.length,{packet:e,buffers:A}}function dS(g,A){if(!g)return g;if(US(g)){const i={_placeholder:!0,num:A.length};return A.push(g),i}else if(Array.isArray(g)){const i=new Array(g.length);for(let e=0;e<g.length;e++)i[e]=dS(g[e],A);return i}else if(typeof g=="object"&&!(g instanceof Date)){const i={};for(const e in g)Object.prototype.hasOwnProperty.call(g,e)&&(i[e]=dS(g[e],A));return i}return g}function LhA(g,A){return g.data=SS(g.data,A),delete g.attachments,g}function SS(g,A){if(!g)return g;if(g&&g._placeholder===!0){if(typeof g.num=="number"&&g.num>=0&&g.num<A.length)return A[g.num];throw new Error("illegal attachments")}else if(Array.isArray(g))for(let i=0;i<g.length;i++)g[i]=SS(g[i],A);else if(typeof g=="object")for(const i in g)Object.prototype.hasOwnProperty.call(g,i)&&(g[i]=SS(g[i],A));return g}const zhA=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],ZhA=5;var Wi;(function(g){g[g.CONNECT=0]="CONNECT",g[g.DISCONNECT=1]="DISCONNECT",g[g.EVENT=2]="EVENT",g[g.ACK=3]="ACK",g[g.CONNECT_ERROR=4]="CONNECT_ERROR",g[g.BINARY_EVENT=5]="BINARY_EVENT",g[g.BINARY_ACK=6]="BINARY_ACK"})(Wi||(Wi={}));class ThA{constructor(A){this.replacer=A}encode(A){return(A.type===Wi.EVENT||A.type===Wi.ACK)&&Cc(A)?this.encodeAsBinary({type:A.type===Wi.EVENT?Wi.BINARY_EVENT:Wi.BINARY_ACK,nsp:A.nsp,data:A.data,id:A.id}):[this.encodeAsString(A)]}encodeAsString(A){let i=""+A.type;return(A.type===Wi.BINARY_EVENT||A.type===Wi.BINARY_ACK)&&(i+=A.attachments+"-"),A.nsp&&A.nsp!=="/"&&(i+=A.nsp+","),A.id!=null&&(i+=A.id),A.data!=null&&(i+=JSON.stringify(A.data,this.replacer)),i}encodeAsBinary(A){const i=jhA(A),e=this.encodeAsString(i.packet),E=i.buffers;return E.unshift(e),E}}function LW(g){return Object.prototype.toString.call(g)==="[object Object]"}class KS extends HE{constructor(A){super(),this.reviver=A}add(A){let i;if(typeof A=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");i=this.decodeString(A);const e=i.type===Wi.BINARY_EVENT;e||i.type===Wi.BINARY_ACK?(i.type=e?Wi.EVENT:Wi.ACK,this.reconstructor=new WhA(i),i.attachments===0&&super.emitReserved("decoded",i)):super.emitReserved("decoded",i)}else if(US(A)||A.base64)if(this.reconstructor)i=this.reconstructor.takeBinaryData(A),i&&(this.reconstructor=null,super.emitReserved("decoded",i));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+A)}decodeString(A){let i=0;const e={type:Number(A.charAt(0))};if(Wi[e.type]===void 0)throw new Error("unknown packet type "+e.type);if(e.type===Wi.BINARY_EVENT||e.type===Wi.BINARY_ACK){const I=i+1;for(;A.charAt(++i)!=="-"&&i!=A.length;);const B=A.substring(I,i);if(B!=Number(B)||A.charAt(i)!=="-")throw new Error("Illegal attachments");e.attachments=Number(B)}if(A.charAt(i+1)==="/"){const I=i+1;for(;++i&&!(A.charAt(i)===","||i===A.length););e.nsp=A.substring(I,i)}else e.nsp="/";const E=A.charAt(i+1);if(E!==""&&Number(E)==E){const I=i+1;for(;++i;){const B=A.charAt(i);if(B==null||Number(B)!=B){--i;break}if(i===A.length)break}e.id=Number(A.substring(I,i+1))}if(A.charAt(++i)){const I=this.tryParse(A.substr(i));if(KS.isPayloadValid(e.type,I))e.data=I;else throw new Error("invalid payload")}return e}tryParse(A){try{return JSON.parse(A,this.reviver)}catch{return!1}}static isPayloadValid(A,i){switch(A){case Wi.CONNECT:return LW(i);case Wi.DISCONNECT:return i===void 0;case Wi.CONNECT_ERROR:return typeof i=="string"||LW(i);case Wi.EVENT:case Wi.BINARY_EVENT:return Array.isArray(i)&&(typeof i[0]=="number"||typeof i[0]=="string"&&zhA.indexOf(i[0])===-1);case Wi.ACK:case Wi.BINARY_ACK:return Array.isArray(i)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class WhA{constructor(A){this.packet=A,this.buffers=[],this.reconPack=A}takeBinaryData(A){if(this.buffers.push(A),this.buffers.length===this.reconPack.attachments){const i=LhA(this.reconPack,this.buffers);return this.finishedReconstruction(),i}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const bhA=Object.freeze(Object.defineProperty({__proto__:null,Decoder:KS,Encoder:ThA,get PacketType(){return Wi},protocol:ZhA},Symbol.toStringTag,{value:"Module"}));function HC(g,A,i){return g.on(A,i),function(){g.off(A,i)}}const fhA=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class zW extends HE{constructor(A,i,e){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=A,this.nsp=i,e&&e.auth&&(this.auth=e.auth),this._opts=Object.assign({},e),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const A=this.io;this.subs=[HC(A,"open",this.onopen.bind(this)),HC(A,"packet",this.onpacket.bind(this)),HC(A,"error",this.onerror.bind(this)),HC(A,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...A){return A.unshift("message"),this.emit.apply(this,A),this}emit(A,...i){var e,E,I;if(fhA.hasOwnProperty(A))throw new Error('"'+A.toString()+'" is a reserved event name');if(i.unshift(A),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(i),this;const B={type:Wi.EVENT,data:i};if(B.options={},B.options.compress=this.flags.compress!==!1,typeof i[i.length-1]=="function"){const r=this.ids++,s=i.pop();this._registerAckCallback(r,s),B.id=r}const t=(E=(e=this.io.engine)===null||e===void 0?void 0:e.transport)===null||E===void 0?void 0:E.writable,o=this.connected&&!(!((I=this.io.engine)===null||I===void 0)&&I._hasPingExpired());return this.flags.volatile&&!t||(o?(this.notifyOutgoingListeners(B),this.packet(B)):this.sendBuffer.push(B)),this.flags={},this}_registerAckCallback(A,i){var e;const E=(e=this.flags.timeout)!==null&&e!==void 0?e:this._opts.ackTimeout;if(E===void 0){this.acks[A]=i;return}const I=this.io.setTimeoutFn(()=>{delete this.acks[A];for(let t=0;t<this.sendBuffer.length;t++)this.sendBuffer[t].id===A&&this.sendBuffer.splice(t,1);i.call(this,new Error("operation has timed out"))},E),B=(...t)=>{this.io.clearTimeoutFn(I),i.apply(this,t)};B.withError=!0,this.acks[A]=B}emitWithAck(A,...i){return new Promise((e,E)=>{const I=(B,t)=>B?E(B):e(t);I.withError=!0,i.push(I),this.emit(A,...i)})}_addToQueue(A){let i;typeof A[A.length-1]=="function"&&(i=A.pop());const e={id:this._queueSeq++,tryCount:0,pending:!1,args:A,flags:Object.assign({fromQueue:!0},this.flags)};A.push((E,...I)=>e!==this._queue[0]?void 0:(E!==null?e.tryCount>this._opts.retries&&(this._queue.shift(),i&&i(E)):(this._queue.shift(),i&&i(null,...I)),e.pending=!1,this._drainQueue())),this._queue.push(e),this._drainQueue()}_drainQueue(A=!1){if(!this.connected||this._queue.length===0)return;const i=this._queue[0];i.pending&&!A||(i.pending=!0,i.tryCount++,this.flags=i.flags,this.emit.apply(this,i.args))}packet(A){A.nsp=this.nsp,this.io._packet(A)}onopen(){typeof this.auth=="function"?this.auth(A=>{this._sendConnectPacket(A)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(A){this.packet({type:Wi.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},A):A})}onerror(A){this.connected||this.emitReserved("connect_error",A)}onclose(A,i){this.connected=!1,delete this.id,this.emitReserved("disconnect",A,i),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(A=>{if(!this.sendBuffer.some(e=>String(e.id)===A)){const e=this.acks[A];delete this.acks[A],e.withError&&e.call(this,new Error("socket has been disconnected"))}})}onpacket(A){if(A.nsp===this.nsp)switch(A.type){case Wi.CONNECT:A.data&&A.data.sid?this.onconnect(A.data.sid,A.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Wi.EVENT:case Wi.BINARY_EVENT:this.onevent(A);break;case Wi.ACK:case Wi.BINARY_ACK:this.onack(A);break;case Wi.DISCONNECT:this.ondisconnect();break;case Wi.CONNECT_ERROR:this.destroy();const e=new Error(A.data.message);e.data=A.data.data,this.emitReserved("connect_error",e);break}}onevent(A){const i=A.data||[];A.id!=null&&i.push(this.ack(A.id)),this.connected?this.emitEvent(i):this.receiveBuffer.push(Object.freeze(i))}emitEvent(A){if(this._anyListeners&&this._anyListeners.length){const i=this._anyListeners.slice();for(const e of i)e.apply(this,A)}super.emit.apply(this,A),this._pid&&A.length&&typeof A[A.length-1]=="string"&&(this._lastOffset=A[A.length-1])}ack(A){const i=this;let e=!1;return function(...E){e||(e=!0,i.packet({type:Wi.ACK,id:A,data:E}))}}onack(A){const i=this.acks[A.id];typeof i=="function"&&(delete this.acks[A.id],i.withError&&A.data.unshift(null),i.apply(this,A.data))}onconnect(A,i){this.id=A,this.recovered=i&&this._pid===i,this._pid=i,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(A=>this.emitEvent(A)),this.receiveBuffer=[],this.sendBuffer.forEach(A=>{this.notifyOutgoingListeners(A),this.packet(A)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(A=>A()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Wi.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(A){return this.flags.compress=A,this}get volatile(){return this.flags.volatile=!0,this}timeout(A){return this.flags.timeout=A,this}onAny(A){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(A),this}prependAny(A){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(A),this}offAny(A){if(!this._anyListeners)return this;if(A){const i=this._anyListeners;for(let e=0;e<i.length;e++)if(A===i[e])return i.splice(e,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(A){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(A),this}prependAnyOutgoing(A){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(A),this}offAnyOutgoing(A){if(!this._anyOutgoingListeners)return this;if(A){const i=this._anyOutgoingListeners;for(let e=0;e<i.length;e++)if(A===i[e])return i.splice(e,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(A){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const i=this._anyOutgoingListeners.slice();for(const e of i)e.apply(this,A.data)}}}function _r(g){g=g||{},this.ms=g.min||100,this.max=g.max||1e4,this.factor=g.factor||2,this.jitter=g.jitter>0&&g.jitter<=1?g.jitter:0,this.attempts=0}_r.prototype.duration=function(){var g=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var A=Math.random(),i=Math.floor(A*this.jitter*g);g=(Math.floor(A*10)&1)==0?g-i:g+i}return Math.min(g,this.max)|0},_r.prototype.reset=function(){this.attempts=0},_r.prototype.setMin=function(g){this.ms=g},_r.prototype.setMax=function(g){this.max=g},_r.prototype.setJitter=function(g){this.jitter=g};class pS extends HE{constructor(A,i){var e;super(),this.nsps={},this.subs=[],A&&typeof A=="object"&&(i=A,A=void 0),i=i||{},i.path=i.path||"/socket.io",this.opts=i,Ic(this,i),this.reconnection(i.reconnection!==!1),this.reconnectionAttempts(i.reconnectionAttempts||1/0),this.reconnectionDelay(i.reconnectionDelay||1e3),this.reconnectionDelayMax(i.reconnectionDelayMax||5e3),this.randomizationFactor((e=i.randomizationFactor)!==null&&e!==void 0?e:.5),this.backoff=new _r({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(i.timeout==null?2e4:i.timeout),this._readyState="closed",this.uri=A;const E=i.parser||bhA;this.encoder=new E.Encoder,this.decoder=new E.Decoder,this._autoConnect=i.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(A){return arguments.length?(this._reconnection=!!A,A||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(A){return A===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=A,this)}reconnectionDelay(A){var i;return A===void 0?this._reconnectionDelay:(this._reconnectionDelay=A,(i=this.backoff)===null||i===void 0||i.setMin(A),this)}randomizationFactor(A){var i;return A===void 0?this._randomizationFactor:(this._randomizationFactor=A,(i=this.backoff)===null||i===void 0||i.setJitter(A),this)}reconnectionDelayMax(A){var i;return A===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=A,(i=this.backoff)===null||i===void 0||i.setMax(A),this)}timeout(A){return arguments.length?(this._timeout=A,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(A){if(~this._readyState.indexOf("open"))return this;this.engine=new OhA(this.uri,this.opts);const i=this.engine,e=this;this._readyState="opening",this.skipReconnect=!1;const E=HC(i,"open",function(){e.onopen(),A&&A()}),I=t=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",t),A?A(t):this.maybeReconnectOnOpen()},B=HC(i,"error",I);if(this._timeout!==!1){const t=this._timeout,o=this.setTimeoutFn(()=>{E(),I(new Error("timeout")),i.close()},t);this.opts.autoUnref&&o.unref(),this.subs.push(()=>{this.clearTimeoutFn(o)})}return this.subs.push(E),this.subs.push(B),this}connect(A){return this.open(A)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const A=this.engine;this.subs.push(HC(A,"ping",this.onping.bind(this)),HC(A,"data",this.ondata.bind(this)),HC(A,"error",this.onerror.bind(this)),HC(A,"close",this.onclose.bind(this)),HC(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(A){try{this.decoder.add(A)}catch(i){this.onclose("parse error",i)}}ondecoded(A){Ec(()=>{this.emitReserved("packet",A)},this.setTimeoutFn)}onerror(A){this.emitReserved("error",A)}socket(A,i){let e=this.nsps[A];return e?this._autoConnect&&!e.active&&e.connect():(e=new zW(this,A,i),this.nsps[A]=e),e}_destroy(A){const i=Object.keys(this.nsps);for(const e of i)if(this.nsps[e].active)return;this._close()}_packet(A){const i=this.encoder.encode(A);for(let e=0;e<i.length;e++)this.engine.write(i[e],A.options)}cleanup(){this.subs.forEach(A=>A()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(A,i){var e;this.cleanup(),(e=this.engine)===null||e===void 0||e.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",A,i),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const A=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const i=this.backoff.duration();this._reconnecting=!0;const e=this.setTimeoutFn(()=>{A.skipReconnect||(this.emitReserved("reconnect_attempt",A.backoff.attempts),!A.skipReconnect&&A.open(E=>{E?(A._reconnecting=!1,A.reconnect(),this.emitReserved("reconnect_error",E)):A.onreconnect()}))},i);this.opts.autoUnref&&e.unref(),this.subs.push(()=>{this.clearTimeoutFn(e)})}}onreconnect(){const A=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",A)}}const bs={};function tc(g,A){typeof g=="object"&&(A=g,g=void 0),A=A||{};const i=yhA(g,A.path||"/socket.io"),e=i.source,E=i.id,I=i.path,B=bs[E]&&I in bs[E].nsps,t=A.forceNew||A["force new connection"]||A.multiplex===!1||B;let o;return t?o=new pS(e,A):(bs[E]||(bs[E]=new pS(e,A)),o=bs[E]),i.query&&!A.query&&(A.query=i.queryKey),o.socket(i.path,A)}Object.assign(tc,{Manager:pS,Socket:zW,io:tc,connect:tc});const fs="https://api.tybotflow.com/api/v1",vhA="https://api.tybotflow.com/api/v1/chatbots-config",ZW="https://migration-meta.tybotflow.com/",TW=ZW+"webhook/v",oc=tc(ZW,{transports:["websocket","polling"],reconnection:!0,reconnectionAttempts:3,autoConnect:!0,reconnectionDelay:2e3}),WW=new ho,kS=g=>{if(!g||!g.message)return"👋 Hey there! how can I help you?";const A=g.message;if(typeof A=="string")return A;if(Array.isArray(A)){const i=window.location.href,e=window.location.origin,E=window.location.pathname,I=e+E;for(const t of A){if(!t.urls||t.urls.length===0)continue;if(t.urls.some(a=>{if(!a||a.trim()==="")return!1;try{let r=a.trim();!r.startsWith("http://")&&!r.startsWith("https://")&&(r="https://"+r);const s=new URL(r),w=s.origin,M=s.pathname,c=w+M;return I===c||i===r?!0:M==="/"||M===""?e===w:!!i.startsWith(r)}catch{return console.warn("Invalid URL in message:",a),!1}}))return t.text||"👋 Hey there! how can I help you?"}const B=A.find(t=>!t.urls||t.urls.length===0||t.urls.every(o=>!o||o.trim()===""));if(B)return B.text||"👋 Hey there! how can I help you?";if(A.length>0)return A[0].text||"👋 Hey there! how can I help you?"}return"👋 Hey there! how can I help you?"},bW=(g,A)=>{const i={className:"w-5 h-5",style:{color:A}};switch(g?.toLowerCase()){case"pdf":return N.jsx(ns,{...i});case"doc":case"docx":return N.jsx(ns,{...i});case"xls":case"xlsx":case"csv":return N.jsx(wiA,{...i});case"ppt":case"pptx":return N.jsx(miA,{...i});case"zip":case"rar":case"7z":case"tar":case"gz":return N.jsx(aiA,{...i});case"txt":case"md":case"rtf":return N.jsx(Cy,{...i});default:return N.jsx(ns,{...i})}},PhA=({config:g})=>{const A=gg.useRef(null),i=gg.useRef(null),e=gg.useRef(null),E=gg.useRef(null),I=gg.useRef(null),[B,t]=gg.useState(null),[o,a]=gg.useState(!0);gg.useEffect(()=>{(async()=>{a(!0),await Ne.get(`${vhA}/bot/${g.bot?.botId}`,{}).then(KA=>{t(KA.data)}).catch(KA=>{console.error("Error fetching bot config:",KA)}).finally(()=>{a(!1)})})()},[g.bot?.botId,g?.token]);const r=B?.mainColor||"#59168b",s=B?.secondaryColor||"#6366f1",w=B?.thirdColor||"#0f172b",M=B?.headerFirstColor||"#6e11b0",c=B?.headerSecondColor||"#372aac",l=B?.inputBackgroundColor||"#1f2937",Y=B?.inputTextColor||"#fff",R=B?.roundness||24,F=B?.chatRoundness||16,m=(B?.minPanelWidth||434)>window.innerWidth?window.innerWidth:B?.minPanelWidth||434,K=(B?.maxPanelWidth||window.innerWidth)>window.innerWidth?window.innerWidth:B?.maxPanelWidth||window.innerWidth,O=B?.chatMaxWidth||88,S=B?.toggleBtnBorderTopLeftRadius||12,q=B?.toggleBtnBorderTopRightRadius||0,H=B?.toggleBtnBorderBottomLeftRadius||12,x=B?.toggleBtnBorderBottomRightRadius||0,Z=B?.menuBackgroundColor||"#1f2937",y=B?.menuTextColor||"#e5e7eb",z=B?.menuHoverBackgroundColor||"#374151",W=B?.agentChatResponseColor||"#e5e7eb",T=B?.agentChatResponseBgColor||"#1f2937",AA=B?.agentIconBgColor||"#59168b",P=B?.agentIconColor||"#fff",EA=B?.userChatMessagesColor||"#fff",$=B?.userChatMessagesBgColor||"#7a1ebe",tA=B?.userIconBgColor||"#7a1ebe",p=B?.userIconColor||"#fff",X=B?.ButtonColor||"#fff",j=B?.ButtonsBgColor||"#59168b",k=B?.fontSize||13,_=B?.toggleBtnPosition||"bottom-right",CA=B?.autoOpenPanel??!0,oA=B?.tempToken||"",lA=(()=>{const V=B?.firstMessageKeyword;if(Array.isArray(V)){const KA=window.location.href,FA=V.find(Fg=>Fg.url&&Fg.url===KA);if(FA)return FA.message;const WA=V.find(Fg=>!Fg.url||Fg.url==="");return WA?WA.message:V[0]?.message||"hi"}return V||"hi"})(),GA=V=>({ip:V.ip||"",flag:{img:V.flag||"",emoji:V.emoji_flag||"",emoji_unicode:V.emoji_unicode||""},is_eu:V.is_eu??!1,postal:V.postal||"",borders:"",latitude:V.latitude||0,platform:V?.platform||"",timezone:{id:V.time_zone?.name||"",utc:V.time_zone?.offset||"",abbr:V.time_zone?.abbr||"",is_dst:V.time_zone?.is_dst??!1,offset:V.time_zone?.offset||0,current_time:V.time_zone?.current_time||""},continent:V.continent_name||"",longitude:V.longitude||0,connection:{asn:V.asn?.asn||0,isp:V.asn?.name||"",org:V.asn?.name||"",domain:V.asn?.domain||""}}),[dA,fA]=gg.useState(m),ng=gg.useRef(!1),eg=gg.useRef(0),kA=gg.useRef(m),eA=V=>{ng.current=!0,eg.current=V.clientX,kA.current=dA,document.body.style.cursor="ew-resize"};gg.useEffect(()=>{const V=FA=>{if(!ng.current)return;const WA=eg.current-FA.clientX;let Fg=kA.current+WA;Fg=Math.max(m,Math.min(K,Fg)),fA(Fg)},KA=()=>{ng.current&&(ng.current=!1,document.body.style.cursor="")};return window.addEventListener("mousemove",V),window.addEventListener("mouseup",KA),()=>{window.removeEventListener("mousemove",V),window.removeEventListener("mouseup",KA)}},[dA,m,K]);const[ZA,cg]=gg.useState(!1),[tg,qA]=gg.useState(!1),[Eg,Ag]=gg.useState(!1),[Rg,og]=gg.useState(()=>_==="bottom-left"?{x:48,y:window.innerHeight-120}:_==="middle-right"?{x:window.innerWidth-80,y:window.innerHeight/2-35}:{x:window.innerWidth-123,y:window.innerHeight-100}),[SA,TA]=gg.useState(!1),[MA,YA]=gg.useState({x:0,y:0}),yA=gg.useRef(null),[LA,Dg]=gg.useState(""),[lg,kg]=gg.useState(!1),[Og,Yg]=gg.useState(!1),[Gg,qg]=gg.useState([]),[Ug,Lg]=gg.useState(!1),Jg=gg.useRef(0),[Pg,ui]=gg.useState(!1),[$g,bg]=gg.useState(!1),Ri=gg.useRef(!1),[DI,Ii]=gg.useState("00:00"),Ee=gg.useRef(null),eE=gg.useRef(0),[vg,qe]=gg.useState(null),[di,$i]=gg.useState(!1),[Ce,Yi]=gg.useState(new Set),[mi,bi]=gg.useState([]),{startRecording:gB,stopRecording:GE,pauseRecording:ZE,resumeRecording:ne,status:Ui,error:We}=gCA.useReactMediaRecorder({video:!1,onStop(V,KA){if(Ri.current){Ri.current=!1,Ii("00:00"),eE.current=0;return}qg(FA=>[...FA,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),file:KA,type:"audio",url:V,name:`recording-${new Date().toISOString()}.webm`,size:KA.size}]),Ii("00:00"),eE.current=0}}),de=B?.icon||g?.bot.avatar_url||fz,yi=B?.title||g?.bot.name||"Tybot webchat",[Ie,Kg]=gg.useState(null),[wA,Qg]=gg.useState(()=>{const V=localStorage.getItem("phone_client");if(g.bot?.botId==="rockskin"&&V)return V;if(!B?.botNeedsAuth){let KA=localStorage.getItem("externalUser");if(!KA){const FA=new Uint8Array(16);window.crypto.getRandomValues(FA),KA=Array.from(FA).map(WA=>WA.toString(16).padStart(2,"0")).join("")}return localStorage.setItem("externalUser",KA),KA}});gg.useEffect(()=>{if(!Ie)return;const V=KA=>{if(KA.bot.conversationId!==parseInt(Ie)||KA.bot.botId!==g?.bot?.botId){kg(!1);return}const FA={id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:KA.bot.item,timestamp:new Date,seen:FE.current,nMessage:Array.isArray(KA.bot.item)?KA.bot.item.length:1};bi(WA=>WA.some(JA=>JA.id===FA.id)?WA:[...WA,FA]),kg(!1)};return oc.on("bot-message",V),()=>{oc.off("bot-message",V)}},[Ie,g?.bot?.botId]),gg.useEffect(()=>{(async()=>{if(!(Ie||!g.bot?.botId||!wA))try{const FA=(await Ne.post(`${fs}/conversations/start-conversation`,{bot_id:g.bot?.botId,externalUser:wA})).data.conversationId;Kg(FA),localStorage.setItem("conversationId",FA),oc.emit("join_room",parseInt(FA))}catch(KA){console.error("Error initializing conversation:",KA)}})()},[Ie,g.bot?.botId,wA]);const[dg,Ae]=gg.useState(()=>B?.botNeedsAuth?!!localStorage.getItem("conversationId"):!0),[ge,se]=gg.useState(""),[Me,he]=gg.useState(""),[Se,FB]=gg.useState(""),[vi,HI]=gg.useState(null),FE=gg.useRef(!1),II=mi.reduce((V,KA)=>KA.seen?V:V+(KA.sender==="agent"?KA.nMessage||1:0),0),QC=()=>{bi(V=>V.map(KA=>({...KA,seen:!0})))};gg.useEffect(()=>{let V;return!localStorage.getItem("webChatOpen")&&B&&CA&&(V=setTimeout(()=>{cg(!0),FE.current=!0,QC(),localStorage.setItem("webChatOpen","true")},3200)),()=>clearTimeout(V)},[B]),gg.useEffect(()=>{const V=B?.widgetLoadBehavior;if(!V||!(()=>{const WA=V.message;if(typeof WA=="string"){if(!V.urls||V.urls.length===0)return!0;const Fg=window.location.origin,JA=window.location.href;return V.urls.some(Bi=>{if(!Bi||Bi.trim()==="")return!0;try{return Fg.includes(Bi)||JA.includes(Bi)||Bi.includes(Fg)}catch{return console.warn("Invalid URL in widgetLoadBehavior:",Bi),!1}})}if(Array.isArray(WA)){const Fg=window.location.href,JA=window.location.origin,Bi=window.location.pathname,ci=JA+Bi;for(const He of WA)if(!He.urls||He.urls.length===0||He.urls.every(be=>!be||be.trim()==="")||He.urls.some(be=>{if(!be||be.trim()==="")return!1;try{let dE=be.trim();!dE.startsWith("http://")&&!dE.startsWith("https://")&&(dE="https://"+dE);const TE=new URL(dE),Zg=TE.origin,BB=TE.pathname,xi=Zg+BB;return ci===xi||Fg===dE?!0:BB==="/"||BB===""?JA===Zg:!!Fg.startsWith(dE)}catch{return console.warn("Invalid URL in message:",be),!1}}))return!0;return!1}return!0})())return;let FA;if(V.behavior==="after seconds")FA=setTimeout(()=>{Ag(!0)},V.value*1e3);else if(V.behavior==="after scroll"){const WA=()=>{const Fg=window.pageYOffset||document.documentElement.scrollTop,JA=document.documentElement.scrollHeight-document.documentElement.clientHeight;Fg/JA*100>=V.value&&(Ag(!0),window.removeEventListener("scroll",WA))};return window.addEventListener("scroll",WA),()=>{window.removeEventListener("scroll",WA)}}return()=>{FA&&clearTimeout(FA)}},[B?.widgetLoadBehavior]),gg.useEffect(()=>{ZA&&Ag(!1)},[ZA]),gg.useEffect(()=>{fetch("https://api.ipdata.co/?api-key=7930ffd0621dafcb6cd830a503d726bf514b74c1cae21ffff8131890").then(function(V){V.json().then(KA=>{HI({...KA,platform:WW.getOS().name+" "+WW.getOS().version})})}).catch(function(V){console.log(V)})},[]);const yt=gg.useCallback(async(V,KA=[],FA)=>{if(!g.bot.botId||!Ie){kg(!1),bi(Fg=>[...Fg,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:[{type:"text",text:"⚠️ Unable to send message: No bot selected or conversation not initialized."}],timestamp:new Date}]);return}if(KA.length>0||FA&&typeof FA=="object"&&FA.attachment!==void 0){const Fg=FA&&typeof FA!="string"?FA.attachment.file:KA[0]?.file,JA=FA&&typeof FA!="string"?FA.attachment.type:KA[0]?.type||"file";let Bi=FA;if(FA&&typeof FA=="object"&&FA.attachment!==void 0){const{attachment:He,...Si}=FA;Bi=Si}const ci=new FormData;ci.append("type",JA),ci.append("file",Fg),ci.append("botId",g.bot.botId),ci.append("external_id",wA||""),ci.append("isintern",g.token?"true":"false"),ci.append("host",window.location.origin),ci.append("channel","web"),ci.append("payload",Bi?JSON.stringify(Bi):""),await Ne.post(TW,ci,{headers:{Authorization:`Bearer ${g?.token}`,"Content-Type":"multipart/form-data"}})}else{const Fg={type:"text",messageText:V,botId:g.bot.botId,external_id:wA||"",isintern:!!g.token,host:window.location.origin,channel:"web"};FA&&(Fg.payload=FA),await Ne.post(TW,Fg,{headers:{Authorization:`Bearer ${g?.token}`,"Content-Type":"application/json"}})}},[g.bot.botId,Ie,g.token,g.user?.id]),Li=gg.useCallback(async()=>{if(g.bot.botId&&Ie){kg(!0);try{await yt(lA)}catch(V){console.error("Error sending first message:",V),kg(!1)}}},[g.bot.botId,lA,Ie,yt]);gg.useEffect(()=>{Ie&&dg&&g?.bot&&mi.length===0&&B&&CA&&(Li(),localStorage.getItem("webChatAuth")&&JSON.parse(localStorage.getItem("webChatAuth"))&&B?.botNeedsAuth&&Ie&&(ge||Se||Me)&&(setTimeout(()=>{mB(Ie)},2e3),localStorage.setItem("webChatAuth","true")))},[dg,g?.bot,Ie,B]),gg.useEffect(()=>(Ui==="recording"?Ee.current||(Ee.current=setInterval(()=>{eE.current+=1;const V=Math.floor(eE.current/60).toString().padStart(2,"0"),KA=(eE.current%60).toString().padStart(2,"0");Ii(`${V}:${KA}`)},1e3)):Ee.current&&(clearInterval(Ee.current),Ee.current=null),()=>{Ee.current&&(clearInterval(Ee.current),Ee.current=null)}),[Ui]),gg.useEffect(()=>{We&&We.toLowerCase().includes("permission_denied")&&(bg(!1),Ii("00:00"),eE.current=0,Ee.current&&(clearInterval(Ee.current),Ee.current=null),alert("Microphone permission denied. Please allow access to record audio."))},[We]),gg.useEffect(()=>{Ui!=="recording"&&Ui!=="paused"&&(Ii("00:00"),eE.current=0)},[Ui]);const aC=gg.useRef(null);gg.useEffect(()=>{if(aC&&aC.current){const V=aC.current;V.style.height="auto";const KA=120;V.scrollHeight>KA?(V.style.height=KA+"px",V.style.overflowY="auto"):(V.style.height=V.scrollHeight+"px",V.style.overflowY="hidden")}},[LA]),gg.useEffect(()=>{(ZA||lg)&&A.current&&(A.current.scrollTop=A.current.scrollHeight)},[mi,lg,ZA]);const KQ=V=>{const KA=V.type.toLowerCase();return KA.startsWith("image/")?"image":KA.startsWith("video/")?"video":KA.startsWith("audio/")?"audio":"document"},mE=gg.useCallback((V,KA)=>{const FA=[];Array.from(V).forEach(WA=>{if(WA.size>10*1024*1024){alert(`File ${WA.name} is too large. Maximum size is 10MB.`);return}const Fg={id:Date.now().toString()+Math.random().toString(36).substring(2,9),file:WA,type:KQ(WA),url:URL.createObjectURL(WA),name:WA.name,size:WA.size};FA.push(Fg)}),qg(WA=>[...WA,...FA]),KA&&KA.current&&(KA.current.value="")},[]),rC=gg.useCallback(V=>{V.preventDefault(),Jg.current=0,Lg(!1);const KA=V.dataTransfer.files;KA.length>0&&mE(KA)},[mE]),BI=gg.useCallback(V=>{V.preventDefault(),Jg.current+=1,Lg(!0)},[]),vC=gg.useCallback(V=>{V.preventDefault()},[]),zi=gg.useCallback(V=>{V.preventDefault(),Jg.current-=1,Jg.current<=0&&Lg(!1)},[]),PC=gg.useCallback(V=>{qg(KA=>{const FA=KA.find(WA=>WA.id===V);return FA&&URL.revokeObjectURL(FA.url),KA.filter(WA=>WA.id!==V)})},[]),pQ=V=>{if(V===0)return"0 Bytes";const KA=1024,FA=["Bytes","KB","MB","GB"],WA=Math.floor(Math.log(V)/Math.log(KA));return Number.parseFloat((V/Math.pow(KA,WA)).toFixed(2))+" "+FA[WA]},Ke=async(V=LA,KA)=>{if(V.trim()||Gg.length!==0){const WA={id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"user",content:V,attachments:[...Gg],timestamp:new Date};if(bi(Fg=>[...Fg,WA]),Dg(""),qg([]),kg(!0),g?.bot)try{if(!Ie){kg(!1),bi(Fg=>[...Fg,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"⚠️ Conversation not initialized. Please try again later.",timestamp:new Date,seen:FE.current,nMessage:1}]);return}await yt(V,Gg,KA)}catch{bi(Fg=>[...Fg,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"Erreur du serveur",timestamp:new Date,seen:FE.current,nMessage:1}]),kg(!1)}else bi(Fg=>[...Fg,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"Aucun bot sélectionné",timestamp:new Date,seen:FE.current,nMessage:1}]),kg(!1)}else return},iB=V=>{switch(ui(!1),V){case"image":i.current?.click();break;case"video":e.current?.click();break;case"audio":E.current?.click();break;case"document":I.current?.click();break}};gg.useEffect(()=>{const V=mi.slice().reverse().find(KA=>KA.sender==="agent");if(V){let KA=!1;Array.isArray(V.content)&&(KA=V.content.some(FA=>FA.type==="text"&&typeof FA.text=="object"&&FA.text.type==="EVFORM")),Yg(KA)}else Yg(!1)},[mi]);const[eB,zB]=gg.useState(!1),CI=gg.useRef({x:0,y:0}),nC=V=>{V.preventDefault(),V.stopPropagation(),TA(!0),zB(!1),CI.current={x:V.clientX,y:V.clientY},YA({x:V.clientX-Rg.x,y:V.clientY-Rg.y}),document.body.style.cursor="grabbing",document.body.style.userSelect="none"},xt=V=>{V.preventDefault(),V.stopPropagation();const KA=V.touches[0];TA(!0),zB(!1),CI.current={x:KA.clientX,y:KA.clientY},YA({x:KA.clientX-Rg.x,y:KA.clientY-Rg.y})},ZB=V=>{if(V.preventDefault(),V.stopPropagation(),eB){zB(!1);return}cg(KA=>!KA),FE.current=!ZA,ZA||QC(),!CA&&mi.length===0&&Li()};gg.useEffect(()=>{const V=Fg=>{if(!SA)return;const JA=Math.abs(Fg.clientX-CI.current.x),Bi=Math.abs(Fg.clientY-CI.current.y);(JA>5||Bi>5)&&zB(!0);const ci=Fg.clientX-MA.x,He=Fg.clientY-MA.y,Si=67,be=window.innerWidth-document.body.clientWidth,dE=Math.max(0,Math.min(window.innerWidth-Si-be,ci)),TE=Math.max(0,Math.min(window.innerHeight-Si,He));og({x:dE,y:TE})},KA=Fg=>{if(!SA)return;Fg.preventDefault();const JA=Fg.touches[0],Bi=Math.abs(JA.clientX-CI.current.x),ci=Math.abs(JA.clientY-CI.current.y);(Bi>5||ci>5)&&zB(!0);const He=JA.clientX-MA.x,Si=JA.clientY-MA.y,be=67,dE=window.innerWidth-document.body.clientWidth,TE=Math.max(0,Math.min(window.innerWidth-be-dE,He)),Zg=Math.max(0,Math.min(window.innerHeight-be,Si));og({x:TE,y:Zg})},FA=()=>{SA&&(TA(!1),document.body.style.cursor="",document.body.style.userSelect="")},WA=()=>{SA&&TA(!1)};return SA&&(document.addEventListener("mousemove",V),document.addEventListener("touchmove",KA,{passive:!1}),document.addEventListener("mouseup",FA),document.addEventListener("touchend",WA)),()=>{document.removeEventListener("mousemove",V),document.removeEventListener("touchmove",KA),document.removeEventListener("mouseup",FA),document.removeEventListener("touchend",WA)}},[SA,MA,Rg]),gg.useEffect(()=>{const V=()=>{const FA=window.innerWidth-67,WA=window.innerHeight-67;og(Fg=>({x:Math.max(0,Math.min(FA,Fg.x)),y:Math.max(0,Math.min(WA,Fg.y))}))};return window.addEventListener("resize",V),()=>window.removeEventListener("resize",V)},[]),gg.useEffect(()=>{const V=async()=>{try{await Ne.patch(`${fs}/widget/endusers/${wA}`,{fiche_contact:{city:vi.city,platform:vi.platform,region:vi.region,country:vi.country_name,age:0,full_name:ge,gender:"",address:"",company:"","phone 2":"",facebook:"",whatsapp:"",job_title:"",avatar_url:""},user_info:GA(vi)},{headers:{Authorization:`Bearer ${oA}`}}),localStorage.setItem("enduserUpdated","true")}catch(FA){console.error("Error updating end user info:",FA)}};let KA;return vi&&Ie&&oA&&mi.length>0&&!localStorage.getItem("enduserUpdated")&&(KA=setTimeout(()=>{V()},5e3)),()=>clearTimeout(KA)},[vi,B,mi,Ie]);const Uo=/^[\u0600-\u06FF\u0750-\u077F\s\d\p{P}]+$/u,ba=/[\u0600-\u06FF\u0750-\u077F]/,vE=V=>Uo.test(V),PE=V=>ba.test(V),UE=gg.useMemo(()=>({h1:({children:V})=>N.jsx("h1",{className:"sm:text-2xl text-xl font-bold my-2",dir:vE(V)?"rtl":"ltr",children:N.jsx(VE,{sequence:[V,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h2:({children:V})=>N.jsx("h2",{className:"sm:text-xl text-lg font-semibold my-2",dir:vE(V)?"rtl":"ltr",children:N.jsx(VE,{sequence:[V,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h3:({children:V})=>N.jsx("h3",{className:"sm:text-lg text-base font-semibold my-2",dir:vE(V)?"rtl":"ltr",children:N.jsx(VE,{sequence:[V,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h4:({children:V})=>N.jsx("h4",{className:"sm:text-base text-sm font-semibold my-2",dir:vE(V)?"rtl":"ltr",children:N.jsx(VE,{sequence:[V,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h5:({children:V})=>N.jsx("h5",{className:"sm:text-base text-sm font-semibold my-2",dir:vE(V)?"rtl":"ltr",children:N.jsx(VE,{sequence:[V,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h6:({children:V})=>N.jsx("h6",{className:"sm:text-base text-sm font-semibold my-2",dir:vE(V)?"rtl":"ltr",children:N.jsx(VE,{sequence:[V,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),p:({children:V})=>{let KA;return typeof V=="string"&&PE(V)||typeof V=="object"&&!Array.isArray(V)&&V?.props?.children&&vE(V?.props?.children)||typeof V=="object"&&Array.isArray(V)&&V.some(FA=>PE(FA))?KA="rtl":KA="ltr",N.jsx("div",{className:"leading-relaxed",dir:typeof V=="string"||!Array.isArray(V)?KA:"",children:Array.isArray(V)?V.map((FA,WA)=>{const Fg=PE(FA)?"p":"span";return typeof FA=="string"&&!new RegExp("^(?:\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F|\\s)+$","u").test(FA)?N.jsx(Fg,{dir:PE(FA)?"rtl":"ltr",children:N.jsx(VE,{sequence:[FA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})},WA):FA?.type!=="br"?FA:null}):N.jsx(N.Fragment,{children:V})})},ul:({children:V})=>N.jsx("ul",{className:"list-disc list-inside ml-4 my-2",style:{color:W},dir:PE(V)?"rtl":"ltr",children:V}),ol:({children:V})=>{let KA=!1;return V.filter(FA=>typeof FA!="string").every(FA=>PE(FA?.props?.children))?KA=!0:KA=!1,N.jsx("ol",{className:"list-decimal list-inside ml-4 my-2",style:{color:W},dir:KA?"rtl":"ltr",children:typeof V=="string"?N.jsx(VE,{sequence:[V,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):V})},li:({children:V})=>N.jsx("li",{className:"my-1",dir:vE(V)?"rtl":"ltr",style:{color:W},children:typeof V=="string"?N.jsx(VE,{sequence:[V,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):V}),a:({href:V,children:KA})=>N.jsx("a",{href:V,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:typeof KA=="string"?N.jsx(VE,{sequence:[KA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):KA}),blockquote:({children:V})=>N.jsx("blockquote",{className:"border-l-4 pl-4 italic my-2",style:{borderColor:j,color:W},children:typeof V=="string"?N.jsx(VE,{sequence:[V,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):V}),code({node:V,className:KA,children:FA,...WA}){const Fg=/language-(\w+)/.exec(KA||"");return Fg?N.jsx(bz,{...WA,PreTag:"div",children:String(FA).replace(/\n$/,""),language:Fg[1],style:qrA,customStyle:{scrollbarWidth:"thin"}}):N.jsx("code",{className:"px-1 rounded font-mono inline",style:{backgroundColor:l,color:W},...WA,children:typeof FA=="string"?N.jsx(VE,{sequence:[FA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):FA})},table:({children:V})=>N.jsx("table",{className:"min-w-full my-2",style:{border:`1px solid ${W}`,color:T,backgroundColor:W},children:V}),thead:({children:V})=>N.jsx("thead",{children:V}),tbody:({children:V})=>N.jsx("tbody",{children:V}),tr:({children:V})=>N.jsx("tr",{style:{border:`1px solid ${T}`},children:V}),th:({children:V})=>N.jsx("th",{className:"px-3 py-2 font-bold text-left",children:V}),td:({children:V})=>N.jsx("td",{className:"px-3 py-2",children:typeof V=="string"?N.jsx(VE,{sequence:[V,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):V}),strong:({children:V})=>N.jsx("strong",{className:"font-bold",children:typeof V=="string"?N.jsx(VE,{sequence:[V,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):V}),em:({children:V})=>N.jsx("em",{className:"italic ",children:typeof V=="string"?N.jsx(VE,{sequence:[V,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):V}),hr:()=>N.jsx("hr",{className:"my-4",style:{borderColor:`1px solid ${W}`}})}),[Y,W,j,l,F]);gg.useEffect(()=>{const V=KA=>{Pg&&KA.target instanceof Element&&!KA.composedPath().some(FA=>FA?.id==="upload-button-toggle"||FA?.id==="document-button"||FA?.id==="image-button"||FA?.id==="video-button"||FA?.id==="audio-button")&&ui(!1)};return document.addEventListener("mousedown",V),()=>{document.removeEventListener("mousedown",V)}},[Pg]);const Vt=V=>{switch(V.type){case"text":if(Array.isArray(V.text))switch(V.text[0].type){case"products":return N.jsx($w,{products:V.text[0].items||[],onValidate:FA=>{Ke("cart",FA)},agentChatResponseColor:W,agentChatResponseBgColor:T,buttonsBgColor:j,buttonColor:X,chatRoundness:F,panelWidth:dA});case"easyspaceform":return N.jsx(Xz,{onValidate:FA=>{Ke("easyspace-form-data",FA)},agentChatResponseColor:W,agentChatResponseBgColor:T,buttonsBgColor:j,buttonColor:X,chatRoundness:F,panelWidth:dA,inputBackgroundColor:l});case"auditec-form":return N.jsx(lW,{onValidate:FA=>{Ke("auditec-form-data",FA)},agentChatResponseColor:W,agentChatResponseBgColor:T,buttonsBgColor:j,buttonColor:X,chatRoundness:F,panelWidth:dA,inputBackgroundColor:l});default:return N.jsx(_o,{remarkPlugins:[$o],components:UE,children:V.text?.replace(/\n/g,`
611
+
611
612
  `)})}else try{const FA=typeof V.text=="string"?JSON.parse(V.text):V.text;switch(FA.type.toLowerCase()){case"products":return N.jsx($w,{products:FA[0].items||[],onValidate:WA=>{Ke("cart",WA)},agentChatResponseColor:W,agentChatResponseBgColor:T,buttonsBgColor:j,buttonColor:X,chatRoundness:F,panelWidth:dA});case"easyspaceform":return N.jsx(Xz,{onValidate:WA=>{Ke("formulaire soumis",WA)},agentChatResponseColor:W,agentChatResponseBgColor:T,buttonsBgColor:j,buttonColor:X,chatRoundness:F,panelWidth:dA,inputBackgroundColor:l});case"evform":return N.jsx(zMA,{onValidate:WA=>{Ke("formulaire soumis",WA)},agentChatResponseColor:W,agentChatResponseBgColor:T,buttonsBgColor:j,buttonColor:X,chatRoundness:F,panelWidth:dA,inputBackgroundColor:l,mainColor:$});case"evform-visiteur":return N.jsx(ZMA,{onValidate:WA=>{Ke("formulaire soumis",WA)},agentChatResponseColor:W,agentChatResponseBgColor:T,buttonsBgColor:j,buttonColor:X,chatRoundness:F,panelWidth:dA,inputBackgroundColor:l,mainColor:$});case"auditec-form":return N.jsx(lW,{onValidate:WA=>{Ke("formulaire soumis",WA)},agentChatResponseColor:W,agentChatResponseBgColor:T,buttonsBgColor:j,buttonColor:X,chatRoundness:F,panelWidth:dA,inputBackgroundColor:l});default:return N.jsx(_o,{remarkPlugins:[$o],components:UE,children:V.text?.replace(/\n/g,`
613
+
612
614
  `)})}}catch{return N.jsx(_o,{remarkPlugins:[$o],components:UE,children:V.text?.replace(/\n/g,`
615
+
613
616
  `)})}case"single-choice":return N.jsxs(N.Fragment,{children:[N.jsx(_o,{remarkPlugins:[$o],components:UE,children:V.text?.replace(/\n/g,`
617
+
614
618
  `)||""}),N.jsx("div",{className:"flex flex-wrap",dir:vE(V.text||"")?"rtl":"ltr",children:V.choices?.map((FA,WA)=>N.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{Ke(FA.title)},style:{background:j,borderRadius:`${F}px`,color:X},dir:vE(FA.title)?"rtl":"ltr",children:N.jsx(VE,{sequence:[FA.title,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],wrapper:"span",cursor:!1,speed:92})},WA))})]});case"image":return N.jsx(N.Fragment,{children:N.jsx("div",{className:"relative group",children:N.jsx("img",{src:V.image,className:"max-w-full max-h-full rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(V.image,"_blank")})})});case"dropdown":return N.jsxs(N.Fragment,{children:[N.jsx(_o,{remarkPlugins:[$o],components:UE,children:V.message?.replace(/\n/g,`
619
+
615
620
  `)}),N.jsx(TMA,{options:V.options||[],message:V.message,allowMultiple:V.allowMultiple||!1,chatRoundness:F,buttonsBgColor:j,buttonColor:X,agentChatResponseColor:W,isRtl:vE(V.message||""),onSend:Ke,onScroll:()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}})]});case"carousel":return N.jsx(sS,{items:V.items||[],chatRoundness:F,agentChatResponseBgColor:T,agentChatResponseColor:W,buttonsBgColor:j,buttonColor:X,inputBackgroundColor:l,onButtonClick:Ke,setMessages:bi});case"card":return N.jsx("div",{className:"mt-2 w-full",children:N.jsx("div",{className:"grid grid-cols-1 gap-3",children:N.jsxs("div",{className:"flex-shrink-0 border rounded-lg p-3 shadow-md",style:{background:T},children:[N.jsx("img",{src:V.image,alt:V.title,className:"max-h-48 w-full object-contain rounded-md mb-2"}),N.jsx("h3",{className:"font-bold",children:V.title}),V.actions?.map((FA,WA)=>N.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{FA.action==="Open URL"?window.open(FA.url,"_blank"):FA.title==="scan"?V.image&&fetch(V.image).then(Fg=>Fg.blob()).then(Fg=>{const JA=URL.createObjectURL(Fg),Bi=document.createElement("a");Bi.href=JA,Bi.download="qrcode.png",document.body.appendChild(Bi),Bi.click(),document.body.removeChild(Bi),URL.revokeObjectURL(JA)}).catch(()=>{alert("Failed to download image.")}):Ke(V.title,FA.payload||void 0)},style:{background:j,borderRadius:`${F}px`,color:X},children:FA.title},WA))]})})});case"video":return N.jsx("div",{className:"relative group w-[200px]",children:N.jsx("video",{src:V.video,className:"w-full rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",controls:!0})});case"file":const KA=V.file?.split(".").pop?.()?.toLowerCase()||"";return N.jsx("div",{className:"p-2 rounded-lg max-w-xs cursor-pointer transition-colors",onClick:()=>window.open(V.file,"_blank"),onMouseEnter:FA=>FA.currentTarget.style.backgroundColor=j,onMouseLeave:FA=>FA.currentTarget.style.backgroundColor="transparent",title:V.title,children:N.jsxs("div",{className:"flex items-center gap-3",children:[N.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center",style:{background:j},children:bW(KA,W)}),N.jsx("div",{className:"flex-1 min-w-0",children:N.jsx("p",{className:"text-sm font-medium truncate",style:{color:W},children:V.title})})]})});case"products":return N.jsx($w,{products:V.products||[],onValidate:FA=>{Ke("cart ",FA)},agentChatResponseColor:W,agentChatResponseBgColor:T,buttonsBgColor:j,buttonColor:X,chatRoundness:F,panelWidth:dA,inputBackgroundColor:l});case"json":switch(V.json?.type){case"text":return N.jsx(_o,{remarkPlugins:[$o],components:UE,children:V.json.content.replace(/\n/g,`
621
+
616
622
  `)});case"image":return N.jsx("div",{className:"relative group",children:N.jsx("img",{src:V.json.content,className:"max-h-48 rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(V.json?.content,"_blank")})});case"video":return N.jsx("div",{className:"relative group",children:N.jsx("video",{src:V.json.content,className:"max-h-48 rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",controls:!0})});case"document":const FA=V.json.content.split(".").pop?.()?.toLowerCase();return N.jsx("div",{className:"w-[300px] p-2 rounded-lg max-w-xs cursor-pointer transition-colors",onClick:()=>window.open(V.json?.content,"_blank"),onMouseEnter:JA=>JA.currentTarget.style.backgroundColor=j,onMouseLeave:JA=>JA.currentTarget.style.backgroundColor="transparent",title:V.json?.title,children:N.jsxs("div",{className:"flex items-center gap-3",children:[N.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center",style:{background:j},children:bW(FA||"",W)}),N.jsx("div",{className:"flex-1 min-w-0",children:N.jsx("p",{className:"text-sm font-medium truncate",style:{color:W},children:V.json.title})})]})});case"audio":return N.jsx("div",{className:"w-[300px]",children:N.jsx(FW,{src:V.json.content,mainColor:r,secondaryColor:s,controlsColor:W})});case"cards":return V.json.content.map((JA,Bi)=>N.jsx("div",{className:"mt-2 w-full",children:N.jsx("div",{className:"grid grid-cols-1 gap-3",children:N.jsxs("div",{className:"flex-shrink-0 border rounded-lg p-3 shadow-md",style:{background:T},children:[N.jsx("img",{src:JA.image,alt:JA.title,className:"max-h-48 w-full rounded-md mb-2"}),N.jsx("h3",{className:"font-bold",children:JA.title}),JA.button?.map((ci,He)=>N.jsx("button",{className:"mb-1 mr-1 px-4 py-1 hover:scale-105 transition-all duration-100",onClick:()=>{if(ci.type==="link"&&typeof ci.action=="string")window.open(ci.action,"_blank");else if(ci.type==="postback"){const Si=(typeof ci.action=="string",ci.action);Ke(ci.label,Si)}else ci.type==="say-something"&&typeof ci.action=="string"&&bi(Si=>[...Si,{sender:"agent",content:ci.action,id:`msg-${Date.now()}`,timestamp:new Date,seen:!0}])},style:{background:j,borderRadius:`${F}px`,color:X},children:ci.label},He))]})})},Bi));case"slider":const WA=V.json.content.map(JA=>({image:JA.image,title:JA.caption,subtitle:"",actions:[]}));return N.jsx(sS,{items:WA,chatRoundness:F,agentChatResponseBgColor:T,agentChatResponseColor:W,buttonsBgColor:j,buttonColor:X,inputBackgroundColor:l,onButtonClick:Ke,setMessages:bi});case"carousel":const Fg=V.json.content.map(JA=>({image:JA.image,title:JA.title,subtitle:JA.description||"",actions:JA.button?.map(Bi=>({title:Bi.label,payload:Bi.action,action:Bi.type,url:typeof Bi.action=="string"?Bi.action:""}))||[]}));return N.jsx(sS,{items:Fg,chatRoundness:F,agentChatResponseBgColor:T,agentChatResponseColor:W,buttonsBgColor:j,buttonColor:X,inputBackgroundColor:l,onButtonClick:Ke,setMessages:bi});case"products":return N.jsx($w,{products:V.json.content,onValidate:JA=>{Ke("cart ",JA)},agentChatResponseColor:W,agentChatResponseBgColor:T,buttonsBgColor:j,buttonColor:X,chatRoundness:F,panelWidth:dA,inputBackgroundColor:l});default:return null}}},jI=async V=>{if(!dg)return;const KA=await fetch(`${fs}/endusers/get-by-username`,{headers:{Authorization:`Bearer ${g?.token}`,"Content-Type":"application/json"},method:"POST",body:JSON.stringify({username:`web_user_${V}`})});if(!KA.ok)throw new Error(`HTTP error! status: ${KA.status}`);return(await KA.json()).id},mB=async V=>{if(!dg)return;const KA=await jI(V);let FA;ge&&(FA={last_name:ge.split(" ")[1]||ge.split(" ")[0]||`web_user_${V}`,first_name:ge.split(" ")[0]||`web_user_${V}`}),Me&&(FA={...FA,phone:Me}),Se&&(FA={...FA,email:Se});const WA=await fetch(`${fs}/endusers/${KA}`,{headers:{Authorization:`Bearer ${g?.token}`,"Content-Type":"application/json"},method:"PUT",body:JSON.stringify(FA)});if(!WA.ok)throw new Error(`HTTP error! status: ${WA.status}`);return await WA.json()},ei=async V=>{V.preventDefault();try{const FA=(await Ne.post(`${fs}/conversations/start-conversation`,{bot_id:g.bot?.botId,externalUser:g.user.id})).data.conversationId;Kg(FA),localStorage.setItem("conversationId",FA),localStorage.setItem("webChatAuth","true"),Ae(!0),oc.emit("join_room",parseInt(FA))}catch(KA){console.error("Error during login:",KA)}},[So,sC]=gg.useState(!1),XC=async()=>{bi([]),localStorage.removeItem("enduserUpdated");const V=localStorage.getItem("phone_client");if(g.bot?.botId==="rockskin"&&V)return Qg(V),localStorage.setItem("externalUser",V),V;const KA=new Uint8Array(16);window.crypto.getRandomValues(KA);const FA=Array.from(KA).map(WA=>WA.toString(16).padStart(2,"0")).join("");Qg(FA),localStorage.setItem("externalUser",FA),localStorage.removeItem("conversationId"),Kg(null)},EB=`linear-gradient(to bottom right, ${w}, ${r}, ${w})`,LI=`linear-gradient(to right, ${r}, ${s})`,lI=`linear-gradient(to right, ${M}, ${c})`,UB=async(V,KA)=>{try{let FA="";if(typeof V=="string")FA=V;else for(const WA of V)WA.type==="text"&&WA.text?FA+=`
617
623
  `+WA.text||"":WA.type==="single-choice"&&WA.choices&&WA.choices.length>0?(FA+=`
618
624
  `+WA.text||"",FA+=`
@@ -680,7 +686,9 @@ Options:
680
686
  }
681
687
  }
682
688
  `}),N.jsxs("div",{className:"fixed top-0 right-0 h-full shadow-2xl !z-[100000000]",style:{width:dA+"px",transition:"transform 0.3s cubic-bezier(0.4,0,0.2,1)",transform:ZA?"translateX(0)":`translateX(${dA}px)`,background:EB},onDrop:rC,onDragOver:vC,onDragEnter:BI,onDragLeave:zi,children:[N.jsx("div",{onMouseDown:eA,className:"absolute left-0 top-0 h-full w-2 cursor-ew-resize z-50 bg-transparent opacity-50 transition-colors",style:{userSelect:"none"},onMouseEnter:V=>V.currentTarget.style.background=r,onMouseLeave:V=>V.currentTarget.style.background="transparent"}),Ug&&N.jsx("div",{className:"absolute inset-0 bg-opacity-20 border-2 border-dashed flex items-center justify-center !z-[9999999]",style:{borderColor:r},children:N.jsxs("div",{className:"text-center ",style:{color:Y},children:[N.jsx(Hu,{className:"w-12 h-12 mx-auto mb-2"}),N.jsx("p",{className:"text-lg font-semibold",children:"Drop files here"})]})}),N.jsx("div",{className:"text-center py-[1px] flex flex-col items-center justify-center gap-1 backdrop-blur-sm",style:{background:r},children:N.jsxs("p",{className:"text-[11px]",style:{color:Y},children:["© Powered by"," ",N.jsx("a",{href:"https://tybot.ma",target:"_blank",rel:"noopener noreferrer",className:"underline font-semibold hover:opacity-80 transition-opacity ",style:{color:Y},children:"Tybot"})]})}),dg?N.jsxs("div",{className:"flex items-center justify-between px-4 py-1 sm:py-3 border-b",style:{background:lI,borderColor:c},children:[N.jsxs("div",{className:"flex items-center gap-3",children:[N.jsx("div",{className:"sm:size-10 size-8 flex items-center justify-center overflow-hidden rounded-full",children:N.jsx("img",{src:de,alt:`${yi} Logo`,className:"w-full h-full"})}),N.jsx("h2",{className:"sm:text-lg text-md font-semibold",style:{color:Y},children:yi})]}),N.jsxs("div",{className:"flex justify-between items-center gap-2 ml-2",children:[N.jsx("button",{className:"transition-colors p-1 rounded-full",style:{color:Y},title:"Reset chat","aria-label":"Reset chat",onClick:()=>sC(!0),onMouseEnter:V=>V.currentTarget.style.background=r,onMouseLeave:V=>V.currentTarget.style.background="transparent",children:N.jsx(UiA,{className:"w-5 h-5"})}),N.jsx("button",{onClick:()=>qA(!0),className:"transition-colors p-1 rounded-full",style:{color:Y},title:"Bot info","aria-label":"Bot info",onMouseEnter:V=>V.currentTarget.style.background=r,onMouseLeave:V=>V.currentTarget.style.background="transparent",children:N.jsx(liA,{className:"w-5 h-5"})}),N.jsx("button",{onClick:()=>{cg(!1),FE.current=!1},className:"transition-colors p-1 rounded-full",style:{color:Y},title:"Close Chat","aria-label":"Close Chat",onMouseEnter:V=>V.currentTarget.style.background=r,onMouseLeave:V=>V.currentTarget.style.background="transparent",children:N.jsx(ha,{className:"w-5 h-5"})})]})]}):N.jsx("div",{className:"flex items-center justify-end px-6 py-3",children:N.jsx("div",{className:"flex items-center",children:N.jsx("button",{onClick:()=>{cg(!1),FE.current=!1},className:"transition-colors p-1 rounded-full",style:{color:g?.inputTextColor||"#FFF"},title:"Close Chat","aria-label":"Close Chat",onMouseEnter:V=>V.currentTarget.style.background=r,onMouseLeave:V=>V.currentTarget.style.background="transparent",children:N.jsx(ha,{className:"w-5 h-5"})})})}),dg&&N.jsxs("div",{ref:A,className:"flex-1 px-2 sm:px-4 py-3 overflow-y-auto space-y-4 scroll-smooth",style:{height:"calc(100% - 160px)",scrollbarWidth:"thin",scrollbarColor:`${r} transparent`,fontSize:k},children:[mi.map(V=>N.jsxs("div",{className:`flex ${V.sender==="agent"?"flex-col sm:flex-row":""} items-start gap-3 ${V.sender==="user"?"flex-row-reverse":""} ${di&&Ce.has(V.id)?"p-2 rounded-lg":""}`,style:{background:di&&Ce.has(V.id)?`${r}20`:"transparent",border:di&&Ce.has(V.id)?`2px solid ${r}`:"none",transition:"all 0.2s ease"},children:[g?.bot?.botId==="easyspace2"&&V.sender!=="user"?N.jsx("div",{className:"sm:size-9 size-7 rounded-full flex items-center justify-center flex-shrink-0 relative overflow-hidden",style:{background:AA},onClick:()=>di&&IB(V.id),children:N.jsx("img",{src:jrA,className:"w-full h-full object-cover"})}):N.jsx("div",{className:"sm:size-8 size-7 rounded-full flex items-center justify-center flex-shrink-0 relative cursor-pointer",style:{background:V.sender==="user"?tA:AA},onClick:()=>di&&IB(V.id),children:di?N.jsx("div",{className:"absolute inset-0 flex items-center justify-center rounded-full",style:{background:"rgba(0,0,0,0.6)"},children:N.jsx("input",{type:"checkbox",checked:Ce.has(V.id),onChange:()=>IB(V.id),className:"w-4 h-4 cursor-pointer",style:{accentColor:r},onClick:KA=>KA.stopPropagation()})}):N.jsx(N.Fragment,{children:V.sender==="user"?N.jsx(ss,{className:"sm:size-4 size-3",style:{color:p}}):N.jsx(Iy,{className:"sm:size-4 size-3",style:{color:P}})})}),N.jsxs("div",{className:`flex flex-col flex-1 ${V.sender==="user"?"items-end":"items-start"}`,children:[V.attachments&&V.attachments.length>0&&N.jsx("div",{className:"flex flex-col items-end w-[88%] mb-2 space-y-2",children:V.attachments.map(KA=>N.jsx(AhA,{attachment:KA,formatFileSize:pQ,mainColor:r,secondaryColor:s,controlsColor:Y},KA.id))}),V.content&&V.sender==="user"?N.jsx("div",{className:"px-4 py-2 backdrop-blur-sm break-words w-fit",style:{wordBreak:"break-word",overflowWrap:"break-word",borderRadius:`${F}px`,maxWidth:`${O}%`,background:$,color:EA},children:N.jsx(_o,{remarkPlugins:[$o],components:UE,children:typeof V.content=="string"?V.content.replace(/\n/g,`
689
+
683
690
  `):""})}):typeof V.content=="object"?V.content.map((KA,FA)=>KA.type==="image"?N.jsx("div",{className:"mb-1 w-72",children:Vt(KA)},FA):N.jsx("div",{className:"mb-1 px-4 py-2 backdrop-blur-sm break-words w-fit",style:{wordBreak:"break-word",overflowWrap:"break-word",borderRadius:`${F}px`,maxWidth:`${O}%`,background:T,color:W},children:Vt(KA)},FA)):typeof V.content=="string"&&V.content?N.jsx("div",{className:"mb-1 px-4 py-2 backdrop-blur-sm break-words w-fit",style:{wordBreak:"break-word",overflowWrap:"break-word",borderRadius:`${F}px`,maxWidth:`${O}%`,background:T,color:W},children:N.jsx(_o,{remarkPlugins:[$o],components:UE,children:V.content.replace(/\n/g,`
691
+
684
692
  `)})}):null,N.jsxs("div",{className:"flex items-center gap-2",children:[N.jsx("span",{className:"ml-1 text-[10px] sm:text-xs mt-1",style:{color:Y},children:V?.timestamp?.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),N.jsx("button",{className:"ml-2 p-1 rounded-full hover:bg-opacity-10 transition-all duration-200",style:{color:vg===V.id?"#10b981":Y},title:vg===V.id?"Copied!":"Copy message","aria-label":"Copy message",onClick:()=>UB((typeof V.content=="string",V.content),V.id),onMouseEnter:KA=>KA.currentTarget.style.background=r,onMouseLeave:KA=>KA.currentTarget.style.background="transparent",children:vg===V.id?N.jsxs("span",{className:"flex gap-1 items-center",children:[N.jsx(AQ,{size:14})," Copied"]}):N.jsxs("span",{className:"flex gap-1 items-center",children:[N.jsx(MiA,{size:14})," Copier"]})}),!di&&N.jsx("button",{className:"p-1 rounded-full hover:bg-opacity-10 transition-all duration-200",style:{color:Y},title:"Share messages","aria-label":"Share messages",onClick:qt,onMouseEnter:KA=>KA.currentTarget.style.background=r,onMouseLeave:KA=>KA.currentTarget.style.background="transparent",children:N.jsxs("span",{className:"flex gap-1 items-center",children:[N.jsx(Qy,{size:14})," Partager"]})})]})]})]},V.id)),lg&&N.jsxs("div",{className:"flex items-start gap-3",children:[N.jsx("div",{className:"sm:size-8 size-7 rounded-full bg-gradient-to-r flex items-center justify-center",style:{background:AA},children:N.jsx(Iy,{className:"sm:size-4 size-3",style:{color:P}})}),N.jsx("div",{className:"px-4 py-2",style:{background:T,color:W,borderRadius:`${F}px`},children:N.jsxs("div",{className:"flex space-x-1",children:[N.jsx("div",{className:"size-1 sm:size-2 rounded-full animate-bounce",style:{background:W}}),N.jsx("div",{className:"size-1 sm:size-2 rounded-full animate-bounce",style:{background:W,animationDelay:"0.1s"}}),N.jsx("div",{className:"size-1 sm:size-2 rounded-full animate-bounce",style:{background:W,animationDelay:"0.2s"}})]})})]})]}),!dg&&N.jsxs("div",{className:"w-full h-full flex flex-col mt-20 items-center p-4 gap-4",children:[N.jsx("h4",{className:"text-sm font-bold mb-2",style:{color:Y},children:"Veuillez fournir vos informations pour commencer à discuter"}),N.jsxs("form",{onSubmit:ei,className:"w-full max-w-xs flex flex-col gap-4 p-6 rounded-2xl shadow-lg",style:{background:r},children:[B?.formFields.includes("full_name")&&N.jsx("input",{type:"text",placeholder:"Nom et prénom",value:ge,onChange:V=>se(V.target.value),className:"py-3 px-4 rounded-lg outline-none transition-all duration-200",style:{borderRadius:"14px",backgroundColor:Y,color:l,borderColor:s}},"full_name"),B?.formFields.includes("phone_number")&&N.jsx("input",{type:"text",placeholder:"Téléphone",value:Me,onChange:V=>he(V.target.value),className:"py-3 px-4 rounded-lg outline-none transition-all duration-200",style:{borderRadius:"14px",backgroundColor:Y,color:l,borderColor:s}},"phone_number"),B?.formFields.includes("email")&&N.jsx("input",{type:"email",placeholder:"Email",value:Se,onChange:V=>FB(V.target.value),className:"py-3 px-4 rounded-lg outline-none transition-all duration-200",style:{borderRadius:"14px",backgroundColor:Y,color:l,borderColor:s}},"email"),N.jsx("button",{type:"submit",className:"py-3 rounded-lg font-bold uppercase outline-none shadow-lg transition-all duration-200",style:{background:`linear-gradient(90deg, ${r}, ${s})`,letterSpacing:"2px",borderRadius:"14px",color:Y},children:"Submit"})]})]}),dg&&N.jsx("div",{className:"absolute bottom-0 left-0 right-0 p-4 pt-0 pb-3",style:{background:`linear-gradient(to top, ${w}, transparent)`},children:di?N.jsxs("div",{className:"flex items-center justify-between gap-3 p-4 rounded-lg",style:{background:l},children:[N.jsxs("div",{className:"flex items-center gap-2",children:[N.jsxs("button",{onClick:qt,className:"px-4 py-2 rounded-lg font-medium transition-all duration-200 flex items-center gap-2",style:{background:"transparent",color:Y,border:`1px solid ${Y}`},onMouseEnter:V=>V.currentTarget.style.background=r,onMouseLeave:V=>V.currentTarget.style.background="transparent",children:[N.jsx(ha,{size:16}),"Annuler"]}),N.jsxs("span",{className:"text-sm",style:{color:Y},children:[Ce.size," message",Ce.size!==1?"s":""," sélectionné",Ce.size!==1?"s":""]})]}),N.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[N.jsx("button",{onClick:Ht,className:"px-4 py-2 rounded-lg font-medium transition-all duration-200",style:{background:s,color:Y},onMouseEnter:V=>V.currentTarget.style.opacity="0.9",onMouseLeave:V=>V.currentTarget.style.opacity="1",children:"Tout sélectionner"}),N.jsxs("button",{onClick:dB,disabled:Ce.size===0,className:"px-4 py-2 rounded-lg font-medium transition-all duration-200 flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",style:{background:r,color:Y},onMouseEnter:V=>!V.currentTarget.disabled&&(V.currentTarget.style.opacity="0.9"),onMouseLeave:V=>V.currentTarget.style.opacity="1",children:[N.jsx(hiA,{size:16}),"Générer PDF"]})]})]}):N.jsxs(N.Fragment,{children:[Gg.length>0&&N.jsx("div",{className:"flex flex-wrap gap-2 mb-3 p-3 bg-opacity-70 rounded-lg",style:{background:l},children:Gg.map(V=>N.jsx(ghA,{attachment:V,onRemove:()=>PC(V.id)},V.id))}),N.jsxs("div",{className:"flex items-center w-full gap-2 relative",children:[N.jsx("div",{className:"flex-1 relative",children:N.jsxs(N.Fragment,{children:[Ui!=="recording"&&Ui!=="paused"?N.jsxs(N.Fragment,{children:[N.jsx("button",{id:"upload-button-toggle",type:"button",onClick:()=>{Og||lg||ui(V=>!V)},className:"absolute left-1 bottom-[10px] sm:bottom-3 size-8 sm:size-9 rounded-full flex items-center justify-center transition-all duration-200 z-10 hover:bg-opacity-10",style:{color:Y},onMouseEnter:V=>V.currentTarget.style.background=r,onMouseLeave:V=>V.currentTarget.style.background="",children:N.jsx(Th,{className:`size-4 sm:size-5 transition-transform duration-200 ${Pg?"rotate-45":""}`})}),N.jsx("button",{type:"button",onClick:()=>{Og||lg||gB()},className:"absolute right-1 bottom-[10px] sm:bottom-3 size-8 sm:size-9 rounded-full flex items-center justify-center transition-all duration-200 z-10",style:{color:Y},onMouseEnter:V=>V.currentTarget.style.background=r,onMouseLeave:V=>V.currentTarget.style.background="",children:N.jsx(RiA,{className:"size-4 sm:size-5"})})]}):N.jsxs(N.Fragment,{children:[N.jsx("button",{type:"button",onClick:()=>{Ri.current=!0,GE()},className:"absolute left-1 bottom-3 w-9 h-9 hover:bg-red-100 hover:bg-opacity-50 rounded-full flex items-center justify-center text-red-500 hover:text-red-600 z-10 after:w-2 after:h-2 after:bg-red-500 after:absolute after:rounded-full after:top-1/2 after:-right-3 after:-translate-y-1/2 after:animate-bounce",children:N.jsx(piA,{className:"w-5 h-5"})}),N.jsx("button",{type:"button",onClick:()=>{$g?(bg(!1),ne()):(bg(!0),ZE())},className:"absolute right-11 bottom-3 w-9 h-9 rounded-full flex items-center justify-center transition-all duration-200 z-10",style:{color:Y},children:$g?N.jsx(siA,{className:"w-7 h-7"}):N.jsx(niA,{className:"w-7 h-7"})}),N.jsxs("div",{className:"absolute left-16 bottom-4 flex items-center gap-4 z-10 ",style:{color:Y},children:[N.jsx("p",{children:DI}),N.jsx("p",{className:`${Ui==="recording"?"animate-pulse":""}`,children:Ui==="recording"?"Recording...":Ui==="paused"?"Paused":"Starting..."})]}),N.jsx("button",{type:"button",onClick:()=>{GE()},className:"absolute right-1 bottom-3 w-9 h-9 rounded-full flex items-center justify-center transition-all duration-200 z-10",style:{color:Y,background:"green"},children:N.jsx(AQ,{className:"w-5 h-5"})})]}),Pg&&N.jsxs("div",{className:"absolute bottom-12 left-0 rounded-lg shadow-xl border border-gray-700 py-2 min-w-48 z-10",style:{background:Z},children:[N.jsxs("button",{id:"document-button",onClick:()=>iB("document"),className:"w-full px-4 py-3 text-left flex items-center gap-3 transition-colors",style:{color:y},onMouseEnter:V=>V.currentTarget.style.background=z,onMouseLeave:V=>V.currentTarget.style.background="",children:[N.jsx("div",{className:"w-8 h-8 bg-blue-600 rounded-full flex items-center justify-center",children:N.jsx(ns,{className:"w-4 h-4 text-white"})}),N.jsx("span",{children:"Document"})]}),N.jsxs("button",{id:"image-button",onClick:()=>iB("image"),className:"w-full px-4 py-3 text-left flex items-center gap-3 transition-colors",style:{color:y},onMouseEnter:V=>V.currentTarget.style.background=z,onMouseLeave:V=>V.currentTarget.style.background="",children:[N.jsx("div",{className:"w-8 h-8 bg-green-600 rounded-full flex items-center justify-center",children:N.jsx(DiA,{className:"w-4 h-4 text-white"})}),N.jsx("span",{children:"Photos"})]}),N.jsxs("button",{id:"video-button",onClick:()=>iB("video"),className:"w-full px-4 py-3 text-left flex items-center gap-3 transition-colors",style:{color:y},onMouseEnter:V=>V.currentTarget.style.background=z,onMouseLeave:V=>V.currentTarget.style.background="",children:[N.jsx("div",{className:"w-8 h-8 bg-red-600 rounded-full flex items-center justify-center",children:N.jsx(ay,{className:"w-4 h-4 text-white"})}),N.jsx("span",{children:"Videos"})]}),N.jsxs("button",{id:"audio-button",onClick:()=>iB("audio"),className:"w-full px-4 py-3 text-left flex items-center gap-3 transition-colors",style:{color:y},onMouseEnter:V=>V.currentTarget.style.background=z,onMouseLeave:V=>V.currentTarget.style.background="",children:[N.jsx("div",{className:"w-8 h-8 bg-purple-600 rounded-full flex items-center justify-center",children:N.jsx(qu,{className:"w-4 h-4 text-white"})}),N.jsx("span",{children:"Audio"})]})]}),N.jsx("textarea",{id:"message-input",ref:aC,className:`disabled:opacity-50 w-full pt-3 text-xs sm:text-sm sm:pt-4 px-12 resize-none min-h-10 sm:min-h-12 max-h-32 overflow-y-auto focus:outline-none backdrop-blur-sm ${Ui==="recording"||Ui==="paused"?"cursor-default":""}`,value:Ui==="recording"||Ui==="paused"?"":LA,onChange:V=>Dg(V.target.value),placeholder:Ui==="recording"||Ui==="paused"?"":"Type your message...",rows:1,onKeyDown:V=>{V.key==="Enter"&&!V.shiftKey&&(V.preventDefault(),Ke())},style:{borderRadius:`${R}px`,background:l,color:Y,scrollbarWidth:"thin",scrollbarColor:`${r} transparent`},readOnly:Ui==="recording"||Ui==="paused",disabled:lg||Og})]})}),(LA.trim()||Gg.length!==0)&&N.jsx("div",{className:"w-min",children:N.jsx("button",{onClick:()=>Ke(),className:"w-10 h-10 rounded-full flex items-center justify-center transition-all duration-200 transform hover:scale-105",style:{background:r,color:Y},children:N.jsx(oy,{className:"w-5 h-5"})})})]}),N.jsx("input",{ref:i,type:"file",multiple:!0,className:"hidden",accept:"image/*",onChange:V=>V.target.files&&mE(V.target.files,i)}),N.jsx("input",{ref:e,type:"file",multiple:!0,className:"hidden",accept:"video/*",onChange:V=>V.target.files&&mE(V.target.files,e)}),N.jsx("input",{ref:E,type:"file",multiple:!0,className:"hidden",accept:"audio/*",onChange:V=>V.target.files&&mE(V.target.files,E)}),N.jsx("input",{ref:I,type:"file",multiple:!0,className:"hidden",accept:".pdf,.doc,.docx,.txt,.csv,.xlsx,.ppt,.pptx,.zip,.rar",onChange:V=>V.target.files&&mE(V.target.files,I)})]})}),tg&&N.jsx("div",{className:"fixed inset-0 z-[998] flex items-center justify-center",style:{background:"rgba(0,0,0,0.45)",backdropFilter:"blur(4px)"},onClick:()=>qA(!1),children:N.jsxs("div",{className:"relative w-full max-w-md mx-4 p-6 rounded-2xl shadow-2xl border overflow-hidden animate-[fadeIn_0.25s_ease]",style:{background:`linear-gradient(145deg, ${w}, ${r}, ${s})`,borderRadius:`${R}px`,borderColor:r},onClick:V=>V.stopPropagation(),children:[N.jsx("button",{onClick:()=>qA(!1),className:"absolute top-3 right-3 p-1 rounded-full transition-colors","aria-label":"Close bot info",style:{color:Y},onMouseEnter:V=>V.currentTarget.style.background=r,onMouseLeave:V=>V.currentTarget.style.background="transparent",children:N.jsx(ha,{className:"w-5 h-5"})}),g?.bot?N.jsxs("div",{className:"flex flex-col gap-4",children:[N.jsxs("div",{className:"flex items-center gap-4",children:[N.jsx("div",{className:"w-16 h-16 rounded-full p-1 flex items-center justify-center shadow-md overflow-hidden",style:{background:`linear-gradient(to bottom right, ${r}, ${s})`,borderRadius:"1.5rem"},children:N.jsx("img",{src:de,alt:`${yi} logo`||"Bot avatar",className:"w-full h-full rounded-full",style:{borderRadius:"1.5rem"}})}),N.jsx("div",{className:"min-w-0",children:N.jsx("h3",{className:"text-lg font-semibold truncate",title:yi,style:{color:Y},children:yi})})]}),B?.description&&N.jsx("div",{className:"max-h-40 overflow-y-auto pr-1 custom-scrollbar",children:N.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-line",style:{wordBreak:"break-word",color:Y},children:B.description})}),N.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",style:{color:Y},children:[Array.isArray(B?.phone_numbers)&&B.phone_numbers.length>0&&N.jsxs("div",{className:"flex flex-col gap-0.5",children:[N.jsxs("span",{className:"uppercase tracking-wide font-bold",style:{color:Y},children:["Phone number",B.phone_numbers.length>1?"s":""]}),N.jsx("div",{className:"flex flex-col gap-1 flex-wrap",children:B.phone_numbers.map((V,KA)=>N.jsx("a",{href:`tel:${V}`,className:"font-medium break-all",style:{color:Y},children:V},KA))})]}),Array.isArray(B?.websites)&&B.websites.length>0&&N.jsxs("div",{className:"flex flex-col gap-0.5",children:[N.jsxs("span",{className:"uppercase tracking-wide font-bold",style:{color:Y},children:["Website",B.websites.length>1?"s":""]}),N.jsx("div",{className:"flex flex-col gap-1 flex-wrap",children:B.websites.map((V,KA)=>N.jsx("a",{className:"break-all underline font-semibold",href:V,target:"_blank",rel:"noopener noreferrer",children:V},KA))})]}),Array.isArray(B?.emails)&&B.emails.length>0&&N.jsxs("div",{className:"flex flex-col gap-0.5",children:[N.jsxs("span",{className:"uppercase tracking-wide font-bold",style:{color:Y},children:["Email",B.emails.length>1?"s":""]}),N.jsx("div",{className:"flex flex-col gap-1",children:B.emails.map((V,KA)=>N.jsx("a",{href:`mailto:${V}`,className:"font-medium break-all",style:{color:Y},children:V},KA))})]}),Array.isArray(B?.channels)&&B?.channels.length>0&&N.jsxs("div",{className:"flex flex-col gap-2 mt-3",children:[N.jsx("span",{className:"uppercase tracking-wide font-bold text-xs",style:{color:Y},children:"Connect with us"}),N.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:B?.channels.map((V,KA)=>{const FA=V.channel_name?.toLowerCase()||"",{icon:WA,color:Fg,hoverColor:JA}=TB(FA);return N.jsx("a",{href:V.link,target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-center p-2.5 rounded-2xl transition-all duration-200 hover:scale-105 shadow-md",style:{background:Fg,color:"#FFFFFF"},title:V.channel_name,onMouseEnter:Bi=>Bi.currentTarget.style.background=JA,onMouseLeave:Bi=>Bi.currentTarget.style.background=Fg,children:WA},KA)})})]})]})]}):N.jsxs("div",{className:"text-center",style:{color:Y},children:[N.jsx("p",{className:"text-sm",children:"No bot selected."}),N.jsx("button",{type:"button",onClick:()=>qA(!1),className:"mt-4 px-4 py-2 rounded-lg text-sm font-medium bg-white/10 hover:bg-white/20 text-black transition-colors",style:{borderRadius:`${R}px`},children:"Close"})]})]})}),So&&N.jsx("div",{className:"fixed inset-0 z-[998] flex items-center justify-center",style:{background:"rgba(0,0,0,0.45)",backdropFilter:"blur(4px)"},onClick:()=>sC(!1),children:N.jsxs("div",{className:"relative w-full max-w-md mx-4 p-6 rounded-2xl shadow-2xl border overflow-hidden animate-[fadeIn_0.25s_ease]",style:{background:`linear-gradient(145deg, ${w}, ${r}, ${s})`,borderRadius:`${R}px`,borderColor:r},onClick:V=>V.stopPropagation(),children:[N.jsx("button",{onClick:()=>sC(!1),className:"absolute top-3 right-3 p-1 rounded-full transition-colors","aria-label":"Close reset chat",style:{color:Y},onMouseEnter:V=>V.currentTarget.style.background=r,onMouseLeave:V=>V.currentTarget.style.background="transparent",children:N.jsx(ha,{className:"w-5 h-5"})}),N.jsx("h3",{className:"text-lg font-semibold mb-2 ",style:{color:Y},children:"Reset Chat?"}),N.jsx("p",{className:"mb-4",style:{color:Y},children:"Are you sure you want to reset the chat? This will clear all messages."}),N.jsxs("div",{className:"flex justify-end gap-2",children:[N.jsx("button",{className:"px-4 py-2 rounded bg-white/80 text-gray-900 hover:bg-white",onClick:()=>sC(!1),children:"Cancel"}),N.jsx("button",{className:"px-4 py-2 rounded bg-red-600 text-white hover:bg-red-700",onClick:async()=>{sC(!1),await XC()},children:"Confirm"})]})]})})]}),g.bot?.botId==="easyspace2"?N.jsxs("div",{className:`${ZA?"hidden":"fixed"} select-none bottom-2 right-1 sm:right-10`,style:{zIndex:999,animation:ZA?"none":"smoothFloat 3s ease-in-out infinite"},children:[!ZA&&N.jsxs("div",{className:"absolute top-[70px] -left-10 sm:top-40 sm:-left-10 -translate-x-1/2 bg-white rounded-lg shadow-lg p-3 min-w-[100px] cursor-pointer",style:{animation:"slideInFromRight 0.5s ease-out"},onClick:ZB,children:[N.jsx("div",{className:"flex items-center gap-2 w-full",children:N.jsx("div",{className:"flex-1",children:N.jsx("p",{className:"text-sm font-medium text-gray-900",children:N.jsx(VE,{sequence:[kS(B?.widgetLoadBehavior)],cursor:!1,speed:50})})})}),N.jsx("div",{className:"absolute top-full right-9 border-l-[8px] border-r-[8px] border-t-[8px] border-l-transparent border-r-transparent border-t-white w-0 h-0"})]}),N.jsxs("button",{onClick:ZB,className:"transform transition-transform hover:scale-95",style:{cursor:"pointer",background:"transparent",border:"none",padding:0},children:[N.jsx("img",{src:HrA,alt:"Rihab",className:"w-auto h-[250px] sm:h-[400px] object-contain"}),II>0&&!ZA?N.jsx(N.Fragment,{children:N.jsx("audio",{src:"https://public-assets.content-platform.envatousercontent.com/3a5b6a9c-bead-4397-bc15-393c0f6edb9f/87e342b2-9863-4e6c-83af-edeb375b338d/preview.mp3",className:"hidden",autoPlay:!0})}):null]})]}):["test","asks-bot","recruteur","auditec"].includes(g.bot?.botId)||!B.icon?N.jsxs("div",{className:`${ZA?"hidden":"fixed"} select-none bottom-2 right-1 sm:right-10`,style:{zIndex:999},children:[!ZA&&N.jsxs("div",{className:"absolute -left-24 top-0 -translate-x-1/2 bg-white rounded-lg shadow-lg p-3 min-w-[100px] cursor-pointer",style:{animation:"slideInFromRight 0.5s ease-out"},onClick:ZB,children:[N.jsx("div",{className:"flex items-center gap-2 w-full",children:N.jsx("div",{className:"flex-1",children:N.jsx("p",{className:"text-sm font-medium text-gray-900",children:N.jsx(VE,{sequence:[kS(B?.widgetLoadBehavior)],cursor:!1,speed:50})})})}),N.jsx("div",{className:"absolute -right-2 top-1/2 -translate-y-1/2 border-t-[8px] border-b-[8px] border-l-[8px] border-t-transparent border-b-transparent border-l-white w-0 h-0"})]}),N.jsxs("button",{onClick:ZB,className:"transform transition-transform hover:scale-95 cursor-pointer bg-transparent border-0 p-0",children:[N.jsx("img",{src:g?.bot.botId==="auditec"?LrA:fz,alt:"Tybot",className:`w-auto ${g?.bot.botId==="auditec"?"h-[130px] sm:h-[150px]":"h-[100px] sm:h-[120px]"} object-contain`}),II>0&&!ZA?N.jsx(N.Fragment,{children:N.jsx("audio",{src:"https://public-assets.content-platform.envatousercontent.com/3a5b6a9c-bead-4397-bc15-393c0f6edb9f/87e342b2-9863-4e6c-83af-edeb375b338d/preview.mp3",className:"hidden",autoPlay:!0})}):null]})]}):_==="middle-right"?N.jsx("div",{className:"fixed top-1/2 -translate-y-1/2",style:{right:"0",transform:ZA?`translateX(-${dA}px)`:"translateX(0)",transition:"transform 0.3s cubic-bezier(0.4,0,0.2,1)",zIndex:1e3},children:N.jsxs("button",{onClick:()=>{cg(V=>!V),FE.current=!ZA,ZA||QC()},className:"px-4 py-3 shadow-lg transform",style:{background:LI,borderTopLeftRadius:`${S}px`,borderBottomLeftRadius:`${H}px`,borderTopRightRadius:`${q}px`,borderBottomRightRadius:`${x}px`,zIndex:1e7},children:[N.jsx("img",{src:de,alt:"Tybot logo",className:"w-7 h-7"}),II>0&&!ZA?N.jsxs(N.Fragment,{children:[N.jsx("audio",{src:"https://public-assets.content-platform.envatousercontent.com/3a5b6a9c-bead-4397-bc15-393c0f6edb9f/87e342b2-9863-4e6c-83af-edeb375b338d/preview.mp3",className:"hidden",autoPlay:!0}),N.jsx("span",{className:"absolute -top-1 -left-1 bg-red-500 text-white text-xs font-medium size-5 rounded-full flex items-center justify-center",children:II>9?"9+":II})]}):null]})}):N.jsxs("div",{ref:yA,className:`${ZA?"hidden":"fixed"} rounded-full select-none`,style:{left:`${Rg.x}px`,top:`${Rg.y}px`,zIndex:999,cursor:SA?"grabbing":"grab",animation:(II>0||Eg)&&!ZA&&!SA?"gentlePulse 2s ease-in-out infinite, smoothFloat 3s ease-in-out infinite":"none",transition:SA?"none":"all 0.2s ease-out"},children:[Eg&&!ZA&&!SA&&N.jsxs("div",{className:`absolute ${_==="bottom-right"?"bottom-[110%] right-2":_==="bottom-left"?"bottom-16 left-0":"top-1/2 right-20 -translate-y-1/2"} bg-white rounded-lg shadow-lg p-3 min-w-[250px] cursor-pointer`,style:{animation:"slideInFromRight 0.5s ease-out"},onClick:ZB,children:[N.jsx("div",{className:"flex items-center gap-2 w-full",children:N.jsx("div",{className:"flex-1",children:N.jsx("p",{className:"text-sm font-medium text-gray-900",children:N.jsx(VE,{sequence:[kS(B?.widgetLoadBehavior)],cursor:!1,speed:50})})})}),N.jsx("div",{className:`absolute ${_==="bottom-right"?"top-full right-6 border-l-[8px] border-r-[8px] border-t-[8px] border-l-transparent border-r-transparent":_==="bottom-left"?"top-full right-6 border-l-[8px] border-r-[8px] border-t-[8px] border-l-transparent border-r-transparent border-t-white":"top-1/2 right-0 border-l-[8px] border-t-[8px] border-b-[8px] border-l-white border-t-transparent border-b-transparent transform translate-x-full -translate-y-1/2"} w-0 h-0`})]}),N.jsxs("button",{onClick:ZB,onMouseDown:nC,onTouchStart:xt,className:"rounded-full size-[67px] p-1 shadow-lg transform",style:{background:LI,cursor:SA?"grabbing":"grab"},onMouseEnter:V=>!SA&&(V.currentTarget.style.transform="scale(0.95)"),onMouseLeave:V=>!SA&&(V.currentTarget.style.transform="scale(1)"),children:[N.jsx("div",{className:"size-full overflow-hidden rounded-full",children:N.jsx("img",{src:de,alt:"Tybot logo",className:"w-full h-full"})}),II>0&&!ZA?N.jsxs(N.Fragment,{children:[N.jsx("audio",{src:"https://public-assets.content-platform.envatousercontent.com/3a5b6a9c-bead-4397-bc15-393c0f6edb9f/87e342b2-9863-4e6c-83af-edeb375b338d/preview.mp3",className:"hidden",autoPlay:!0}),N.jsx("span",{className:"absolute -top-0 -left-0 bg-red-500 text-white text-xs font-medium size-5 rounded-full flex items-center justify-center",children:II>9?"9+":II})]}):null]})]})]})};function XhA(g){const A="tybot-widget-container";let i=document.getElementById(A);i||(i=document.createElement("div"),i.id=A,document.body.appendChild(i));const e=i.shadowRoot??i.attachShadow({mode:"open"});if(!document.querySelector("#tybot-widget-fonts")){const t=document.createElement("link");t.rel="preconnect",t.href="https://fonts.googleapis.com";const o=document.createElement("link");o.rel="preconnect",o.href="https://fonts.gstatic.com",o.crossOrigin="";const a=document.createElement("link");a.id="tybot-widget-fonts",a.rel="stylesheet",a.href="https://fonts.googleapis.com/css2?family=Nunito:ital@0;1&display=swap",document.head.append(t),document.head.append(o),document.head.append(a)}if(!e.querySelector("#tybot-widget-style")){const t=document.createElement("style");t.id="tybot-widget-style",t.textContent=YP,e.appendChild(t)}const E=e.querySelector("#tybot-widget-root");E&&E.remove();const I=document.createElement("div");I.id="tybot-widget-root",e.appendChild(I),RP.createRoot(I).render(N.jsx(PhA,{config:g}))}/*!
685
693
  * html2canvas 1.4.1 <https://html2canvas.hertzen.com>
686
694
  * Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tybotflow-widget",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "description": "A modern, customizable React widget for Tybot chat integration.",
5
5
  "license": "ISC",
6
6
  "main": "dist/index.umd.js",