tybotflow-widget 0.5.9 → 0.6.0

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
@@ -63133,7 +63133,7 @@ Object.assign(Oc, {
63133
63133
  io: Oc,
63134
63134
  connect: Oc
63135
63135
  });
63136
- const Zs = "https://migration-tybot.tybot.ma/api/v1", IuA = "https://migration-tybot.tybot.ma/api/v1/chatbots-config", Kv = "https://migration-meta.tybotflow.com/", mz = Kv + "webhook/v", VM = Oc(Kv, {
63136
+ const Zs = "https://api.tybotflow.com/api/v1", IuA = "https://api.tybotflow.com/api/v1/chatbots-config", Kv = "https://migration-meta.tybotflow.com/", mz = Kv + "webhook/v", VM = Oc(Kv, {
63137
63137
  transports: ["websocket", "polling"],
63138
63138
  reconnection: !0,
63139
63139
  reconnectionAttempts: 3,
package/dist/index.umd.js CHANGED
@@ -597,7 +597,7 @@ end`};A.events.push(["putFont",function(B){(function(t){var C=t.font,o=t.out,r=t
597
597
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
598
598
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
599
599
  PERFORMANCE OF THIS SOFTWARE.
600
- ***************************************************************************** */function uq(e,A){const[g,i]=ee.useState(null),I=ee.useMemo(()=>Object.entries(A).flat(),[A]);return ee.useEffect(()=>{if(!e?.current)return;const B=MS.create(Object.assign(Object.assign({},A),{container:e.current}));return i(B),()=>{B.destroy()}},[e,...I]),g}const Yq=/^on([A-Z])/,WwA=e=>Yq.test(e);function PwA(e,A){const g=ee.useMemo(()=>Object.entries(A).flat(),[A]);ee.useEffect(()=>{if(!e)return;const i=Object.entries(A);if(!i.length)return;const I=i.map(([B,t])=>{const C=B.replace(Yq,(o,r)=>r.toLowerCase());return e.on(C,(...o)=>t(e,...o))});return()=>{I.forEach(B=>B())}},[e,...g])}ee.memo(e=>{const A=ee.useRef(null),[g,i]=function(I){return ee.useMemo(()=>{const B=Object.assign({},I),t=Object.assign({},I);for(const C in B)WwA(C)?delete B[C]:delete t[C];return[B,t]},[I])}(e);return PwA(uq(A,g),i),y.jsx("div",{ref:A})});function vwA(e){var{container:A}=e;const g=uq(A,function(I,B){var t={};for(var C in I)Object.prototype.hasOwnProperty.call(I,C)&&B.indexOf(C)<0&&(t[C]=I[C]);if(I!=null&&typeof Object.getOwnPropertySymbols=="function"){var o=0;for(C=Object.getOwnPropertySymbols(I);o<C.length;o++)B.indexOf(C[o])<0&&Object.prototype.propertyIsEnumerable.call(I,C[o])&&(t[C[o]]=I[C[o]])}return t}(e,["container"])),i=function(I){const[B,t]=ee.useState(!1),[C,o]=ee.useState(!1),[r,a]=ee.useState(!1),[s,M]=ee.useState(0);return ee.useEffect(()=>{if(!I)return;const w=[I.on("load",()=>{t(!1),o(!1),M(0)}),I.on("ready",()=>{t(!0),o(!1),a(!1),M(0)}),I.on("finish",()=>{a(!0)}),I.on("play",()=>{o(!0)}),I.on("pause",()=>{o(!1)}),I.on("timeupdate",()=>{M(I.getCurrentTime())}),I.on("destroy",()=>{t(!1),o(!1)})];return()=>{w.forEach(c=>c())}},[I]),ee.useMemo(()=>({isReady:B,isPlaying:C,hasFinished:r,currentTime:s}),[C,r,s,B])}(g);return ee.useMemo(()=>Object.assign(Object.assign({},i),{wavesurfer:g}),[i,g])}const Gq=({src:e,mainColor:A,secondaryColor:g,controlsColor:i})=>{const I=ee.useRef(null),[B,t]=ee.useState(1),{wavesurfer:C,isPlaying:o}=vwA({container:I,waveColor:A,progressColor:g,barWidth:2,height:50,url:e}),r=()=>{C&&C.playPause()},a=()=>{const w=B===0?1:0;t(w),C?.setVolume(w)},s=()=>{C?.skip(-.096)},M=()=>{C?.skip(.096)};return y.jsxs("div",{className:"flex w-full flex-col items-center rounded-xl pt-1",children:[y.jsx("div",{ref:I,className:"w-full px-2"}),y.jsxs("div",{className:"flex w-full items-center justify-between",children:[y.jsx("div",{className:"relative flex items-center",children:y.jsx("button",{className:"transition-colors",style:{color:i},onClick:a,"aria-label":"Toggle volume",children:B===0?y.jsx(pgA,{size:20}):y.jsx(SgA,{size:20})})}),y.jsxs("div",{className:"-ml-9 flex flex-1 cursor-auto justify-center gap-2 rounded-full py-2 text-white",children:[y.jsx("button",{onClick:s,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:i},"aria-label":"Step back",children:y.jsx(dgA,{})}),y.jsx("button",{onClick:r,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:i},"aria-label":o?"Pause":"Play",children:o?y.jsx(lgA,{}):y.jsx(ugA,{})}),y.jsx("button",{onClick:M,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:i},"aria-label":"Step forward",children:y.jsx(UgA,{})})]})]})]})},XwA=({attachment:e,formatFileSize:A,mainColor:g,secondaryColor:i,controlsColor:I})=>{const{type:B,url:t,name:C,size:o}=e;switch(B){case"image":return y.jsxs("div",{className:"relative group",children:[y.jsx("img",{src:t,alt:C,className:"max-w-xs max-h-48 size-full rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(t,"_blank")}),y.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 y.jsxs("div",{className:"max-w-xs",children:[y.jsx("video",{src:t,controls:!0,className:"w-full max-h-48 rounded-lg",preload:"metadata",onError:()=>{console.error("Video failed to load:",t)},children:"Your browser does not support the video tag."}),y.jsxs("div",{className:"flex text-xs text-white mt-1 w-full overflow-hidden whitespace-nowrap text-ellipsis",children:[y.jsx("span",{className:"block w-full overflow-hidden whitespace-nowrap text-ellipsis",title:C,children:C}),y.jsxs("span",{className:"ml-2",children:["• ",A(o)]})]})]});case"audio":return y.jsxs("div",{className:"bg-gray-800 bg-opacity-70 p-3 rounded-lg flex-1 w-full",children:[y.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[y.jsx(Ju,{className:"w-4 h-4",style:{color:g}}),y.jsx("span",{className:"text-sm font-medium truncate text-white",title:C,children:C})]}),y.jsx(Gq,{src:t,mainColor:g,secondaryColor:i,controlsColor:I}),y.jsx("p",{className:"text-xs text-gray-400 mt-1",children:A(o)})]});case"document":return y.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(t,"_blank"),children:y.jsxs("div",{className:"flex items-center gap-3",children:[y.jsx("div",{className:"w-10 h-10 bg-purple-600 rounded-lg flex items-center justify-center",children:y.jsx(ns,{className:"w-5 h-5 text-white"})}),y.jsxs("div",{className:"flex-1 min-w-0",children:[y.jsx("p",{className:"text-sm font-medium truncate text-white",children:C}),y.jsx("p",{className:"text-xs text-gray-400",children:A(o)})]})]})});default:return null}},_wA=ee.memo(({attachment:e,onRemove:A})=>y.jsxs("div",{className:"relative group w-24 h-24 rounded-xl overflow-hidden bg-gray-900 shadow-md border border-gray-700",children:[e.type==="image"&&e.url?y.jsx("img",{src:e.url,alt:e.name,className:"w-full h-full object-cover"}):y.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center text-gray-300 px-1 text-center text-xs",children:[e.type==="video"&&y.jsx(oy,{className:"w-5 h-5 mb-1 text-red-400"}),e.type==="audio"&&y.jsx(Ju,{className:"w-5 h-5 mb-1 text-green-400"}),e.type==="document"&&y.jsx(Ey,{className:"w-5 h-5 mb-1 text-yellow-400"}),y.jsx("span",{className:"w-full truncate",title:e.name,children:e.name})]}),y.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:y.jsx(wr,{className:"w-3 h-3"})})]})),pC=Object.create(null);pC.open="0",pC.close="1",pC.ping="2",pC.pong="3",pC.message="4",pC.upgrade="5",pC.noop="6";const Ac=Object.create(null);Object.keys(pC).forEach(e=>{Ac[pC[e]]=e});const cS={type:"error",data:"parser error"},Rq=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",Fq=typeof ArrayBuffer=="function",dq=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,DS=({type:e,data:A},g,i)=>Rq&&A instanceof Blob?g?i(A):Uq(A,i):Fq&&(A instanceof ArrayBuffer||dq(A))?g?i(A):Uq(new Blob([A]),i):i(pC[e]+(A||"")),Uq=(e,A)=>{const g=new FileReader;return g.onload=function(){const i=g.result.split(",")[1];A("b"+(i||""))},g.readAsDataURL(e)};function mq(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let lS;function $wA(e,A){if(Rq&&e.data instanceof Blob)return e.data.arrayBuffer().then(mq).then(A);if(Fq&&(e.data instanceof ArrayBuffer||dq(e.data)))return A(mq(e.data));DS(e,!1,g=>{lS||(lS=new TextEncoder),A(lS.encode(g))})}const Sq="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bs=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let e=0;e<Sq.length;e++)bs[Sq.charCodeAt(e)]=e;const AhA=e=>{let A=e.length*.75,g=e.length,i,I=0,B,t,C,o;e[e.length-1]==="="&&(A--,e[e.length-2]==="="&&A--);const r=new ArrayBuffer(A),a=new Uint8Array(r);for(i=0;i<g;i+=4)B=bs[e.charCodeAt(i)],t=bs[e.charCodeAt(i+1)],C=bs[e.charCodeAt(i+2)],o=bs[e.charCodeAt(i+3)],a[I++]=B<<2|t>>4,a[I++]=(t&15)<<4|C>>2,a[I++]=(C&3)<<6|o&63;return r},ehA=typeof ArrayBuffer=="function",uS=(e,A)=>{if(typeof e!="string")return{type:"message",data:pq(e,A)};const g=e.charAt(0);return g==="b"?{type:"message",data:ghA(e.substring(1),A)}:Ac[g]?e.length>1?{type:Ac[g],data:e.substring(1)}:{type:Ac[g]}:cS},ghA=(e,A)=>{if(ehA){const g=AhA(e);return pq(g,A)}else return{base64:!0,data:e}},pq=(e,A)=>{switch(A){case"blob":return e instanceof Blob?e:new Blob([e]);case"arraybuffer":default:return e instanceof ArrayBuffer?e:e.buffer}},Kq="",ihA=(e,A)=>{const g=e.length,i=new Array(g);let I=0;e.forEach((B,t)=>{DS(B,!1,C=>{i[t]=C,++I===g&&A(i.join(Kq))})})},IhA=(e,A)=>{const g=e.split(Kq),i=[];for(let I=0;I<g.length;I++){const B=uS(g[I],A);if(i.push(B),B.type==="error")break}return i};function BhA(){return new TransformStream({transform(e,A){$wA(e,g=>{const i=g.length;let I;if(i<126)I=new Uint8Array(1),new DataView(I.buffer).setUint8(0,i);else if(i<65536){I=new Uint8Array(3);const B=new DataView(I.buffer);B.setUint8(0,126),B.setUint16(1,i)}else{I=new Uint8Array(9);const B=new DataView(I.buffer);B.setUint8(0,127),B.setBigUint64(1,BigInt(i))}e.data&&typeof e.data!="string"&&(I[0]|=128),A.enqueue(I),A.enqueue(g)})}})}let YS;function ec(e){return e.reduce((A,g)=>A+g.length,0)}function gc(e,A){if(e[0].length===A)return e.shift();const g=new Uint8Array(A);let i=0;for(let I=0;I<A;I++)g[I]=e[0][i++],i===e[0].length&&(e.shift(),i=0);return e.length&&i<e[0].length&&(e[0]=e[0].slice(i)),g}function thA(e,A){YS||(YS=new TextDecoder);const g=[];let i=0,I=-1,B=!1;return new TransformStream({transform(t,C){for(g.push(t);;){if(i===0){if(ec(g)<1)break;const o=gc(g,1);B=(o[0]&128)===128,I=o[0]&127,I<126?i=3:I===126?i=1:i=2}else if(i===1){if(ec(g)<2)break;const o=gc(g,2);I=new DataView(o.buffer,o.byteOffset,o.length).getUint16(0),i=3}else if(i===2){if(ec(g)<8)break;const o=gc(g,8),r=new DataView(o.buffer,o.byteOffset,o.length),a=r.getUint32(0);if(a>Math.pow(2,21)-1){C.enqueue(cS);break}I=a*Math.pow(2,32)+r.getUint32(4),i=3}else{if(ec(g)<I)break;const o=gc(g,I);C.enqueue(uS(B?o:YS.decode(o),A)),i=0}if(I===0||I>e){C.enqueue(cS);break}}}})}const kq=4;function LI(e){if(e)return EhA(e)}function EhA(e){for(var A in LI.prototype)e[A]=LI.prototype[A];return e}LI.prototype.on=LI.prototype.addEventListener=function(e,A){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(A),this},LI.prototype.once=function(e,A){function g(){this.off(e,g),A.apply(this,arguments)}return g.fn=A,this.on(e,g),this},LI.prototype.off=LI.prototype.removeListener=LI.prototype.removeAllListeners=LI.prototype.removeEventListener=function(e,A){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var g=this._callbacks["$"+e];if(!g)return this;if(arguments.length==1)return delete this._callbacks["$"+e],this;for(var i,I=0;I<g.length;I++)if(i=g[I],i===A||i.fn===A){g.splice(I,1);break}return g.length===0&&delete this._callbacks["$"+e],this},LI.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var A=new Array(arguments.length-1),g=this._callbacks["$"+e],i=1;i<arguments.length;i++)A[i-1]=arguments[i];if(g){g=g.slice(0);for(var i=0,I=g.length;i<I;++i)g[i].apply(this,A)}return this},LI.prototype.emitReserved=LI.prototype.emit,LI.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},LI.prototype.hasListeners=function(e){return!!this.listeners(e).length};const ic=typeof Promise=="function"&&typeof Promise.resolve=="function"?A=>Promise.resolve().then(A):(A,g)=>g(A,0),iE=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),ChA="arraybuffer";function USA(){}function Nq(e,...A){return A.reduce((g,i)=>(e.hasOwnProperty(i)&&(g[i]=e[i]),g),{})}const ohA=iE.setTimeout,QhA=iE.clearTimeout;function Ic(e,A){A.useNativeTimers?(e.setTimeoutFn=ohA.bind(iE),e.clearTimeoutFn=QhA.bind(iE)):(e.setTimeoutFn=iE.setTimeout.bind(iE),e.clearTimeoutFn=iE.clearTimeout.bind(iE))}const rhA=1.33;function ahA(e){return typeof e=="string"?nhA(e):Math.ceil((e.byteLength||e.size)*rhA)}function nhA(e){let A=0,g=0;for(let i=0,I=e.length;i<I;i++)A=e.charCodeAt(i),A<128?g+=1:A<2048?g+=2:A<55296||A>=57344?g+=3:(i++,g+=4);return g}function Oq(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function shA(e){let A="";for(let g in e)e.hasOwnProperty(g)&&(A.length&&(A+="&"),A+=encodeURIComponent(g)+"="+encodeURIComponent(e[g]));return A}function whA(e){let A={},g=e.split("&");for(let i=0,I=g.length;i<I;i++){let B=g[i].split("=");A[decodeURIComponent(B[0])]=decodeURIComponent(B[1])}return A}class hhA extends Error{constructor(A,g,i){super(A),this.description=g,this.context=i,this.type="TransportError"}}class GS extends LI{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,g,i){return super.emitReserved("error",new hhA(A,g,i)),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 g=uS(A,this.socket.binaryType);this.onPacket(g)}onPacket(A){super.emitReserved("packet",A)}onClose(A){this.readyState="closed",super.emitReserved("close",A)}pause(A){}createUri(A,g={}){return A+"://"+this._hostname()+this._port()+this.opts.path+this._query(g)}_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 g=shA(A);return g.length?"?"+g:""}}class MhA extends GS{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(A){this.readyState="pausing";const g=()=>{this.readyState="paused",A()};if(this._polling||!this.writable){let i=0;this._polling&&(i++,this.once("pollComplete",function(){--i||g()})),this.writable||(i++,this.once("drain",function(){--i||g()}))}else g()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(A){const g=i=>{if(this.readyState==="opening"&&i.type==="open"&&this.onOpen(),i.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(i)};IhA(A,this.socket.binaryType).forEach(g),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,ihA(A,g=>{this.doWrite(g,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const A=this.opts.secure?"https":"http",g=this.query||{};return this.opts.timestampRequests!==!1&&(g[this.opts.timestampParam]=Oq()),!this.supportsBinary&&!g.sid&&(g.b64=1),this.createUri(A,g)}}let Hq=!1;try{Hq=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const chA=Hq;function DhA(){}class lhA extends MhA{constructor(A){if(super(A),typeof location<"u"){const g=location.protocol==="https:";let i=location.port;i||(i=g?"443":"80"),this.xd=typeof location<"u"&&A.hostname!==location.hostname||i!==A.port}}doWrite(A,g){const i=this.request({method:"POST",data:A});i.on("success",g),i.on("error",(I,B)=>{this.onError("xhr post error",I,B)})}doPoll(){const A=this.request();A.on("data",this.onData.bind(this)),A.on("error",(g,i)=>{this.onError("xhr poll error",g,i)}),this.pollXhr=A}}let Xa=class dl extends LI{constructor(A,g,i){super(),this.createRequest=A,Ic(this,i),this._opts=i,this._method=i.method||"GET",this._uri=g,this._data=i.data!==void 0?i.data:null,this._create()}_create(){var A;const g=Nq(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");g.xdomain=!!this._opts.xd;const i=this._xhr=this.createRequest(g);try{i.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){i.setDisableHeaderCheck&&i.setDisableHeaderCheck(!0);for(let I in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(I)&&i.setRequestHeader(I,this._opts.extraHeaders[I])}}catch{}if(this._method==="POST")try{i.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{i.setRequestHeader("Accept","*/*")}catch{}(A=this._opts.cookieJar)===null||A===void 0||A.addCookies(i),"withCredentials"in i&&(i.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(i.timeout=this._opts.requestTimeout),i.onreadystatechange=()=>{var I;i.readyState===3&&((I=this._opts.cookieJar)===null||I===void 0||I.parseCookies(i.getResponseHeader("set-cookie"))),i.readyState===4&&(i.status===200||i.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof i.status=="number"?i.status:0)},0))},i.send(this._data)}catch(I){this.setTimeoutFn(()=>{this._onError(I)},0);return}typeof document<"u"&&(this._index=dl.requestsCount++,dl.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=DhA,A)try{this._xhr.abort()}catch{}typeof document<"u"&&delete dl.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(Xa.requestsCount=0,Xa.requests={},typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",yq);else if(typeof addEventListener=="function"){const e="onpagehide"in iE?"pagehide":"unload";addEventListener(e,yq,!1)}}function yq(){for(let e in Xa.requests)Xa.requests.hasOwnProperty(e)&&Xa.requests[e].abort()}const uhA=function(){const e=xq({xdomain:!1});return e&&e.responseType!==null}();class YhA extends lhA{constructor(A){super(A);const g=A&&A.forceBase64;this.supportsBinary=uhA&&!g}request(A={}){return Object.assign(A,{xd:this.xd},this.opts),new Xa(xq,this.uri(),A)}}function xq(e){const A=e.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!A||chA))return new XMLHttpRequest}catch{}if(!A)try{return new iE[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}const Jq=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class GhA extends GS{get name(){return"websocket"}doOpen(){const A=this.uri(),g=this.opts.protocols,i=Jq?{}:Nq(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(i.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(A,g,i)}catch(I){return this.emitReserved("error",I)}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 g=0;g<A.length;g++){const i=A[g],I=g===A.length-1;DS(i,this.supportsBinary,B=>{try{this.doWrite(i,B)}catch{}I&&ic(()=>{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",g=this.query||{};return this.opts.timestampRequests&&(g[this.opts.timestampParam]=Oq()),this.supportsBinary||(g.b64=1),this.createUri(A,g)}}const RS=iE.WebSocket||iE.MozWebSocket;class RhA extends GhA{createSocket(A,g,i){return Jq?new RS(A,g,i):g?new RS(A,g):new RS(A)}doWrite(A,g){this.ws.send(g)}}class FhA extends GS{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 g=thA(Number.MAX_SAFE_INTEGER,this.socket.binaryType),i=A.readable.pipeThrough(g).getReader(),I=BhA();I.readable.pipeTo(A.writable),this._writer=I.writable.getWriter();const B=()=>{i.read().then(({done:C,value:o})=>{C||(this.onPacket(o),B())}).catch(C=>{})};B();const t={type:"open"};this.query.sid&&(t.data=`{"sid":"${this.query.sid}"}`),this._writer.write(t).then(()=>this.onOpen())})})}write(A){this.writable=!1;for(let g=0;g<A.length;g++){const i=A[g],I=g===A.length-1;this._writer.write(i).then(()=>{I&&ic(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var A;(A=this._transport)===null||A===void 0||A.close()}}const dhA={websocket:RhA,webtransport:FhA,polling:YhA},UhA=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,mhA=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function FS(e){if(e.length>8e3)throw"URI too long";const A=e,g=e.indexOf("["),i=e.indexOf("]");g!=-1&&i!=-1&&(e=e.substring(0,g)+e.substring(g,i).replace(/:/g,";")+e.substring(i,e.length));let I=UhA.exec(e||""),B={},t=14;for(;t--;)B[mhA[t]]=I[t]||"";return g!=-1&&i!=-1&&(B.source=A,B.host=B.host.substring(1,B.host.length-1).replace(/;/g,":"),B.authority=B.authority.replace("[","").replace("]","").replace(/;/g,":"),B.ipv6uri=!0),B.pathNames=ShA(B,B.path),B.queryKey=phA(B,B.query),B}function ShA(e,A){const g=/\/{2,9}/g,i=A.replace(g,"/").split("/");return(A.slice(0,1)=="/"||A.length===0)&&i.splice(0,1),A.slice(-1)=="/"&&i.splice(i.length-1,1),i}function phA(e,A){const g={};return A.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(i,I,B){I&&(g[I]=B)}),g}const dS=typeof addEventListener=="function"&&typeof removeEventListener=="function",Bc=[];dS&&addEventListener("offline",()=>{Bc.forEach(e=>e())},!1);class sQ extends LI{constructor(A,g){if(super(),this.binaryType=ChA,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,A&&typeof A=="object"&&(g=A,A=null),A){const i=FS(A);g.hostname=i.host,g.secure=i.protocol==="https"||i.protocol==="wss",g.port=i.port,i.query&&(g.query=i.query)}else g.host&&(g.hostname=FS(g.host).host);Ic(this,g),this.secure=g.secure!=null?g.secure:typeof location<"u"&&location.protocol==="https:",g.hostname&&!g.port&&(g.port=this.secure?"443":"80"),this.hostname=g.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=g.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},g.transports.forEach(i=>{const I=i.prototype.name;this.transports.push(I),this._transportsByName[I]=i}),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},g),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=whA(this.opts.query)),dS&&(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 g=Object.assign({},this.opts.query);g.EIO=kq,g.transport=A,this.id&&(g.sid=this.id);const i=Object.assign({},this.opts,{query:g,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[A]);return new this._transportsByName[A](i)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}const A=this.opts.rememberUpgrade&&sQ.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";const g=this.createTransport(A);g.open(),this.setTransport(g)}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",g=>this._onClose("transport close",g))}onOpen(){this.readyState="open",sQ.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 g=new Error("server error");g.code=A.data,this._onError(g);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 g=1;for(let i=0;i<this.writeBuffer.length;i++){const I=this.writeBuffer[i].data;if(I&&(g+=ahA(I)),i>0&&g>this._maxPayload)return this.writeBuffer.slice(0,i);g+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const A=Date.now()>this._pingTimeoutTime;return A&&(this._pingTimeoutTime=0,ic(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),A}write(A,g,i){return this._sendPacket("message",A,g,i),this}send(A,g,i){return this._sendPacket("message",A,g,i),this}_sendPacket(A,g,i,I){if(typeof g=="function"&&(I=g,g=void 0),typeof i=="function"&&(I=i,i=null),this.readyState==="closing"||this.readyState==="closed")return;i=i||{},i.compress=i.compress!==!1;const B={type:A,data:g,options:i};this.emitReserved("packetCreate",B),this.writeBuffer.push(B),I&&this.once("flush",I),this.flush()}close(){const A=()=>{this._onClose("forced close"),this.transport.close()},g=()=>{this.off("upgrade",g),this.off("upgradeError",g),A()},i=()=>{this.once("upgrade",g),this.once("upgradeError",g)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?i():A()}):this.upgrading?i():A()),this}_onError(A){if(sQ.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,g){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(),dS&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const i=Bc.indexOf(this._offlineEventListener);i!==-1&&Bc.splice(i,1)}this.readyState="closed",this.id=null,this.emitReserved("close",A,g),this.writeBuffer=[],this._prevBufferLen=0}}}sQ.protocol=kq;class KhA extends sQ{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 g=this.createTransport(A),i=!1;sQ.priorWebsocketSuccess=!1;const I=()=>{i||(g.send([{type:"ping",data:"probe"}]),g.once("packet",s=>{if(!i)if(s.type==="pong"&&s.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",g),!g)return;sQ.priorWebsocketSuccess=g.name==="websocket",this.transport.pause(()=>{i||this.readyState!=="closed"&&(a(),this.setTransport(g),g.send([{type:"upgrade"}]),this.emitReserved("upgrade",g),g=null,this.upgrading=!1,this.flush())})}else{const M=new Error("probe error");M.transport=g.name,this.emitReserved("upgradeError",M)}}))};function B(){i||(i=!0,a(),g.close(),g=null)}const t=s=>{const M=new Error("probe error: "+s);M.transport=g.name,B(),this.emitReserved("upgradeError",M)};function C(){t("transport closed")}function o(){t("socket closed")}function r(s){g&&s.name!==g.name&&B()}const a=()=>{g.removeListener("open",I),g.removeListener("error",t),g.removeListener("close",C),this.off("close",o),this.off("upgrading",r)};g.once("open",I),g.once("error",t),g.once("close",C),this.once("close",o),this.once("upgrading",r),this._upgrades.indexOf("webtransport")!==-1&&A!=="webtransport"?this.setTimeoutFn(()=>{i||g.open()},200):g.open()}onHandshake(A){this._upgrades=this._filterUpgrades(A.upgrades),super.onHandshake(A)}_filterUpgrades(A){const g=[];for(let i=0;i<A.length;i++)~this.transports.indexOf(A[i])&&g.push(A[i]);return g}}let khA=class extends KhA{constructor(A,g={}){const i=typeof A=="object"?A:g;(!i.transports||i.transports&&typeof i.transports[0]=="string")&&(i.transports=(i.transports||["polling","websocket","webtransport"]).map(I=>dhA[I]).filter(I=>!!I)),super(A,i)}};function NhA(e,A="",g){let i=e;g=g||typeof location<"u"&&location,e==null&&(e=g.protocol+"//"+g.host),typeof e=="string"&&(e.charAt(0)==="/"&&(e.charAt(1)==="/"?e=g.protocol+e:e=g.host+e),/^(https?|wss?):\/\//.test(e)||(typeof g<"u"?e=g.protocol+"//"+e:e="https://"+e),i=FS(e)),i.port||(/^(http|ws)$/.test(i.protocol)?i.port="80":/^(http|ws)s$/.test(i.protocol)&&(i.port="443")),i.path=i.path||"/";const B=i.host.indexOf(":")!==-1?"["+i.host+"]":i.host;return i.id=i.protocol+"://"+B+":"+i.port+A,i.href=i.protocol+"://"+B+(g&&g.port===i.port?"":":"+i.port),i}const OhA=typeof ArrayBuffer=="function",HhA=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,jq=Object.prototype.toString,yhA=typeof Blob=="function"||typeof Blob<"u"&&jq.call(Blob)==="[object BlobConstructor]",xhA=typeof File=="function"||typeof File<"u"&&jq.call(File)==="[object FileConstructor]";function US(e){return OhA&&(e instanceof ArrayBuffer||HhA(e))||yhA&&e instanceof Blob||xhA&&e instanceof File}function tc(e,A){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let g=0,i=e.length;g<i;g++)if(tc(e[g]))return!0;return!1}if(US(e))return!0;if(e.toJSON&&typeof e.toJSON=="function"&&arguments.length===1)return tc(e.toJSON(),!0);for(const g in e)if(Object.prototype.hasOwnProperty.call(e,g)&&tc(e[g]))return!0;return!1}function JhA(e){const A=[],g=e.data,i=e;return i.data=mS(g,A),i.attachments=A.length,{packet:i,buffers:A}}function mS(e,A){if(!e)return e;if(US(e)){const g={_placeholder:!0,num:A.length};return A.push(e),g}else if(Array.isArray(e)){const g=new Array(e.length);for(let i=0;i<e.length;i++)g[i]=mS(e[i],A);return g}else if(typeof e=="object"&&!(e instanceof Date)){const g={};for(const i in e)Object.prototype.hasOwnProperty.call(e,i)&&(g[i]=mS(e[i],A));return g}return e}function jhA(e,A){return e.data=SS(e.data,A),delete e.attachments,e}function SS(e,A){if(!e)return e;if(e&&e._placeholder===!0){if(typeof e.num=="number"&&e.num>=0&&e.num<A.length)return A[e.num];throw new Error("illegal attachments")}else if(Array.isArray(e))for(let g=0;g<e.length;g++)e[g]=SS(e[g],A);else if(typeof e=="object")for(const g in e)Object.prototype.hasOwnProperty.call(e,g)&&(e[g]=SS(e[g],A));return e}const LhA=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],ThA=5;var qg;(function(e){e[e.CONNECT=0]="CONNECT",e[e.DISCONNECT=1]="DISCONNECT",e[e.EVENT=2]="EVENT",e[e.ACK=3]="ACK",e[e.CONNECT_ERROR=4]="CONNECT_ERROR",e[e.BINARY_EVENT=5]="BINARY_EVENT",e[e.BINARY_ACK=6]="BINARY_ACK"})(qg||(qg={}));class VhA{constructor(A){this.replacer=A}encode(A){return(A.type===qg.EVENT||A.type===qg.ACK)&&tc(A)?this.encodeAsBinary({type:A.type===qg.EVENT?qg.BINARY_EVENT:qg.BINARY_ACK,nsp:A.nsp,data:A.data,id:A.id}):[this.encodeAsString(A)]}encodeAsString(A){let g=""+A.type;return(A.type===qg.BINARY_EVENT||A.type===qg.BINARY_ACK)&&(g+=A.attachments+"-"),A.nsp&&A.nsp!=="/"&&(g+=A.nsp+","),A.id!=null&&(g+=A.id),A.data!=null&&(g+=JSON.stringify(A.data,this.replacer)),g}encodeAsBinary(A){const g=JhA(A),i=this.encodeAsString(g.packet),I=g.buffers;return I.unshift(i),I}}function Lq(e){return Object.prototype.toString.call(e)==="[object Object]"}class pS extends LI{constructor(A){super(),this.reviver=A}add(A){let g;if(typeof A=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");g=this.decodeString(A);const i=g.type===qg.BINARY_EVENT;i||g.type===qg.BINARY_ACK?(g.type=i?qg.EVENT:qg.ACK,this.reconstructor=new fhA(g),g.attachments===0&&super.emitReserved("decoded",g)):super.emitReserved("decoded",g)}else if(US(A)||A.base64)if(this.reconstructor)g=this.reconstructor.takeBinaryData(A),g&&(this.reconstructor=null,super.emitReserved("decoded",g));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+A)}decodeString(A){let g=0;const i={type:Number(A.charAt(0))};if(qg[i.type]===void 0)throw new Error("unknown packet type "+i.type);if(i.type===qg.BINARY_EVENT||i.type===qg.BINARY_ACK){const B=g+1;for(;A.charAt(++g)!=="-"&&g!=A.length;);const t=A.substring(B,g);if(t!=Number(t)||A.charAt(g)!=="-")throw new Error("Illegal attachments");i.attachments=Number(t)}if(A.charAt(g+1)==="/"){const B=g+1;for(;++g&&!(A.charAt(g)===","||g===A.length););i.nsp=A.substring(B,g)}else i.nsp="/";const I=A.charAt(g+1);if(I!==""&&Number(I)==I){const B=g+1;for(;++g;){const t=A.charAt(g);if(t==null||Number(t)!=t){--g;break}if(g===A.length)break}i.id=Number(A.substring(B,g+1))}if(A.charAt(++g)){const B=this.tryParse(A.substr(g));if(pS.isPayloadValid(i.type,B))i.data=B;else throw new Error("invalid payload")}return i}tryParse(A){try{return JSON.parse(A,this.reviver)}catch{return!1}}static isPayloadValid(A,g){switch(A){case qg.CONNECT:return Lq(g);case qg.DISCONNECT:return g===void 0;case qg.CONNECT_ERROR:return typeof g=="string"||Lq(g);case qg.EVENT:case qg.BINARY_EVENT:return Array.isArray(g)&&(typeof g[0]=="number"||typeof g[0]=="string"&&LhA.indexOf(g[0])===-1);case qg.ACK:case qg.BINARY_ACK:return Array.isArray(g)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class fhA{constructor(A){this.packet=A,this.buffers=[],this.reconPack=A}takeBinaryData(A){if(this.buffers.push(A),this.buffers.length===this.reconPack.attachments){const g=jhA(this.reconPack,this.buffers);return this.finishedReconstruction(),g}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const zhA=Object.freeze(Object.defineProperty({__proto__:null,Decoder:pS,Encoder:VhA,get PacketType(){return qg},protocol:ThA},Symbol.toStringTag,{value:"Module"}));function LE(e,A,g){return e.on(A,g),function(){e.off(A,g)}}const bhA=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Tq extends LI{constructor(A,g,i){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=g,i&&i.auth&&(this.auth=i.auth),this._opts=Object.assign({},i),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const A=this.io;this.subs=[LE(A,"open",this.onopen.bind(this)),LE(A,"packet",this.onpacket.bind(this)),LE(A,"error",this.onerror.bind(this)),LE(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,...g){var i,I,B;if(bhA.hasOwnProperty(A))throw new Error('"'+A.toString()+'" is a reserved event name');if(g.unshift(A),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(g),this;const t={type:qg.EVENT,data:g};if(t.options={},t.options.compress=this.flags.compress!==!1,typeof g[g.length-1]=="function"){const a=this.ids++,s=g.pop();this._registerAckCallback(a,s),t.id=a}const C=(I=(i=this.io.engine)===null||i===void 0?void 0:i.transport)===null||I===void 0?void 0:I.writable,o=this.connected&&!(!((B=this.io.engine)===null||B===void 0)&&B._hasPingExpired());return this.flags.volatile&&!C||(o?(this.notifyOutgoingListeners(t),this.packet(t)):this.sendBuffer.push(t)),this.flags={},this}_registerAckCallback(A,g){var i;const I=(i=this.flags.timeout)!==null&&i!==void 0?i:this._opts.ackTimeout;if(I===void 0){this.acks[A]=g;return}const B=this.io.setTimeoutFn(()=>{delete this.acks[A];for(let C=0;C<this.sendBuffer.length;C++)this.sendBuffer[C].id===A&&this.sendBuffer.splice(C,1);g.call(this,new Error("operation has timed out"))},I),t=(...C)=>{this.io.clearTimeoutFn(B),g.apply(this,C)};t.withError=!0,this.acks[A]=t}emitWithAck(A,...g){return new Promise((i,I)=>{const B=(t,C)=>t?I(t):i(C);B.withError=!0,g.push(B),this.emit(A,...g)})}_addToQueue(A){let g;typeof A[A.length-1]=="function"&&(g=A.pop());const i={id:this._queueSeq++,tryCount:0,pending:!1,args:A,flags:Object.assign({fromQueue:!0},this.flags)};A.push((I,...B)=>i!==this._queue[0]?void 0:(I!==null?i.tryCount>this._opts.retries&&(this._queue.shift(),g&&g(I)):(this._queue.shift(),g&&g(null,...B)),i.pending=!1,this._drainQueue())),this._queue.push(i),this._drainQueue()}_drainQueue(A=!1){if(!this.connected||this._queue.length===0)return;const g=this._queue[0];g.pending&&!A||(g.pending=!0,g.tryCount++,this.flags=g.flags,this.emit.apply(this,g.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:qg.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,g){this.connected=!1,delete this.id,this.emitReserved("disconnect",A,g),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(A=>{if(!this.sendBuffer.some(i=>String(i.id)===A)){const i=this.acks[A];delete this.acks[A],i.withError&&i.call(this,new Error("socket has been disconnected"))}})}onpacket(A){if(A.nsp===this.nsp)switch(A.type){case qg.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 qg.EVENT:case qg.BINARY_EVENT:this.onevent(A);break;case qg.ACK:case qg.BINARY_ACK:this.onack(A);break;case qg.DISCONNECT:this.ondisconnect();break;case qg.CONNECT_ERROR:this.destroy();const i=new Error(A.data.message);i.data=A.data.data,this.emitReserved("connect_error",i);break}}onevent(A){const g=A.data||[];A.id!=null&&g.push(this.ack(A.id)),this.connected?this.emitEvent(g):this.receiveBuffer.push(Object.freeze(g))}emitEvent(A){if(this._anyListeners&&this._anyListeners.length){const g=this._anyListeners.slice();for(const i of g)i.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 g=this;let i=!1;return function(...I){i||(i=!0,g.packet({type:qg.ACK,id:A,data:I}))}}onack(A){const g=this.acks[A.id];typeof g=="function"&&(delete this.acks[A.id],g.withError&&A.data.unshift(null),g.apply(this,A.data))}onconnect(A,g){this.id=A,this.recovered=g&&this._pid===g,this._pid=g,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:qg.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 g=this._anyListeners;for(let i=0;i<g.length;i++)if(A===g[i])return g.splice(i,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 g=this._anyOutgoingListeners;for(let i=0;i<g.length;i++)if(A===g[i])return g.splice(i,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(A){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const g=this._anyOutgoingListeners.slice();for(const i of g)i.apply(this,A.data)}}}function _a(e){e=e||{},this.ms=e.min||100,this.max=e.max||1e4,this.factor=e.factor||2,this.jitter=e.jitter>0&&e.jitter<=1?e.jitter:0,this.attempts=0}_a.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var A=Math.random(),g=Math.floor(A*this.jitter*e);e=(Math.floor(A*10)&1)==0?e-g:e+g}return Math.min(e,this.max)|0},_a.prototype.reset=function(){this.attempts=0},_a.prototype.setMin=function(e){this.ms=e},_a.prototype.setMax=function(e){this.max=e},_a.prototype.setJitter=function(e){this.jitter=e};class KS extends LI{constructor(A,g){var i;super(),this.nsps={},this.subs=[],A&&typeof A=="object"&&(g=A,A=void 0),g=g||{},g.path=g.path||"/socket.io",this.opts=g,Ic(this,g),this.reconnection(g.reconnection!==!1),this.reconnectionAttempts(g.reconnectionAttempts||1/0),this.reconnectionDelay(g.reconnectionDelay||1e3),this.reconnectionDelayMax(g.reconnectionDelayMax||5e3),this.randomizationFactor((i=g.randomizationFactor)!==null&&i!==void 0?i:.5),this.backoff=new _a({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(g.timeout==null?2e4:g.timeout),this._readyState="closed",this.uri=A;const I=g.parser||zhA;this.encoder=new I.Encoder,this.decoder=new I.Decoder,this._autoConnect=g.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 g;return A===void 0?this._reconnectionDelay:(this._reconnectionDelay=A,(g=this.backoff)===null||g===void 0||g.setMin(A),this)}randomizationFactor(A){var g;return A===void 0?this._randomizationFactor:(this._randomizationFactor=A,(g=this.backoff)===null||g===void 0||g.setJitter(A),this)}reconnectionDelayMax(A){var g;return A===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=A,(g=this.backoff)===null||g===void 0||g.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 khA(this.uri,this.opts);const g=this.engine,i=this;this._readyState="opening",this.skipReconnect=!1;const I=LE(g,"open",function(){i.onopen(),A&&A()}),B=C=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",C),A?A(C):this.maybeReconnectOnOpen()},t=LE(g,"error",B);if(this._timeout!==!1){const C=this._timeout,o=this.setTimeoutFn(()=>{I(),B(new Error("timeout")),g.close()},C);this.opts.autoUnref&&o.unref(),this.subs.push(()=>{this.clearTimeoutFn(o)})}return this.subs.push(I),this.subs.push(t),this}connect(A){return this.open(A)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const A=this.engine;this.subs.push(LE(A,"ping",this.onping.bind(this)),LE(A,"data",this.ondata.bind(this)),LE(A,"error",this.onerror.bind(this)),LE(A,"close",this.onclose.bind(this)),LE(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(A){try{this.decoder.add(A)}catch(g){this.onclose("parse error",g)}}ondecoded(A){ic(()=>{this.emitReserved("packet",A)},this.setTimeoutFn)}onerror(A){this.emitReserved("error",A)}socket(A,g){let i=this.nsps[A];return i?this._autoConnect&&!i.active&&i.connect():(i=new Tq(this,A,g),this.nsps[A]=i),i}_destroy(A){const g=Object.keys(this.nsps);for(const i of g)if(this.nsps[i].active)return;this._close()}_packet(A){const g=this.encoder.encode(A);for(let i=0;i<g.length;i++)this.engine.write(g[i],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,g){var i;this.cleanup(),(i=this.engine)===null||i===void 0||i.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",A,g),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 g=this.backoff.duration();this._reconnecting=!0;const i=this.setTimeoutFn(()=>{A.skipReconnect||(this.emitReserved("reconnect_attempt",A.backoff.attempts),!A.skipReconnect&&A.open(I=>{I?(A._reconnecting=!1,A.reconnect(),this.emitReserved("reconnect_error",I)):A.onreconnect()}))},g);this.opts.autoUnref&&i.unref(),this.subs.push(()=>{this.clearTimeoutFn(i)})}}onreconnect(){const A=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",A)}}const qs={};function Ec(e,A){typeof e=="object"&&(A=e,e=void 0),A=A||{};const g=NhA(e,A.path||"/socket.io"),i=g.source,I=g.id,B=g.path,t=qs[I]&&B in qs[I].nsps,C=A.forceNew||A["force new connection"]||A.multiplex===!1||t;let o;return C?o=new KS(i,A):(qs[I]||(qs[I]=new KS(i,A)),o=qs[I]),g.query&&!A.query&&(A.query=g.queryKey),o.socket(g.path,A)}Object.assign(Ec,{Manager:KS,Socket:Tq,io:Ec,connect:Ec});const Zs="https://migration-tybot.tybot.ma/api/v1",qhA="https://migration-tybot.tybot.ma/api/v1/chatbots-config",Vq="https://migration-meta.tybotflow.com/",fq=Vq+"webhook/v",Cc=Ec(Vq,{transports:["websocket","polling"],reconnection:!0,reconnectionAttempts:3,autoConnect:!0,reconnectionDelay:2e3}),zq=new wo,kS=e=>{if(!e||!e.message)return"👋 Hey there! how can I help you?";const A=e.message;if(typeof A=="string")return A;if(Array.isArray(A)){const g=window.location.href,i=window.location.origin,I=window.location.pathname,B=i+I;for(const C of A){if(!C.urls||C.urls.length===0)continue;if(C.urls.some(r=>{if(!r||r.trim()==="")return!1;try{let a=r.trim();!a.startsWith("http://")&&!a.startsWith("https://")&&(a="https://"+a);const s=new URL(a),M=s.origin,w=s.pathname,c=M+w;return B===c||g===a?!0:w==="/"||w===""?i===M:!!g.startsWith(a)}catch{return console.warn("Invalid URL in message:",r),!1}}))return C.text||"👋 Hey there! how can I help you?"}const t=A.find(C=>!C.urls||C.urls.length===0||C.urls.every(o=>!o||o.trim()===""));if(t)return t.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?"},bq=(e,A)=>{const g={className:"w-5 h-5",style:{color:A}};switch(e?.toLowerCase()){case"pdf":return y.jsx(ns,{...g});case"doc":case"docx":return y.jsx(ns,{...g});case"xls":case"xlsx":case"csv":return y.jsx(sgA,{...g});case"ppt":case"pptx":return y.jsx(YgA,{...g});case"zip":case"rar":case"7z":case"tar":case"gz":return y.jsx(CgA,{...g});case"txt":case"md":case"rtf":return y.jsx(Ey,{...g});default:return y.jsx(ns,{...g})}},ZhA=({config:e})=>{const A=ee.useRef(null),g=ee.useRef(null),i=ee.useRef(null),I=ee.useRef(null),B=ee.useRef(null),[t,C]=ee.useState(null),[o,r]=ee.useState(!0);ee.useEffect(()=>{(async()=>{r(!0),await Oi.get(`${qhA}/bot/${e.bot?.botId}`,{}).then(yA=>{C(yA.data)}).catch(yA=>{console.error("Error fetching bot config:",yA)}).finally(()=>{r(!1)})})()},[e.bot?.botId,e?.token]);const a=t?.mainColor||"#59168b",s=t?.secondaryColor||"#6366f1",M=t?.thirdColor||"#0f172b",w=t?.headerFirstColor||"#6e11b0",c=t?.headerSecondColor||"#372aac",l=t?.inputBackgroundColor||"#1f2937",G=t?.inputTextColor||"#fff",u=t?.roundness||24,F=t?.chatRoundness||16,d=(t?.minPanelWidth||434)>window.innerWidth?window.innerWidth:t?.minPanelWidth||434,p=(t?.maxPanelWidth||window.innerWidth)>window.innerWidth?window.innerWidth:t?.maxPanelWidth||window.innerWidth,O=t?.chatMaxWidth||88,S=t?.toggleBtnBorderTopLeftRadius||12,j=t?.toggleBtnBorderTopRightRadius||0,L=t?.toggleBtnBorderBottomLeftRadius||12,x=t?.toggleBtnBorderBottomRightRadius||0,z=t?.menuBackgroundColor||"#1f2937",H=t?.menuTextColor||"#e5e7eb",f=t?.menuHoverBackgroundColor||"#374151",q=t?.agentChatResponseColor||"#e5e7eb",b=t?.agentChatResponseBgColor||"#1f2937",AA=t?.agentIconBgColor||"#59168b",v=t?.agentIconColor||"#fff",IA=t?.userChatMessagesColor||"#fff",$=t?.userChatMessagesBgColor||"#7a1ebe",CA=t?.userIconBgColor||"#7a1ebe",K=t?.userIconColor||"#fff",X=t?.ButtonColor||"#fff",T=t?.ButtonsBgColor||"#59168b",k=t?.fontSize||13,_=t?.toggleBtnPosition||"bottom-right",EA=t?.autoOpenPanel??!0,oA=t?.tempToken||"",lA=(()=>{const J=t?.firstMessageKeyword;if(Array.isArray(J)){const yA=window.location.href,FA=J.find(Fe=>Fe.url&&Fe.url===yA);if(FA)return FA.message;const ZA=J.find(Fe=>!Fe.url||Fe.url==="");return ZA?ZA.message:J[0]?.message||"hi"}return J||"hi"})(),RA=J=>({ip:J.ip||"",flag:{img:J.flag||"",emoji:J.emoji_flag||"",emoji_unicode:J.emoji_unicode||""},is_eu:J.is_eu??!1,postal:J.postal||"",borders:"",latitude:J.latitude||0,platform:J?.platform||"",timezone:{id:J.time_zone?.name||"",utc:J.time_zone?.offset||"",abbr:J.time_zone?.abbr||"",is_dst:J.time_zone?.is_dst??!1,offset:J.time_zone?.offset||0,current_time:J.time_zone?.current_time||""},continent:J.continent_name||"",longitude:J.longitude||0,connection:{asn:J.asn?.asn||0,isp:J.asn?.name||"",org:J.asn?.name||"",domain:J.asn?.domain||""}}),[mA,WA]=ee.useState(d),ne=ee.useRef(!1),ie=ee.useRef(0),kA=ee.useRef(d),iA=J=>{ne.current=!0,ie.current=J.clientX,kA.current=mA,document.body.style.cursor="ew-resize"};ee.useEffect(()=>{const J=FA=>{if(!ne.current)return;const ZA=ie.current-FA.clientX;let Fe=kA.current+ZA;Fe=Math.max(d,Math.min(p,Fe)),WA(Fe)},yA=()=>{ne.current&&(ne.current=!1,document.body.style.cursor="")};return window.addEventListener("mousemove",J),window.addEventListener("mouseup",yA),()=>{window.removeEventListener("mousemove",J),window.removeEventListener("mouseup",yA)}},[mA,d,p]);const[zA,ce]=ee.useState(!1),[Ce,jA]=ee.useState(!1),[Ie,Ae]=ee.useState(!1),[Ye,oe]=ee.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,bA]=ee.useState(!1),[wA,GA]=ee.useState({x:0,y:0}),HA=ee.useRef(null),[VA,De]=ee.useState(""),[le,ke]=ee.useState(!1),[He,Ge]=ee.useState(!1),[Re,je]=ee.useState([]),[Ue,Ve]=ee.useState(!1),Ne=ee.useRef(0),[ve,lg]=ee.useState(!1),[$e,Ze]=ee.useState(!1),ug=ee.useRef(!1),[DB,Bg]=ee.useState("00:00"),Ii=ee.useRef(null),iI=ee.useRef(0),[Pe,ji]=ee.useState(null),[mg,$g]=ee.useState(!1),[Ei,Yg]=ee.useState(new Set),[dg,Zg]=ee.useState([]),{startRecording:et,stopRecording:FI,pauseRecording:zI,resumeRecording:ai,status:Ug,error:qi}=_tA.useReactMediaRecorder({video:!1,onStop(J,yA){if(ug.current){ug.current=!1,Bg("00:00"),iI.current=0;return}je(FA=>[...FA,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),file:yA,type:"audio",url:J,name:`recording-${new Date().toISOString()}.webm`,size:yA.size}]),Bg("00:00"),iI.current=0}}),mi=t?.icon||e?.bot.avatar_url||Zf,yg=t?.title||e?.bot.name||"Tybot webchat",[Bi,pe]=ee.useState(null),[MA,Qe]=ee.useState(()=>{const J=localStorage.getItem("phone_client");if(e.bot?.botId==="rockskin"&&J)return J;if(!t?.botNeedsAuth){let yA=localStorage.getItem("externalUser");if(!yA){const FA=new Uint8Array(16);window.crypto.getRandomValues(FA),yA=Array.from(FA).map(ZA=>ZA.toString(16).padStart(2,"0")).join("")}return localStorage.setItem("externalUser",yA),yA}});ee.useEffect(()=>{if(!Bi)return;const J=yA=>{if(yA.bot.conversationId!==parseInt(Bi)){ke(!1);return}const FA={id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:yA.bot.item,timestamp:new Date,seen:dI.current,nMessage:Array.isArray(yA.bot.item)?yA.bot.item.length:1};Zg(ZA=>ZA.some(KA=>KA.id===FA.id)?ZA:[...ZA,FA]),ke(!1)};return Cc.on("bot-message",J),()=>{Cc.off("bot-message",J)}},[Bi,e?.bot?.botId]),ee.useEffect(()=>{(async()=>{if(!(Bi||!e.bot?.botId||!MA))try{const FA=(await Oi.post(`${Zs}/conversations/start-conversation`,{bot_id:e.bot?.botId,externalUser:MA})).data.conversationId;pe(FA),localStorage.setItem("conversationId",FA),Cc.emit("join_room",parseInt(FA))}catch(yA){console.error("Error initializing conversation:",yA)}})()},[Bi,e.bot?.botId,MA]);const[me,Ai]=ee.useState(()=>t?.botNeedsAuth?!!localStorage.getItem("conversationId"):!0),[ei,ni]=ee.useState(""),[si,wi]=ee.useState(""),[Si,Ft]=ee.useState(""),[Pg,LB]=ee.useState(null),dI=ee.useRef(!1),IB=dg.reduce((J,yA)=>yA.seen?J:J+(yA.sender==="agent"?yA.nMessage||1:0),0),QE=()=>{Zg(J=>J.map(yA=>({...yA,seen:!0})))};ee.useEffect(()=>{let J;return!localStorage.getItem("webChatOpen")&&t&&EA&&(J=setTimeout(()=>{ce(!0),dI.current=!0,QE(),localStorage.setItem("webChatOpen","true")},3200)),()=>clearTimeout(J)},[t]),ee.useEffect(()=>{const J=t?.widgetLoadBehavior;if(!J||!(()=>{const ZA=J.message;if(typeof ZA=="string"){if(!J.urls||J.urls.length===0)return!0;const Fe=window.location.origin,KA=window.location.href;return J.urls.some(hg=>{if(!hg||hg.trim()==="")return!0;try{return Fe.includes(hg)||KA.includes(hg)||hg.includes(Fe)}catch{return console.warn("Invalid URL in widgetLoadBehavior:",hg),!1}})}if(Array.isArray(ZA)){const Fe=window.location.href,KA=window.location.origin,hg=window.location.pathname,Gg=KA+hg;for(const Zi of ZA)if(!Zi.urls||Zi.urls.length===0||Zi.urls.every(hi=>!hi||hi.trim()==="")||Zi.urls.some(hi=>{if(!hi||hi.trim()==="")return!1;try{let nI=hi.trim();!nI.startsWith("http://")&&!nI.startsWith("https://")&&(nI="https://"+nI);const tt=new URL(nI),ze=tt.origin,EB=tt.pathname,Sg=ze+EB;return Gg===Sg||Fe===nI?!0:EB==="/"||EB===""?KA===ze:!!Fe.startsWith(nI)}catch{return console.warn("Invalid URL in message:",hi),!1}}))return!0;return!1}return!0})())return;let FA;if(J.behavior==="after seconds")FA=setTimeout(()=>{Ae(!0)},J.value*1e3);else if(J.behavior==="after scroll"){const ZA=()=>{const Fe=window.pageYOffset||document.documentElement.scrollTop,KA=document.documentElement.scrollHeight-document.documentElement.clientHeight;Fe/KA*100>=J.value&&(Ae(!0),window.removeEventListener("scroll",ZA))};return window.addEventListener("scroll",ZA),()=>{window.removeEventListener("scroll",ZA)}}return()=>{FA&&clearTimeout(FA)}},[t?.widgetLoadBehavior]),ee.useEffect(()=>{zA&&Ae(!1)},[zA]),ee.useEffect(()=>{fetch("https://api.ipdata.co/?api-key=7930ffd0621dafcb6cd830a503d726bf514b74c1cae21ffff8131890").then(function(J){J.json().then(yA=>{LB({...yA,platform:zq.getOS().name+" "+zq.getOS().version})})}).catch(function(J){console.log(J)})},[]);const yC=ee.useCallback(async(J,yA=[],FA)=>{if(!e.bot.botId||!Bi){ke(!1),Zg(Fe=>[...Fe,{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(yA.length>0||FA&&typeof FA=="object"&&FA.attachment!==void 0){const Fe=FA&&typeof FA!="string"?FA.attachment.file:yA[0]?.file,KA=FA&&typeof FA!="string"?FA.attachment.type:yA[0]?.type||"file";let hg=FA;if(FA&&typeof FA=="object"&&FA.attachment!==void 0){const{attachment:Zi,...Kg}=FA;hg=Kg}const Gg=new FormData;Gg.append("type",KA),Gg.append("file",Fe),Gg.append("botId",e.bot.botId),Gg.append("external_id",MA||""),Gg.append("isintern",e.token?"true":"false"),Gg.append("host",window.location.origin),Gg.append("channel","web"),Gg.append("payload",hg?JSON.stringify(hg):""),await Oi.post(fq,Gg,{headers:{Authorization:`Bearer ${e?.token}`,"Content-Type":"multipart/form-data"}})}else{const Fe={type:"text",messageText:J,botId:e.bot.botId,external_id:MA||"",isintern:!!e.token,host:window.location.origin,channel:"web"};FA&&(Fe.payload=FA),await Oi.post(fq,Fe,{headers:{Authorization:`Bearer ${e?.token}`,"Content-Type":"application/json"}})}},[e.bot.botId,Bi,e.token,e.user?.id]),Vg=ee.useCallback(async()=>{if(e.bot.botId&&Bi){ke(!0);try{await yC(lA)}catch(J){console.error("Error sending first message:",J),ke(!1)}}},[e.bot.botId,lA,Bi,yC]);ee.useEffect(()=>{Bi&&me&&e?.bot&&dg.length===0&&t&&EA&&(Vg(),localStorage.getItem("webChatAuth")&&JSON.parse(localStorage.getItem("webChatAuth"))&&t?.botNeedsAuth&&Bi&&(ei||Si||si)&&(setTimeout(()=>{dt(Bi)},2e3),localStorage.setItem("webChatAuth","true")))},[me,e?.bot,Bi,t]),ee.useEffect(()=>(Ug==="recording"?Ii.current||(Ii.current=setInterval(()=>{iI.current+=1;const J=Math.floor(iI.current/60).toString().padStart(2,"0"),yA=(iI.current%60).toString().padStart(2,"0");Bg(`${J}:${yA}`)},1e3)):Ii.current&&(clearInterval(Ii.current),Ii.current=null),()=>{Ii.current&&(clearInterval(Ii.current),Ii.current=null)}),[Ug]),ee.useEffect(()=>{qi&&qi.toLowerCase().includes("permission_denied")&&(Ze(!1),Bg("00:00"),iI.current=0,Ii.current&&(clearInterval(Ii.current),Ii.current=null),alert("Microphone permission denied. Please allow access to record audio."))},[qi]),ee.useEffect(()=>{Ug!=="recording"&&Ug!=="paused"&&(Bg("00:00"),iI.current=0)},[Ug]);const rE=ee.useRef(null);ee.useEffect(()=>{if(rE&&rE.current){const J=rE.current;J.style.height="auto";const yA=120;J.scrollHeight>yA?(J.style.height=yA+"px",J.style.overflowY="auto"):(J.style.height=J.scrollHeight+"px",J.style.overflowY="hidden")}},[VA]),ee.useEffect(()=>{(zA||le)&&A.current&&(A.current.scrollTop=A.current.scrollHeight)},[dg,le,zA]);const mQ=J=>{const yA=J.type.toLowerCase();return yA.startsWith("image/")?"image":yA.startsWith("video/")?"video":yA.startsWith("audio/")?"audio":"document"},UI=ee.useCallback((J,yA)=>{const FA=[];Array.from(J).forEach(ZA=>{if(ZA.size>10*1024*1024){alert(`File ${ZA.name} is too large. Maximum size is 10MB.`);return}const Fe={id:Date.now().toString()+Math.random().toString(36).substring(2,9),file:ZA,type:mQ(ZA),url:URL.createObjectURL(ZA),name:ZA.name,size:ZA.size};FA.push(Fe)}),je(ZA=>[...ZA,...FA]),yA&&yA.current&&(yA.current.value="")},[]),aE=ee.useCallback(J=>{J.preventDefault(),Ne.current=0,Ve(!1);const yA=J.dataTransfer.files;yA.length>0&&UI(yA)},[UI]),BB=ee.useCallback(J=>{J.preventDefault(),Ne.current+=1,Ve(!0)},[]),PE=ee.useCallback(J=>{J.preventDefault()},[]),fg=ee.useCallback(J=>{J.preventDefault(),Ne.current-=1,Ne.current<=0&&Ve(!1)},[]),vE=ee.useCallback(J=>{je(yA=>{const FA=yA.find(ZA=>ZA.id===J);return FA&&URL.revokeObjectURL(FA.url),yA.filter(ZA=>ZA.id!==J)})},[]),SQ=J=>{if(J===0)return"0 Bytes";const yA=1024,FA=["Bytes","KB","MB","GB"],ZA=Math.floor(Math.log(J)/Math.log(yA));return Number.parseFloat((J/Math.pow(yA,ZA)).toFixed(2))+" "+FA[ZA]},Li=async(J=VA,yA)=>{if(J.trim()||Re.length!==0){const ZA={id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"user",content:J,attachments:[...Re],timestamp:new Date};if(Zg(Fe=>[...Fe,ZA]),De(""),je([]),ke(!0),e?.bot)try{if(!Bi){ke(!1),Zg(Fe=>[...Fe,{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:dI.current,nMessage:1}]);return}await yC(J,Re,yA)}catch{Zg(Fe=>[...Fe,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"Erreur du serveur",timestamp:new Date,seen:dI.current,nMessage:1}]),ke(!1)}else Zg(Fe=>[...Fe,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"Aucun bot sélectionné",timestamp:new Date,seen:dI.current,nMessage:1}]),ke(!1)}else return},gt=J=>{switch(lg(!1),J){case"image":g.current?.click();break;case"video":i.current?.click();break;case"audio":I.current?.click();break;case"document":B.current?.click();break}};ee.useEffect(()=>{const J=dg.slice().reverse().find(yA=>yA.sender==="agent");if(J){let yA=!1;Array.isArray(J.content)&&(yA=J.content.some(FA=>FA.type==="text"&&typeof FA.text=="object"&&FA.text.type==="EVFORM")),Ge(yA)}else Ge(!1)},[dg]);const[it,ft]=ee.useState(!1),tB=ee.useRef({x:0,y:0}),nE=J=>{J.preventDefault(),J.stopPropagation(),bA(!0),ft(!1),tB.current={x:J.clientX,y:J.clientY},GA({x:J.clientX-Ye.x,y:J.clientY-Ye.y}),document.body.style.cursor="grabbing",document.body.style.userSelect="none"},xC=J=>{J.preventDefault(),J.stopPropagation();const yA=J.touches[0];bA(!0),ft(!1),tB.current={x:yA.clientX,y:yA.clientY},GA({x:yA.clientX-Ye.x,y:yA.clientY-Ye.y})},zt=J=>{if(J.preventDefault(),J.stopPropagation(),it){ft(!1);return}ce(yA=>!yA),dI.current=!zA,zA||QE(),!EA&&dg.length===0&&Vg()};ee.useEffect(()=>{const J=Fe=>{if(!SA)return;const KA=Math.abs(Fe.clientX-tB.current.x),hg=Math.abs(Fe.clientY-tB.current.y);(KA>5||hg>5)&&ft(!0);const Gg=Fe.clientX-wA.x,Zi=Fe.clientY-wA.y,Kg=67,hi=window.innerWidth-document.body.clientWidth,nI=Math.max(0,Math.min(window.innerWidth-Kg-hi,Gg)),tt=Math.max(0,Math.min(window.innerHeight-Kg,Zi));oe({x:nI,y:tt})},yA=Fe=>{if(!SA)return;Fe.preventDefault();const KA=Fe.touches[0],hg=Math.abs(KA.clientX-tB.current.x),Gg=Math.abs(KA.clientY-tB.current.y);(hg>5||Gg>5)&&ft(!0);const Zi=KA.clientX-wA.x,Kg=KA.clientY-wA.y,hi=67,nI=window.innerWidth-document.body.clientWidth,tt=Math.max(0,Math.min(window.innerWidth-hi-nI,Zi)),ze=Math.max(0,Math.min(window.innerHeight-hi,Kg));oe({x:tt,y:ze})},FA=()=>{SA&&(bA(!1),document.body.style.cursor="",document.body.style.userSelect="")},ZA=()=>{SA&&bA(!1)};return SA&&(document.addEventListener("mousemove",J),document.addEventListener("touchmove",yA,{passive:!1}),document.addEventListener("mouseup",FA),document.addEventListener("touchend",ZA)),()=>{document.removeEventListener("mousemove",J),document.removeEventListener("touchmove",yA),document.removeEventListener("mouseup",FA),document.removeEventListener("touchend",ZA)}},[SA,wA,Ye]),ee.useEffect(()=>{const J=()=>{const FA=window.innerWidth-67,ZA=window.innerHeight-67;oe(Fe=>({x:Math.max(0,Math.min(FA,Fe.x)),y:Math.max(0,Math.min(ZA,Fe.y))}))};return window.addEventListener("resize",J),()=>window.removeEventListener("resize",J)},[]),ee.useEffect(()=>{const J=async()=>{try{await Oi.patch(`${Zs}/widget/endusers/${MA}`,{fiche_contact:{city:Pg.city,platform:Pg.platform,region:Pg.region,country:Pg.country_name,age:0,full_name:ei,gender:"",address:"",company:"","phone 2":"",facebook:"",whatsapp:"",job_title:"",avatar_url:""},user_info:RA(Pg)},{headers:{Authorization:`Bearer ${oA}`}}),localStorage.setItem("enduserUpdated","true")}catch(FA){console.error("Error updating end user info:",FA)}};let yA;return Pg&&Bi&&oA&&dg.length>0&&!localStorage.getItem("enduserUpdated")&&(yA=setTimeout(()=>{J()},5e3)),()=>clearTimeout(yA)},[Pg,t,dg,Bi]);const Uo=/^[\u0600-\u06FF\u0750-\u077F\s\d\p{P}]+$/u,qr=/[\u0600-\u06FF\u0750-\u077F]/,WI=J=>Uo.test(J),PI=J=>qr.test(J),mI=ee.useMemo(()=>({h1:({children:J})=>y.jsx("h1",{className:"sm:text-2xl text-xl font-bold my-2",dir:WI(J)?"rtl":"ltr",children:y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h2:({children:J})=>y.jsx("h2",{className:"sm:text-xl text-lg font-semibold my-2",dir:WI(J)?"rtl":"ltr",children:y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h3:({children:J})=>y.jsx("h3",{className:"sm:text-lg text-base font-semibold my-2",dir:WI(J)?"rtl":"ltr",children:y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h4:({children:J})=>y.jsx("h4",{className:"sm:text-base text-sm font-semibold my-2",dir:WI(J)?"rtl":"ltr",children:y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h5:({children:J})=>y.jsx("h5",{className:"sm:text-base text-sm font-semibold my-2",dir:WI(J)?"rtl":"ltr",children:y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h6:({children:J})=>y.jsx("h6",{className:"sm:text-base text-sm font-semibold my-2",dir:WI(J)?"rtl":"ltr",children:y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),p:({children:J})=>{let yA;return typeof J=="string"&&PI(J)||typeof J=="object"&&!Array.isArray(J)&&J?.props?.children&&WI(J?.props?.children)||typeof J=="object"&&Array.isArray(J)&&J.some(FA=>PI(FA))?yA="rtl":yA="ltr",y.jsx("div",{className:"leading-relaxed",dir:typeof J=="string"||!Array.isArray(J)?yA:"",children:Array.isArray(J)?J.map((FA,ZA)=>{const Fe=PI(FA)?"p":"span";return typeof FA=="string"&&!new RegExp("^(?:\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F|\\s)+$","u").test(FA)?y.jsx(Fe,{dir:PI(FA)?"rtl":"ltr",children:y.jsx(JI,{sequence:[FA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})},ZA):FA?.type!=="br"?FA:null}):y.jsx(y.Fragment,{children:J})})},ul:({children:J})=>y.jsx("ul",{className:"list-disc list-inside ml-4 my-2",style:{color:q},dir:PI(J)?"rtl":"ltr",children:J}),ol:({children:J})=>{let yA=!1;return J.filter(FA=>typeof FA!="string").every(FA=>PI(FA?.props?.children))?yA=!0:yA=!1,y.jsx("ol",{className:"list-decimal list-inside ml-4 my-2",style:{color:q},dir:yA?"rtl":"ltr",children:typeof J=="string"?y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):J})},li:({children:J})=>y.jsx("li",{className:"my-1",dir:WI(J)?"rtl":"ltr",style:{color:q},children:typeof J=="string"?y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):J}),a:({href:J,children:yA})=>y.jsx("a",{href:J,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:typeof yA=="string"?y.jsx(JI,{sequence:[yA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):yA}),blockquote:({children:J})=>y.jsx("blockquote",{className:"border-l-4 pl-4 italic my-2",style:{borderColor:T,color:q},children:typeof J=="string"?y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):J}),code({node:J,className:yA,children:FA,...ZA}){const Fe=/language-(\w+)/.exec(yA||"");return Fe?y.jsx(qf,{...ZA,PreTag:"div",children:String(FA).replace(/\n$/,""),language:Fe[1],style:yaA,customStyle:{scrollbarWidth:"thin"}}):y.jsx("code",{className:"px-1 rounded font-mono inline",style:{backgroundColor:l,color:q},...ZA,children:typeof FA=="string"?y.jsx(JI,{sequence:[FA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):FA})},table:({children:J})=>y.jsx("table",{className:"min-w-full my-2",style:{border:`1px solid ${q}`,color:b,backgroundColor:q},children:J}),thead:({children:J})=>y.jsx("thead",{children:J}),tbody:({children:J})=>y.jsx("tbody",{children:J}),tr:({children:J})=>y.jsx("tr",{style:{border:`1px solid ${b}`},children:J}),th:({children:J})=>y.jsx("th",{className:"px-3 py-2 font-bold text-left",children:J}),td:({children:J})=>y.jsx("td",{className:"px-3 py-2",children:typeof J=="string"?y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):J}),strong:({children:J})=>y.jsx("strong",{className:"font-bold",children:typeof J=="string"?y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):J}),em:({children:J})=>y.jsx("em",{className:"italic ",children:typeof J=="string"?y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):J}),hr:()=>y.jsx("hr",{className:"my-4",style:{borderColor:`1px solid ${q}`}})}),[G,q,T,l,F]);ee.useEffect(()=>{const J=yA=>{ve&&yA.target instanceof Element&&!yA.composedPath().some(FA=>FA?.id==="upload-button-toggle"||FA?.id==="document-button"||FA?.id==="image-button"||FA?.id==="video-button"||FA?.id==="audio-button")&&lg(!1)};return document.addEventListener("mousedown",J),()=>{document.removeEventListener("mousedown",J)}},[ve]);const JC=J=>{switch(J.type){case"text":if(Array.isArray(J.text))switch(J.text[0].type){case"products":return y.jsx(_M,{products:J.text[0].items||[],onValidate:FA=>{Li("cart",FA)},agentChatResponseColor:q,agentChatResponseBgColor:b,buttonsBgColor:T,buttonColor:X,chatRoundness:F,panelWidth:mA});case"easyspaceform":return y.jsx(vf,{onValidate:FA=>{Li("easyspace-form-data",FA)},agentChatResponseColor:q,agentChatResponseBgColor:b,buttonsBgColor:T,buttonColor:X,chatRoundness:F,panelWidth:mA,inputBackgroundColor:l});default:return y.jsx(Xo,{remarkPlugins:[_o],components:mI,children:J.text?.replace(/\n/g,`
600
+ ***************************************************************************** */function uq(e,A){const[g,i]=ee.useState(null),I=ee.useMemo(()=>Object.entries(A).flat(),[A]);return ee.useEffect(()=>{if(!e?.current)return;const B=MS.create(Object.assign(Object.assign({},A),{container:e.current}));return i(B),()=>{B.destroy()}},[e,...I]),g}const Yq=/^on([A-Z])/,WwA=e=>Yq.test(e);function PwA(e,A){const g=ee.useMemo(()=>Object.entries(A).flat(),[A]);ee.useEffect(()=>{if(!e)return;const i=Object.entries(A);if(!i.length)return;const I=i.map(([B,t])=>{const C=B.replace(Yq,(o,r)=>r.toLowerCase());return e.on(C,(...o)=>t(e,...o))});return()=>{I.forEach(B=>B())}},[e,...g])}ee.memo(e=>{const A=ee.useRef(null),[g,i]=function(I){return ee.useMemo(()=>{const B=Object.assign({},I),t=Object.assign({},I);for(const C in B)WwA(C)?delete B[C]:delete t[C];return[B,t]},[I])}(e);return PwA(uq(A,g),i),y.jsx("div",{ref:A})});function vwA(e){var{container:A}=e;const g=uq(A,function(I,B){var t={};for(var C in I)Object.prototype.hasOwnProperty.call(I,C)&&B.indexOf(C)<0&&(t[C]=I[C]);if(I!=null&&typeof Object.getOwnPropertySymbols=="function"){var o=0;for(C=Object.getOwnPropertySymbols(I);o<C.length;o++)B.indexOf(C[o])<0&&Object.prototype.propertyIsEnumerable.call(I,C[o])&&(t[C[o]]=I[C[o]])}return t}(e,["container"])),i=function(I){const[B,t]=ee.useState(!1),[C,o]=ee.useState(!1),[r,a]=ee.useState(!1),[s,M]=ee.useState(0);return ee.useEffect(()=>{if(!I)return;const w=[I.on("load",()=>{t(!1),o(!1),M(0)}),I.on("ready",()=>{t(!0),o(!1),a(!1),M(0)}),I.on("finish",()=>{a(!0)}),I.on("play",()=>{o(!0)}),I.on("pause",()=>{o(!1)}),I.on("timeupdate",()=>{M(I.getCurrentTime())}),I.on("destroy",()=>{t(!1),o(!1)})];return()=>{w.forEach(c=>c())}},[I]),ee.useMemo(()=>({isReady:B,isPlaying:C,hasFinished:r,currentTime:s}),[C,r,s,B])}(g);return ee.useMemo(()=>Object.assign(Object.assign({},i),{wavesurfer:g}),[i,g])}const Gq=({src:e,mainColor:A,secondaryColor:g,controlsColor:i})=>{const I=ee.useRef(null),[B,t]=ee.useState(1),{wavesurfer:C,isPlaying:o}=vwA({container:I,waveColor:A,progressColor:g,barWidth:2,height:50,url:e}),r=()=>{C&&C.playPause()},a=()=>{const w=B===0?1:0;t(w),C?.setVolume(w)},s=()=>{C?.skip(-.096)},M=()=>{C?.skip(.096)};return y.jsxs("div",{className:"flex w-full flex-col items-center rounded-xl pt-1",children:[y.jsx("div",{ref:I,className:"w-full px-2"}),y.jsxs("div",{className:"flex w-full items-center justify-between",children:[y.jsx("div",{className:"relative flex items-center",children:y.jsx("button",{className:"transition-colors",style:{color:i},onClick:a,"aria-label":"Toggle volume",children:B===0?y.jsx(pgA,{size:20}):y.jsx(SgA,{size:20})})}),y.jsxs("div",{className:"-ml-9 flex flex-1 cursor-auto justify-center gap-2 rounded-full py-2 text-white",children:[y.jsx("button",{onClick:s,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:i},"aria-label":"Step back",children:y.jsx(dgA,{})}),y.jsx("button",{onClick:r,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:i},"aria-label":o?"Pause":"Play",children:o?y.jsx(lgA,{}):y.jsx(ugA,{})}),y.jsx("button",{onClick:M,className:"cursor-pointer hover:scale-110 transition-colors",style:{color:i},"aria-label":"Step forward",children:y.jsx(UgA,{})})]})]})]})},XwA=({attachment:e,formatFileSize:A,mainColor:g,secondaryColor:i,controlsColor:I})=>{const{type:B,url:t,name:C,size:o}=e;switch(B){case"image":return y.jsxs("div",{className:"relative group",children:[y.jsx("img",{src:t,alt:C,className:"max-w-xs max-h-48 size-full rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(t,"_blank")}),y.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 y.jsxs("div",{className:"max-w-xs",children:[y.jsx("video",{src:t,controls:!0,className:"w-full max-h-48 rounded-lg",preload:"metadata",onError:()=>{console.error("Video failed to load:",t)},children:"Your browser does not support the video tag."}),y.jsxs("div",{className:"flex text-xs text-white mt-1 w-full overflow-hidden whitespace-nowrap text-ellipsis",children:[y.jsx("span",{className:"block w-full overflow-hidden whitespace-nowrap text-ellipsis",title:C,children:C}),y.jsxs("span",{className:"ml-2",children:["• ",A(o)]})]})]});case"audio":return y.jsxs("div",{className:"bg-gray-800 bg-opacity-70 p-3 rounded-lg flex-1 w-full",children:[y.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[y.jsx(Ju,{className:"w-4 h-4",style:{color:g}}),y.jsx("span",{className:"text-sm font-medium truncate text-white",title:C,children:C})]}),y.jsx(Gq,{src:t,mainColor:g,secondaryColor:i,controlsColor:I}),y.jsx("p",{className:"text-xs text-gray-400 mt-1",children:A(o)})]});case"document":return y.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(t,"_blank"),children:y.jsxs("div",{className:"flex items-center gap-3",children:[y.jsx("div",{className:"w-10 h-10 bg-purple-600 rounded-lg flex items-center justify-center",children:y.jsx(ns,{className:"w-5 h-5 text-white"})}),y.jsxs("div",{className:"flex-1 min-w-0",children:[y.jsx("p",{className:"text-sm font-medium truncate text-white",children:C}),y.jsx("p",{className:"text-xs text-gray-400",children:A(o)})]})]})});default:return null}},_wA=ee.memo(({attachment:e,onRemove:A})=>y.jsxs("div",{className:"relative group w-24 h-24 rounded-xl overflow-hidden bg-gray-900 shadow-md border border-gray-700",children:[e.type==="image"&&e.url?y.jsx("img",{src:e.url,alt:e.name,className:"w-full h-full object-cover"}):y.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center text-gray-300 px-1 text-center text-xs",children:[e.type==="video"&&y.jsx(oy,{className:"w-5 h-5 mb-1 text-red-400"}),e.type==="audio"&&y.jsx(Ju,{className:"w-5 h-5 mb-1 text-green-400"}),e.type==="document"&&y.jsx(Ey,{className:"w-5 h-5 mb-1 text-yellow-400"}),y.jsx("span",{className:"w-full truncate",title:e.name,children:e.name})]}),y.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:y.jsx(wr,{className:"w-3 h-3"})})]})),pC=Object.create(null);pC.open="0",pC.close="1",pC.ping="2",pC.pong="3",pC.message="4",pC.upgrade="5",pC.noop="6";const Ac=Object.create(null);Object.keys(pC).forEach(e=>{Ac[pC[e]]=e});const cS={type:"error",data:"parser error"},Rq=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",Fq=typeof ArrayBuffer=="function",dq=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,DS=({type:e,data:A},g,i)=>Rq&&A instanceof Blob?g?i(A):Uq(A,i):Fq&&(A instanceof ArrayBuffer||dq(A))?g?i(A):Uq(new Blob([A]),i):i(pC[e]+(A||"")),Uq=(e,A)=>{const g=new FileReader;return g.onload=function(){const i=g.result.split(",")[1];A("b"+(i||""))},g.readAsDataURL(e)};function mq(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let lS;function $wA(e,A){if(Rq&&e.data instanceof Blob)return e.data.arrayBuffer().then(mq).then(A);if(Fq&&(e.data instanceof ArrayBuffer||dq(e.data)))return A(mq(e.data));DS(e,!1,g=>{lS||(lS=new TextEncoder),A(lS.encode(g))})}const Sq="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bs=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let e=0;e<Sq.length;e++)bs[Sq.charCodeAt(e)]=e;const AhA=e=>{let A=e.length*.75,g=e.length,i,I=0,B,t,C,o;e[e.length-1]==="="&&(A--,e[e.length-2]==="="&&A--);const r=new ArrayBuffer(A),a=new Uint8Array(r);for(i=0;i<g;i+=4)B=bs[e.charCodeAt(i)],t=bs[e.charCodeAt(i+1)],C=bs[e.charCodeAt(i+2)],o=bs[e.charCodeAt(i+3)],a[I++]=B<<2|t>>4,a[I++]=(t&15)<<4|C>>2,a[I++]=(C&3)<<6|o&63;return r},ehA=typeof ArrayBuffer=="function",uS=(e,A)=>{if(typeof e!="string")return{type:"message",data:pq(e,A)};const g=e.charAt(0);return g==="b"?{type:"message",data:ghA(e.substring(1),A)}:Ac[g]?e.length>1?{type:Ac[g],data:e.substring(1)}:{type:Ac[g]}:cS},ghA=(e,A)=>{if(ehA){const g=AhA(e);return pq(g,A)}else return{base64:!0,data:e}},pq=(e,A)=>{switch(A){case"blob":return e instanceof Blob?e:new Blob([e]);case"arraybuffer":default:return e instanceof ArrayBuffer?e:e.buffer}},Kq="",ihA=(e,A)=>{const g=e.length,i=new Array(g);let I=0;e.forEach((B,t)=>{DS(B,!1,C=>{i[t]=C,++I===g&&A(i.join(Kq))})})},IhA=(e,A)=>{const g=e.split(Kq),i=[];for(let I=0;I<g.length;I++){const B=uS(g[I],A);if(i.push(B),B.type==="error")break}return i};function BhA(){return new TransformStream({transform(e,A){$wA(e,g=>{const i=g.length;let I;if(i<126)I=new Uint8Array(1),new DataView(I.buffer).setUint8(0,i);else if(i<65536){I=new Uint8Array(3);const B=new DataView(I.buffer);B.setUint8(0,126),B.setUint16(1,i)}else{I=new Uint8Array(9);const B=new DataView(I.buffer);B.setUint8(0,127),B.setBigUint64(1,BigInt(i))}e.data&&typeof e.data!="string"&&(I[0]|=128),A.enqueue(I),A.enqueue(g)})}})}let YS;function ec(e){return e.reduce((A,g)=>A+g.length,0)}function gc(e,A){if(e[0].length===A)return e.shift();const g=new Uint8Array(A);let i=0;for(let I=0;I<A;I++)g[I]=e[0][i++],i===e[0].length&&(e.shift(),i=0);return e.length&&i<e[0].length&&(e[0]=e[0].slice(i)),g}function thA(e,A){YS||(YS=new TextDecoder);const g=[];let i=0,I=-1,B=!1;return new TransformStream({transform(t,C){for(g.push(t);;){if(i===0){if(ec(g)<1)break;const o=gc(g,1);B=(o[0]&128)===128,I=o[0]&127,I<126?i=3:I===126?i=1:i=2}else if(i===1){if(ec(g)<2)break;const o=gc(g,2);I=new DataView(o.buffer,o.byteOffset,o.length).getUint16(0),i=3}else if(i===2){if(ec(g)<8)break;const o=gc(g,8),r=new DataView(o.buffer,o.byteOffset,o.length),a=r.getUint32(0);if(a>Math.pow(2,21)-1){C.enqueue(cS);break}I=a*Math.pow(2,32)+r.getUint32(4),i=3}else{if(ec(g)<I)break;const o=gc(g,I);C.enqueue(uS(B?o:YS.decode(o),A)),i=0}if(I===0||I>e){C.enqueue(cS);break}}}})}const kq=4;function LI(e){if(e)return EhA(e)}function EhA(e){for(var A in LI.prototype)e[A]=LI.prototype[A];return e}LI.prototype.on=LI.prototype.addEventListener=function(e,A){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(A),this},LI.prototype.once=function(e,A){function g(){this.off(e,g),A.apply(this,arguments)}return g.fn=A,this.on(e,g),this},LI.prototype.off=LI.prototype.removeListener=LI.prototype.removeAllListeners=LI.prototype.removeEventListener=function(e,A){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var g=this._callbacks["$"+e];if(!g)return this;if(arguments.length==1)return delete this._callbacks["$"+e],this;for(var i,I=0;I<g.length;I++)if(i=g[I],i===A||i.fn===A){g.splice(I,1);break}return g.length===0&&delete this._callbacks["$"+e],this},LI.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var A=new Array(arguments.length-1),g=this._callbacks["$"+e],i=1;i<arguments.length;i++)A[i-1]=arguments[i];if(g){g=g.slice(0);for(var i=0,I=g.length;i<I;++i)g[i].apply(this,A)}return this},LI.prototype.emitReserved=LI.prototype.emit,LI.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},LI.prototype.hasListeners=function(e){return!!this.listeners(e).length};const ic=typeof Promise=="function"&&typeof Promise.resolve=="function"?A=>Promise.resolve().then(A):(A,g)=>g(A,0),iE=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),ChA="arraybuffer";function USA(){}function Nq(e,...A){return A.reduce((g,i)=>(e.hasOwnProperty(i)&&(g[i]=e[i]),g),{})}const ohA=iE.setTimeout,QhA=iE.clearTimeout;function Ic(e,A){A.useNativeTimers?(e.setTimeoutFn=ohA.bind(iE),e.clearTimeoutFn=QhA.bind(iE)):(e.setTimeoutFn=iE.setTimeout.bind(iE),e.clearTimeoutFn=iE.clearTimeout.bind(iE))}const rhA=1.33;function ahA(e){return typeof e=="string"?nhA(e):Math.ceil((e.byteLength||e.size)*rhA)}function nhA(e){let A=0,g=0;for(let i=0,I=e.length;i<I;i++)A=e.charCodeAt(i),A<128?g+=1:A<2048?g+=2:A<55296||A>=57344?g+=3:(i++,g+=4);return g}function Oq(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function shA(e){let A="";for(let g in e)e.hasOwnProperty(g)&&(A.length&&(A+="&"),A+=encodeURIComponent(g)+"="+encodeURIComponent(e[g]));return A}function whA(e){let A={},g=e.split("&");for(let i=0,I=g.length;i<I;i++){let B=g[i].split("=");A[decodeURIComponent(B[0])]=decodeURIComponent(B[1])}return A}class hhA extends Error{constructor(A,g,i){super(A),this.description=g,this.context=i,this.type="TransportError"}}class GS extends LI{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,g,i){return super.emitReserved("error",new hhA(A,g,i)),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 g=uS(A,this.socket.binaryType);this.onPacket(g)}onPacket(A){super.emitReserved("packet",A)}onClose(A){this.readyState="closed",super.emitReserved("close",A)}pause(A){}createUri(A,g={}){return A+"://"+this._hostname()+this._port()+this.opts.path+this._query(g)}_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 g=shA(A);return g.length?"?"+g:""}}class MhA extends GS{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(A){this.readyState="pausing";const g=()=>{this.readyState="paused",A()};if(this._polling||!this.writable){let i=0;this._polling&&(i++,this.once("pollComplete",function(){--i||g()})),this.writable||(i++,this.once("drain",function(){--i||g()}))}else g()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(A){const g=i=>{if(this.readyState==="opening"&&i.type==="open"&&this.onOpen(),i.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(i)};IhA(A,this.socket.binaryType).forEach(g),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,ihA(A,g=>{this.doWrite(g,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const A=this.opts.secure?"https":"http",g=this.query||{};return this.opts.timestampRequests!==!1&&(g[this.opts.timestampParam]=Oq()),!this.supportsBinary&&!g.sid&&(g.b64=1),this.createUri(A,g)}}let Hq=!1;try{Hq=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const chA=Hq;function DhA(){}class lhA extends MhA{constructor(A){if(super(A),typeof location<"u"){const g=location.protocol==="https:";let i=location.port;i||(i=g?"443":"80"),this.xd=typeof location<"u"&&A.hostname!==location.hostname||i!==A.port}}doWrite(A,g){const i=this.request({method:"POST",data:A});i.on("success",g),i.on("error",(I,B)=>{this.onError("xhr post error",I,B)})}doPoll(){const A=this.request();A.on("data",this.onData.bind(this)),A.on("error",(g,i)=>{this.onError("xhr poll error",g,i)}),this.pollXhr=A}}let Xa=class dl extends LI{constructor(A,g,i){super(),this.createRequest=A,Ic(this,i),this._opts=i,this._method=i.method||"GET",this._uri=g,this._data=i.data!==void 0?i.data:null,this._create()}_create(){var A;const g=Nq(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");g.xdomain=!!this._opts.xd;const i=this._xhr=this.createRequest(g);try{i.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){i.setDisableHeaderCheck&&i.setDisableHeaderCheck(!0);for(let I in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(I)&&i.setRequestHeader(I,this._opts.extraHeaders[I])}}catch{}if(this._method==="POST")try{i.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{i.setRequestHeader("Accept","*/*")}catch{}(A=this._opts.cookieJar)===null||A===void 0||A.addCookies(i),"withCredentials"in i&&(i.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(i.timeout=this._opts.requestTimeout),i.onreadystatechange=()=>{var I;i.readyState===3&&((I=this._opts.cookieJar)===null||I===void 0||I.parseCookies(i.getResponseHeader("set-cookie"))),i.readyState===4&&(i.status===200||i.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof i.status=="number"?i.status:0)},0))},i.send(this._data)}catch(I){this.setTimeoutFn(()=>{this._onError(I)},0);return}typeof document<"u"&&(this._index=dl.requestsCount++,dl.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=DhA,A)try{this._xhr.abort()}catch{}typeof document<"u"&&delete dl.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(Xa.requestsCount=0,Xa.requests={},typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",yq);else if(typeof addEventListener=="function"){const e="onpagehide"in iE?"pagehide":"unload";addEventListener(e,yq,!1)}}function yq(){for(let e in Xa.requests)Xa.requests.hasOwnProperty(e)&&Xa.requests[e].abort()}const uhA=function(){const e=xq({xdomain:!1});return e&&e.responseType!==null}();class YhA extends lhA{constructor(A){super(A);const g=A&&A.forceBase64;this.supportsBinary=uhA&&!g}request(A={}){return Object.assign(A,{xd:this.xd},this.opts),new Xa(xq,this.uri(),A)}}function xq(e){const A=e.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!A||chA))return new XMLHttpRequest}catch{}if(!A)try{return new iE[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}const Jq=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class GhA extends GS{get name(){return"websocket"}doOpen(){const A=this.uri(),g=this.opts.protocols,i=Jq?{}:Nq(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(i.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(A,g,i)}catch(I){return this.emitReserved("error",I)}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 g=0;g<A.length;g++){const i=A[g],I=g===A.length-1;DS(i,this.supportsBinary,B=>{try{this.doWrite(i,B)}catch{}I&&ic(()=>{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",g=this.query||{};return this.opts.timestampRequests&&(g[this.opts.timestampParam]=Oq()),this.supportsBinary||(g.b64=1),this.createUri(A,g)}}const RS=iE.WebSocket||iE.MozWebSocket;class RhA extends GhA{createSocket(A,g,i){return Jq?new RS(A,g,i):g?new RS(A,g):new RS(A)}doWrite(A,g){this.ws.send(g)}}class FhA extends GS{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 g=thA(Number.MAX_SAFE_INTEGER,this.socket.binaryType),i=A.readable.pipeThrough(g).getReader(),I=BhA();I.readable.pipeTo(A.writable),this._writer=I.writable.getWriter();const B=()=>{i.read().then(({done:C,value:o})=>{C||(this.onPacket(o),B())}).catch(C=>{})};B();const t={type:"open"};this.query.sid&&(t.data=`{"sid":"${this.query.sid}"}`),this._writer.write(t).then(()=>this.onOpen())})})}write(A){this.writable=!1;for(let g=0;g<A.length;g++){const i=A[g],I=g===A.length-1;this._writer.write(i).then(()=>{I&&ic(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var A;(A=this._transport)===null||A===void 0||A.close()}}const dhA={websocket:RhA,webtransport:FhA,polling:YhA},UhA=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,mhA=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function FS(e){if(e.length>8e3)throw"URI too long";const A=e,g=e.indexOf("["),i=e.indexOf("]");g!=-1&&i!=-1&&(e=e.substring(0,g)+e.substring(g,i).replace(/:/g,";")+e.substring(i,e.length));let I=UhA.exec(e||""),B={},t=14;for(;t--;)B[mhA[t]]=I[t]||"";return g!=-1&&i!=-1&&(B.source=A,B.host=B.host.substring(1,B.host.length-1).replace(/;/g,":"),B.authority=B.authority.replace("[","").replace("]","").replace(/;/g,":"),B.ipv6uri=!0),B.pathNames=ShA(B,B.path),B.queryKey=phA(B,B.query),B}function ShA(e,A){const g=/\/{2,9}/g,i=A.replace(g,"/").split("/");return(A.slice(0,1)=="/"||A.length===0)&&i.splice(0,1),A.slice(-1)=="/"&&i.splice(i.length-1,1),i}function phA(e,A){const g={};return A.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(i,I,B){I&&(g[I]=B)}),g}const dS=typeof addEventListener=="function"&&typeof removeEventListener=="function",Bc=[];dS&&addEventListener("offline",()=>{Bc.forEach(e=>e())},!1);class sQ extends LI{constructor(A,g){if(super(),this.binaryType=ChA,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,A&&typeof A=="object"&&(g=A,A=null),A){const i=FS(A);g.hostname=i.host,g.secure=i.protocol==="https"||i.protocol==="wss",g.port=i.port,i.query&&(g.query=i.query)}else g.host&&(g.hostname=FS(g.host).host);Ic(this,g),this.secure=g.secure!=null?g.secure:typeof location<"u"&&location.protocol==="https:",g.hostname&&!g.port&&(g.port=this.secure?"443":"80"),this.hostname=g.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=g.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},g.transports.forEach(i=>{const I=i.prototype.name;this.transports.push(I),this._transportsByName[I]=i}),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},g),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=whA(this.opts.query)),dS&&(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 g=Object.assign({},this.opts.query);g.EIO=kq,g.transport=A,this.id&&(g.sid=this.id);const i=Object.assign({},this.opts,{query:g,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[A]);return new this._transportsByName[A](i)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}const A=this.opts.rememberUpgrade&&sQ.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";const g=this.createTransport(A);g.open(),this.setTransport(g)}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",g=>this._onClose("transport close",g))}onOpen(){this.readyState="open",sQ.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 g=new Error("server error");g.code=A.data,this._onError(g);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 g=1;for(let i=0;i<this.writeBuffer.length;i++){const I=this.writeBuffer[i].data;if(I&&(g+=ahA(I)),i>0&&g>this._maxPayload)return this.writeBuffer.slice(0,i);g+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const A=Date.now()>this._pingTimeoutTime;return A&&(this._pingTimeoutTime=0,ic(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),A}write(A,g,i){return this._sendPacket("message",A,g,i),this}send(A,g,i){return this._sendPacket("message",A,g,i),this}_sendPacket(A,g,i,I){if(typeof g=="function"&&(I=g,g=void 0),typeof i=="function"&&(I=i,i=null),this.readyState==="closing"||this.readyState==="closed")return;i=i||{},i.compress=i.compress!==!1;const B={type:A,data:g,options:i};this.emitReserved("packetCreate",B),this.writeBuffer.push(B),I&&this.once("flush",I),this.flush()}close(){const A=()=>{this._onClose("forced close"),this.transport.close()},g=()=>{this.off("upgrade",g),this.off("upgradeError",g),A()},i=()=>{this.once("upgrade",g),this.once("upgradeError",g)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?i():A()}):this.upgrading?i():A()),this}_onError(A){if(sQ.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,g){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(),dS&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const i=Bc.indexOf(this._offlineEventListener);i!==-1&&Bc.splice(i,1)}this.readyState="closed",this.id=null,this.emitReserved("close",A,g),this.writeBuffer=[],this._prevBufferLen=0}}}sQ.protocol=kq;class KhA extends sQ{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 g=this.createTransport(A),i=!1;sQ.priorWebsocketSuccess=!1;const I=()=>{i||(g.send([{type:"ping",data:"probe"}]),g.once("packet",s=>{if(!i)if(s.type==="pong"&&s.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",g),!g)return;sQ.priorWebsocketSuccess=g.name==="websocket",this.transport.pause(()=>{i||this.readyState!=="closed"&&(a(),this.setTransport(g),g.send([{type:"upgrade"}]),this.emitReserved("upgrade",g),g=null,this.upgrading=!1,this.flush())})}else{const M=new Error("probe error");M.transport=g.name,this.emitReserved("upgradeError",M)}}))};function B(){i||(i=!0,a(),g.close(),g=null)}const t=s=>{const M=new Error("probe error: "+s);M.transport=g.name,B(),this.emitReserved("upgradeError",M)};function C(){t("transport closed")}function o(){t("socket closed")}function r(s){g&&s.name!==g.name&&B()}const a=()=>{g.removeListener("open",I),g.removeListener("error",t),g.removeListener("close",C),this.off("close",o),this.off("upgrading",r)};g.once("open",I),g.once("error",t),g.once("close",C),this.once("close",o),this.once("upgrading",r),this._upgrades.indexOf("webtransport")!==-1&&A!=="webtransport"?this.setTimeoutFn(()=>{i||g.open()},200):g.open()}onHandshake(A){this._upgrades=this._filterUpgrades(A.upgrades),super.onHandshake(A)}_filterUpgrades(A){const g=[];for(let i=0;i<A.length;i++)~this.transports.indexOf(A[i])&&g.push(A[i]);return g}}let khA=class extends KhA{constructor(A,g={}){const i=typeof A=="object"?A:g;(!i.transports||i.transports&&typeof i.transports[0]=="string")&&(i.transports=(i.transports||["polling","websocket","webtransport"]).map(I=>dhA[I]).filter(I=>!!I)),super(A,i)}};function NhA(e,A="",g){let i=e;g=g||typeof location<"u"&&location,e==null&&(e=g.protocol+"//"+g.host),typeof e=="string"&&(e.charAt(0)==="/"&&(e.charAt(1)==="/"?e=g.protocol+e:e=g.host+e),/^(https?|wss?):\/\//.test(e)||(typeof g<"u"?e=g.protocol+"//"+e:e="https://"+e),i=FS(e)),i.port||(/^(http|ws)$/.test(i.protocol)?i.port="80":/^(http|ws)s$/.test(i.protocol)&&(i.port="443")),i.path=i.path||"/";const B=i.host.indexOf(":")!==-1?"["+i.host+"]":i.host;return i.id=i.protocol+"://"+B+":"+i.port+A,i.href=i.protocol+"://"+B+(g&&g.port===i.port?"":":"+i.port),i}const OhA=typeof ArrayBuffer=="function",HhA=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,jq=Object.prototype.toString,yhA=typeof Blob=="function"||typeof Blob<"u"&&jq.call(Blob)==="[object BlobConstructor]",xhA=typeof File=="function"||typeof File<"u"&&jq.call(File)==="[object FileConstructor]";function US(e){return OhA&&(e instanceof ArrayBuffer||HhA(e))||yhA&&e instanceof Blob||xhA&&e instanceof File}function tc(e,A){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let g=0,i=e.length;g<i;g++)if(tc(e[g]))return!0;return!1}if(US(e))return!0;if(e.toJSON&&typeof e.toJSON=="function"&&arguments.length===1)return tc(e.toJSON(),!0);for(const g in e)if(Object.prototype.hasOwnProperty.call(e,g)&&tc(e[g]))return!0;return!1}function JhA(e){const A=[],g=e.data,i=e;return i.data=mS(g,A),i.attachments=A.length,{packet:i,buffers:A}}function mS(e,A){if(!e)return e;if(US(e)){const g={_placeholder:!0,num:A.length};return A.push(e),g}else if(Array.isArray(e)){const g=new Array(e.length);for(let i=0;i<e.length;i++)g[i]=mS(e[i],A);return g}else if(typeof e=="object"&&!(e instanceof Date)){const g={};for(const i in e)Object.prototype.hasOwnProperty.call(e,i)&&(g[i]=mS(e[i],A));return g}return e}function jhA(e,A){return e.data=SS(e.data,A),delete e.attachments,e}function SS(e,A){if(!e)return e;if(e&&e._placeholder===!0){if(typeof e.num=="number"&&e.num>=0&&e.num<A.length)return A[e.num];throw new Error("illegal attachments")}else if(Array.isArray(e))for(let g=0;g<e.length;g++)e[g]=SS(e[g],A);else if(typeof e=="object")for(const g in e)Object.prototype.hasOwnProperty.call(e,g)&&(e[g]=SS(e[g],A));return e}const LhA=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],ThA=5;var qg;(function(e){e[e.CONNECT=0]="CONNECT",e[e.DISCONNECT=1]="DISCONNECT",e[e.EVENT=2]="EVENT",e[e.ACK=3]="ACK",e[e.CONNECT_ERROR=4]="CONNECT_ERROR",e[e.BINARY_EVENT=5]="BINARY_EVENT",e[e.BINARY_ACK=6]="BINARY_ACK"})(qg||(qg={}));class VhA{constructor(A){this.replacer=A}encode(A){return(A.type===qg.EVENT||A.type===qg.ACK)&&tc(A)?this.encodeAsBinary({type:A.type===qg.EVENT?qg.BINARY_EVENT:qg.BINARY_ACK,nsp:A.nsp,data:A.data,id:A.id}):[this.encodeAsString(A)]}encodeAsString(A){let g=""+A.type;return(A.type===qg.BINARY_EVENT||A.type===qg.BINARY_ACK)&&(g+=A.attachments+"-"),A.nsp&&A.nsp!=="/"&&(g+=A.nsp+","),A.id!=null&&(g+=A.id),A.data!=null&&(g+=JSON.stringify(A.data,this.replacer)),g}encodeAsBinary(A){const g=JhA(A),i=this.encodeAsString(g.packet),I=g.buffers;return I.unshift(i),I}}function Lq(e){return Object.prototype.toString.call(e)==="[object Object]"}class pS extends LI{constructor(A){super(),this.reviver=A}add(A){let g;if(typeof A=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");g=this.decodeString(A);const i=g.type===qg.BINARY_EVENT;i||g.type===qg.BINARY_ACK?(g.type=i?qg.EVENT:qg.ACK,this.reconstructor=new fhA(g),g.attachments===0&&super.emitReserved("decoded",g)):super.emitReserved("decoded",g)}else if(US(A)||A.base64)if(this.reconstructor)g=this.reconstructor.takeBinaryData(A),g&&(this.reconstructor=null,super.emitReserved("decoded",g));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+A)}decodeString(A){let g=0;const i={type:Number(A.charAt(0))};if(qg[i.type]===void 0)throw new Error("unknown packet type "+i.type);if(i.type===qg.BINARY_EVENT||i.type===qg.BINARY_ACK){const B=g+1;for(;A.charAt(++g)!=="-"&&g!=A.length;);const t=A.substring(B,g);if(t!=Number(t)||A.charAt(g)!=="-")throw new Error("Illegal attachments");i.attachments=Number(t)}if(A.charAt(g+1)==="/"){const B=g+1;for(;++g&&!(A.charAt(g)===","||g===A.length););i.nsp=A.substring(B,g)}else i.nsp="/";const I=A.charAt(g+1);if(I!==""&&Number(I)==I){const B=g+1;for(;++g;){const t=A.charAt(g);if(t==null||Number(t)!=t){--g;break}if(g===A.length)break}i.id=Number(A.substring(B,g+1))}if(A.charAt(++g)){const B=this.tryParse(A.substr(g));if(pS.isPayloadValid(i.type,B))i.data=B;else throw new Error("invalid payload")}return i}tryParse(A){try{return JSON.parse(A,this.reviver)}catch{return!1}}static isPayloadValid(A,g){switch(A){case qg.CONNECT:return Lq(g);case qg.DISCONNECT:return g===void 0;case qg.CONNECT_ERROR:return typeof g=="string"||Lq(g);case qg.EVENT:case qg.BINARY_EVENT:return Array.isArray(g)&&(typeof g[0]=="number"||typeof g[0]=="string"&&LhA.indexOf(g[0])===-1);case qg.ACK:case qg.BINARY_ACK:return Array.isArray(g)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class fhA{constructor(A){this.packet=A,this.buffers=[],this.reconPack=A}takeBinaryData(A){if(this.buffers.push(A),this.buffers.length===this.reconPack.attachments){const g=jhA(this.reconPack,this.buffers);return this.finishedReconstruction(),g}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const zhA=Object.freeze(Object.defineProperty({__proto__:null,Decoder:pS,Encoder:VhA,get PacketType(){return qg},protocol:ThA},Symbol.toStringTag,{value:"Module"}));function LE(e,A,g){return e.on(A,g),function(){e.off(A,g)}}const bhA=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Tq extends LI{constructor(A,g,i){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=g,i&&i.auth&&(this.auth=i.auth),this._opts=Object.assign({},i),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const A=this.io;this.subs=[LE(A,"open",this.onopen.bind(this)),LE(A,"packet",this.onpacket.bind(this)),LE(A,"error",this.onerror.bind(this)),LE(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,...g){var i,I,B;if(bhA.hasOwnProperty(A))throw new Error('"'+A.toString()+'" is a reserved event name');if(g.unshift(A),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(g),this;const t={type:qg.EVENT,data:g};if(t.options={},t.options.compress=this.flags.compress!==!1,typeof g[g.length-1]=="function"){const a=this.ids++,s=g.pop();this._registerAckCallback(a,s),t.id=a}const C=(I=(i=this.io.engine)===null||i===void 0?void 0:i.transport)===null||I===void 0?void 0:I.writable,o=this.connected&&!(!((B=this.io.engine)===null||B===void 0)&&B._hasPingExpired());return this.flags.volatile&&!C||(o?(this.notifyOutgoingListeners(t),this.packet(t)):this.sendBuffer.push(t)),this.flags={},this}_registerAckCallback(A,g){var i;const I=(i=this.flags.timeout)!==null&&i!==void 0?i:this._opts.ackTimeout;if(I===void 0){this.acks[A]=g;return}const B=this.io.setTimeoutFn(()=>{delete this.acks[A];for(let C=0;C<this.sendBuffer.length;C++)this.sendBuffer[C].id===A&&this.sendBuffer.splice(C,1);g.call(this,new Error("operation has timed out"))},I),t=(...C)=>{this.io.clearTimeoutFn(B),g.apply(this,C)};t.withError=!0,this.acks[A]=t}emitWithAck(A,...g){return new Promise((i,I)=>{const B=(t,C)=>t?I(t):i(C);B.withError=!0,g.push(B),this.emit(A,...g)})}_addToQueue(A){let g;typeof A[A.length-1]=="function"&&(g=A.pop());const i={id:this._queueSeq++,tryCount:0,pending:!1,args:A,flags:Object.assign({fromQueue:!0},this.flags)};A.push((I,...B)=>i!==this._queue[0]?void 0:(I!==null?i.tryCount>this._opts.retries&&(this._queue.shift(),g&&g(I)):(this._queue.shift(),g&&g(null,...B)),i.pending=!1,this._drainQueue())),this._queue.push(i),this._drainQueue()}_drainQueue(A=!1){if(!this.connected||this._queue.length===0)return;const g=this._queue[0];g.pending&&!A||(g.pending=!0,g.tryCount++,this.flags=g.flags,this.emit.apply(this,g.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:qg.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,g){this.connected=!1,delete this.id,this.emitReserved("disconnect",A,g),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(A=>{if(!this.sendBuffer.some(i=>String(i.id)===A)){const i=this.acks[A];delete this.acks[A],i.withError&&i.call(this,new Error("socket has been disconnected"))}})}onpacket(A){if(A.nsp===this.nsp)switch(A.type){case qg.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 qg.EVENT:case qg.BINARY_EVENT:this.onevent(A);break;case qg.ACK:case qg.BINARY_ACK:this.onack(A);break;case qg.DISCONNECT:this.ondisconnect();break;case qg.CONNECT_ERROR:this.destroy();const i=new Error(A.data.message);i.data=A.data.data,this.emitReserved("connect_error",i);break}}onevent(A){const g=A.data||[];A.id!=null&&g.push(this.ack(A.id)),this.connected?this.emitEvent(g):this.receiveBuffer.push(Object.freeze(g))}emitEvent(A){if(this._anyListeners&&this._anyListeners.length){const g=this._anyListeners.slice();for(const i of g)i.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 g=this;let i=!1;return function(...I){i||(i=!0,g.packet({type:qg.ACK,id:A,data:I}))}}onack(A){const g=this.acks[A.id];typeof g=="function"&&(delete this.acks[A.id],g.withError&&A.data.unshift(null),g.apply(this,A.data))}onconnect(A,g){this.id=A,this.recovered=g&&this._pid===g,this._pid=g,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:qg.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 g=this._anyListeners;for(let i=0;i<g.length;i++)if(A===g[i])return g.splice(i,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 g=this._anyOutgoingListeners;for(let i=0;i<g.length;i++)if(A===g[i])return g.splice(i,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(A){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const g=this._anyOutgoingListeners.slice();for(const i of g)i.apply(this,A.data)}}}function _a(e){e=e||{},this.ms=e.min||100,this.max=e.max||1e4,this.factor=e.factor||2,this.jitter=e.jitter>0&&e.jitter<=1?e.jitter:0,this.attempts=0}_a.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var A=Math.random(),g=Math.floor(A*this.jitter*e);e=(Math.floor(A*10)&1)==0?e-g:e+g}return Math.min(e,this.max)|0},_a.prototype.reset=function(){this.attempts=0},_a.prototype.setMin=function(e){this.ms=e},_a.prototype.setMax=function(e){this.max=e},_a.prototype.setJitter=function(e){this.jitter=e};class KS extends LI{constructor(A,g){var i;super(),this.nsps={},this.subs=[],A&&typeof A=="object"&&(g=A,A=void 0),g=g||{},g.path=g.path||"/socket.io",this.opts=g,Ic(this,g),this.reconnection(g.reconnection!==!1),this.reconnectionAttempts(g.reconnectionAttempts||1/0),this.reconnectionDelay(g.reconnectionDelay||1e3),this.reconnectionDelayMax(g.reconnectionDelayMax||5e3),this.randomizationFactor((i=g.randomizationFactor)!==null&&i!==void 0?i:.5),this.backoff=new _a({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(g.timeout==null?2e4:g.timeout),this._readyState="closed",this.uri=A;const I=g.parser||zhA;this.encoder=new I.Encoder,this.decoder=new I.Decoder,this._autoConnect=g.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 g;return A===void 0?this._reconnectionDelay:(this._reconnectionDelay=A,(g=this.backoff)===null||g===void 0||g.setMin(A),this)}randomizationFactor(A){var g;return A===void 0?this._randomizationFactor:(this._randomizationFactor=A,(g=this.backoff)===null||g===void 0||g.setJitter(A),this)}reconnectionDelayMax(A){var g;return A===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=A,(g=this.backoff)===null||g===void 0||g.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 khA(this.uri,this.opts);const g=this.engine,i=this;this._readyState="opening",this.skipReconnect=!1;const I=LE(g,"open",function(){i.onopen(),A&&A()}),B=C=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",C),A?A(C):this.maybeReconnectOnOpen()},t=LE(g,"error",B);if(this._timeout!==!1){const C=this._timeout,o=this.setTimeoutFn(()=>{I(),B(new Error("timeout")),g.close()},C);this.opts.autoUnref&&o.unref(),this.subs.push(()=>{this.clearTimeoutFn(o)})}return this.subs.push(I),this.subs.push(t),this}connect(A){return this.open(A)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const A=this.engine;this.subs.push(LE(A,"ping",this.onping.bind(this)),LE(A,"data",this.ondata.bind(this)),LE(A,"error",this.onerror.bind(this)),LE(A,"close",this.onclose.bind(this)),LE(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(A){try{this.decoder.add(A)}catch(g){this.onclose("parse error",g)}}ondecoded(A){ic(()=>{this.emitReserved("packet",A)},this.setTimeoutFn)}onerror(A){this.emitReserved("error",A)}socket(A,g){let i=this.nsps[A];return i?this._autoConnect&&!i.active&&i.connect():(i=new Tq(this,A,g),this.nsps[A]=i),i}_destroy(A){const g=Object.keys(this.nsps);for(const i of g)if(this.nsps[i].active)return;this._close()}_packet(A){const g=this.encoder.encode(A);for(let i=0;i<g.length;i++)this.engine.write(g[i],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,g){var i;this.cleanup(),(i=this.engine)===null||i===void 0||i.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",A,g),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 g=this.backoff.duration();this._reconnecting=!0;const i=this.setTimeoutFn(()=>{A.skipReconnect||(this.emitReserved("reconnect_attempt",A.backoff.attempts),!A.skipReconnect&&A.open(I=>{I?(A._reconnecting=!1,A.reconnect(),this.emitReserved("reconnect_error",I)):A.onreconnect()}))},g);this.opts.autoUnref&&i.unref(),this.subs.push(()=>{this.clearTimeoutFn(i)})}}onreconnect(){const A=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",A)}}const qs={};function Ec(e,A){typeof e=="object"&&(A=e,e=void 0),A=A||{};const g=NhA(e,A.path||"/socket.io"),i=g.source,I=g.id,B=g.path,t=qs[I]&&B in qs[I].nsps,C=A.forceNew||A["force new connection"]||A.multiplex===!1||t;let o;return C?o=new KS(i,A):(qs[I]||(qs[I]=new KS(i,A)),o=qs[I]),g.query&&!A.query&&(A.query=g.queryKey),o.socket(g.path,A)}Object.assign(Ec,{Manager:KS,Socket:Tq,io:Ec,connect:Ec});const Zs="https://api.tybotflow.com/api/v1",qhA="https://api.tybotflow.com/api/v1/chatbots-config",Vq="https://migration-meta.tybotflow.com/",fq=Vq+"webhook/v",Cc=Ec(Vq,{transports:["websocket","polling"],reconnection:!0,reconnectionAttempts:3,autoConnect:!0,reconnectionDelay:2e3}),zq=new wo,kS=e=>{if(!e||!e.message)return"👋 Hey there! how can I help you?";const A=e.message;if(typeof A=="string")return A;if(Array.isArray(A)){const g=window.location.href,i=window.location.origin,I=window.location.pathname,B=i+I;for(const C of A){if(!C.urls||C.urls.length===0)continue;if(C.urls.some(r=>{if(!r||r.trim()==="")return!1;try{let a=r.trim();!a.startsWith("http://")&&!a.startsWith("https://")&&(a="https://"+a);const s=new URL(a),M=s.origin,w=s.pathname,c=M+w;return B===c||g===a?!0:w==="/"||w===""?i===M:!!g.startsWith(a)}catch{return console.warn("Invalid URL in message:",r),!1}}))return C.text||"👋 Hey there! how can I help you?"}const t=A.find(C=>!C.urls||C.urls.length===0||C.urls.every(o=>!o||o.trim()===""));if(t)return t.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?"},bq=(e,A)=>{const g={className:"w-5 h-5",style:{color:A}};switch(e?.toLowerCase()){case"pdf":return y.jsx(ns,{...g});case"doc":case"docx":return y.jsx(ns,{...g});case"xls":case"xlsx":case"csv":return y.jsx(sgA,{...g});case"ppt":case"pptx":return y.jsx(YgA,{...g});case"zip":case"rar":case"7z":case"tar":case"gz":return y.jsx(CgA,{...g});case"txt":case"md":case"rtf":return y.jsx(Ey,{...g});default:return y.jsx(ns,{...g})}},ZhA=({config:e})=>{const A=ee.useRef(null),g=ee.useRef(null),i=ee.useRef(null),I=ee.useRef(null),B=ee.useRef(null),[t,C]=ee.useState(null),[o,r]=ee.useState(!0);ee.useEffect(()=>{(async()=>{r(!0),await Oi.get(`${qhA}/bot/${e.bot?.botId}`,{}).then(yA=>{C(yA.data)}).catch(yA=>{console.error("Error fetching bot config:",yA)}).finally(()=>{r(!1)})})()},[e.bot?.botId,e?.token]);const a=t?.mainColor||"#59168b",s=t?.secondaryColor||"#6366f1",M=t?.thirdColor||"#0f172b",w=t?.headerFirstColor||"#6e11b0",c=t?.headerSecondColor||"#372aac",l=t?.inputBackgroundColor||"#1f2937",G=t?.inputTextColor||"#fff",u=t?.roundness||24,F=t?.chatRoundness||16,d=(t?.minPanelWidth||434)>window.innerWidth?window.innerWidth:t?.minPanelWidth||434,p=(t?.maxPanelWidth||window.innerWidth)>window.innerWidth?window.innerWidth:t?.maxPanelWidth||window.innerWidth,O=t?.chatMaxWidth||88,S=t?.toggleBtnBorderTopLeftRadius||12,j=t?.toggleBtnBorderTopRightRadius||0,L=t?.toggleBtnBorderBottomLeftRadius||12,x=t?.toggleBtnBorderBottomRightRadius||0,z=t?.menuBackgroundColor||"#1f2937",H=t?.menuTextColor||"#e5e7eb",f=t?.menuHoverBackgroundColor||"#374151",q=t?.agentChatResponseColor||"#e5e7eb",b=t?.agentChatResponseBgColor||"#1f2937",AA=t?.agentIconBgColor||"#59168b",v=t?.agentIconColor||"#fff",IA=t?.userChatMessagesColor||"#fff",$=t?.userChatMessagesBgColor||"#7a1ebe",CA=t?.userIconBgColor||"#7a1ebe",K=t?.userIconColor||"#fff",X=t?.ButtonColor||"#fff",T=t?.ButtonsBgColor||"#59168b",k=t?.fontSize||13,_=t?.toggleBtnPosition||"bottom-right",EA=t?.autoOpenPanel??!0,oA=t?.tempToken||"",lA=(()=>{const J=t?.firstMessageKeyword;if(Array.isArray(J)){const yA=window.location.href,FA=J.find(Fe=>Fe.url&&Fe.url===yA);if(FA)return FA.message;const ZA=J.find(Fe=>!Fe.url||Fe.url==="");return ZA?ZA.message:J[0]?.message||"hi"}return J||"hi"})(),RA=J=>({ip:J.ip||"",flag:{img:J.flag||"",emoji:J.emoji_flag||"",emoji_unicode:J.emoji_unicode||""},is_eu:J.is_eu??!1,postal:J.postal||"",borders:"",latitude:J.latitude||0,platform:J?.platform||"",timezone:{id:J.time_zone?.name||"",utc:J.time_zone?.offset||"",abbr:J.time_zone?.abbr||"",is_dst:J.time_zone?.is_dst??!1,offset:J.time_zone?.offset||0,current_time:J.time_zone?.current_time||""},continent:J.continent_name||"",longitude:J.longitude||0,connection:{asn:J.asn?.asn||0,isp:J.asn?.name||"",org:J.asn?.name||"",domain:J.asn?.domain||""}}),[mA,WA]=ee.useState(d),ne=ee.useRef(!1),ie=ee.useRef(0),kA=ee.useRef(d),iA=J=>{ne.current=!0,ie.current=J.clientX,kA.current=mA,document.body.style.cursor="ew-resize"};ee.useEffect(()=>{const J=FA=>{if(!ne.current)return;const ZA=ie.current-FA.clientX;let Fe=kA.current+ZA;Fe=Math.max(d,Math.min(p,Fe)),WA(Fe)},yA=()=>{ne.current&&(ne.current=!1,document.body.style.cursor="")};return window.addEventListener("mousemove",J),window.addEventListener("mouseup",yA),()=>{window.removeEventListener("mousemove",J),window.removeEventListener("mouseup",yA)}},[mA,d,p]);const[zA,ce]=ee.useState(!1),[Ce,jA]=ee.useState(!1),[Ie,Ae]=ee.useState(!1),[Ye,oe]=ee.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,bA]=ee.useState(!1),[wA,GA]=ee.useState({x:0,y:0}),HA=ee.useRef(null),[VA,De]=ee.useState(""),[le,ke]=ee.useState(!1),[He,Ge]=ee.useState(!1),[Re,je]=ee.useState([]),[Ue,Ve]=ee.useState(!1),Ne=ee.useRef(0),[ve,lg]=ee.useState(!1),[$e,Ze]=ee.useState(!1),ug=ee.useRef(!1),[DB,Bg]=ee.useState("00:00"),Ii=ee.useRef(null),iI=ee.useRef(0),[Pe,ji]=ee.useState(null),[mg,$g]=ee.useState(!1),[Ei,Yg]=ee.useState(new Set),[dg,Zg]=ee.useState([]),{startRecording:et,stopRecording:FI,pauseRecording:zI,resumeRecording:ai,status:Ug,error:qi}=_tA.useReactMediaRecorder({video:!1,onStop(J,yA){if(ug.current){ug.current=!1,Bg("00:00"),iI.current=0;return}je(FA=>[...FA,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),file:yA,type:"audio",url:J,name:`recording-${new Date().toISOString()}.webm`,size:yA.size}]),Bg("00:00"),iI.current=0}}),mi=t?.icon||e?.bot.avatar_url||Zf,yg=t?.title||e?.bot.name||"Tybot webchat",[Bi,pe]=ee.useState(null),[MA,Qe]=ee.useState(()=>{const J=localStorage.getItem("phone_client");if(e.bot?.botId==="rockskin"&&J)return J;if(!t?.botNeedsAuth){let yA=localStorage.getItem("externalUser");if(!yA){const FA=new Uint8Array(16);window.crypto.getRandomValues(FA),yA=Array.from(FA).map(ZA=>ZA.toString(16).padStart(2,"0")).join("")}return localStorage.setItem("externalUser",yA),yA}});ee.useEffect(()=>{if(!Bi)return;const J=yA=>{if(yA.bot.conversationId!==parseInt(Bi)){ke(!1);return}const FA={id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:yA.bot.item,timestamp:new Date,seen:dI.current,nMessage:Array.isArray(yA.bot.item)?yA.bot.item.length:1};Zg(ZA=>ZA.some(KA=>KA.id===FA.id)?ZA:[...ZA,FA]),ke(!1)};return Cc.on("bot-message",J),()=>{Cc.off("bot-message",J)}},[Bi,e?.bot?.botId]),ee.useEffect(()=>{(async()=>{if(!(Bi||!e.bot?.botId||!MA))try{const FA=(await Oi.post(`${Zs}/conversations/start-conversation`,{bot_id:e.bot?.botId,externalUser:MA})).data.conversationId;pe(FA),localStorage.setItem("conversationId",FA),Cc.emit("join_room",parseInt(FA))}catch(yA){console.error("Error initializing conversation:",yA)}})()},[Bi,e.bot?.botId,MA]);const[me,Ai]=ee.useState(()=>t?.botNeedsAuth?!!localStorage.getItem("conversationId"):!0),[ei,ni]=ee.useState(""),[si,wi]=ee.useState(""),[Si,Ft]=ee.useState(""),[Pg,LB]=ee.useState(null),dI=ee.useRef(!1),IB=dg.reduce((J,yA)=>yA.seen?J:J+(yA.sender==="agent"?yA.nMessage||1:0),0),QE=()=>{Zg(J=>J.map(yA=>({...yA,seen:!0})))};ee.useEffect(()=>{let J;return!localStorage.getItem("webChatOpen")&&t&&EA&&(J=setTimeout(()=>{ce(!0),dI.current=!0,QE(),localStorage.setItem("webChatOpen","true")},3200)),()=>clearTimeout(J)},[t]),ee.useEffect(()=>{const J=t?.widgetLoadBehavior;if(!J||!(()=>{const ZA=J.message;if(typeof ZA=="string"){if(!J.urls||J.urls.length===0)return!0;const Fe=window.location.origin,KA=window.location.href;return J.urls.some(hg=>{if(!hg||hg.trim()==="")return!0;try{return Fe.includes(hg)||KA.includes(hg)||hg.includes(Fe)}catch{return console.warn("Invalid URL in widgetLoadBehavior:",hg),!1}})}if(Array.isArray(ZA)){const Fe=window.location.href,KA=window.location.origin,hg=window.location.pathname,Gg=KA+hg;for(const Zi of ZA)if(!Zi.urls||Zi.urls.length===0||Zi.urls.every(hi=>!hi||hi.trim()==="")||Zi.urls.some(hi=>{if(!hi||hi.trim()==="")return!1;try{let nI=hi.trim();!nI.startsWith("http://")&&!nI.startsWith("https://")&&(nI="https://"+nI);const tt=new URL(nI),ze=tt.origin,EB=tt.pathname,Sg=ze+EB;return Gg===Sg||Fe===nI?!0:EB==="/"||EB===""?KA===ze:!!Fe.startsWith(nI)}catch{return console.warn("Invalid URL in message:",hi),!1}}))return!0;return!1}return!0})())return;let FA;if(J.behavior==="after seconds")FA=setTimeout(()=>{Ae(!0)},J.value*1e3);else if(J.behavior==="after scroll"){const ZA=()=>{const Fe=window.pageYOffset||document.documentElement.scrollTop,KA=document.documentElement.scrollHeight-document.documentElement.clientHeight;Fe/KA*100>=J.value&&(Ae(!0),window.removeEventListener("scroll",ZA))};return window.addEventListener("scroll",ZA),()=>{window.removeEventListener("scroll",ZA)}}return()=>{FA&&clearTimeout(FA)}},[t?.widgetLoadBehavior]),ee.useEffect(()=>{zA&&Ae(!1)},[zA]),ee.useEffect(()=>{fetch("https://api.ipdata.co/?api-key=7930ffd0621dafcb6cd830a503d726bf514b74c1cae21ffff8131890").then(function(J){J.json().then(yA=>{LB({...yA,platform:zq.getOS().name+" "+zq.getOS().version})})}).catch(function(J){console.log(J)})},[]);const yC=ee.useCallback(async(J,yA=[],FA)=>{if(!e.bot.botId||!Bi){ke(!1),Zg(Fe=>[...Fe,{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(yA.length>0||FA&&typeof FA=="object"&&FA.attachment!==void 0){const Fe=FA&&typeof FA!="string"?FA.attachment.file:yA[0]?.file,KA=FA&&typeof FA!="string"?FA.attachment.type:yA[0]?.type||"file";let hg=FA;if(FA&&typeof FA=="object"&&FA.attachment!==void 0){const{attachment:Zi,...Kg}=FA;hg=Kg}const Gg=new FormData;Gg.append("type",KA),Gg.append("file",Fe),Gg.append("botId",e.bot.botId),Gg.append("external_id",MA||""),Gg.append("isintern",e.token?"true":"false"),Gg.append("host",window.location.origin),Gg.append("channel","web"),Gg.append("payload",hg?JSON.stringify(hg):""),await Oi.post(fq,Gg,{headers:{Authorization:`Bearer ${e?.token}`,"Content-Type":"multipart/form-data"}})}else{const Fe={type:"text",messageText:J,botId:e.bot.botId,external_id:MA||"",isintern:!!e.token,host:window.location.origin,channel:"web"};FA&&(Fe.payload=FA),await Oi.post(fq,Fe,{headers:{Authorization:`Bearer ${e?.token}`,"Content-Type":"application/json"}})}},[e.bot.botId,Bi,e.token,e.user?.id]),Vg=ee.useCallback(async()=>{if(e.bot.botId&&Bi){ke(!0);try{await yC(lA)}catch(J){console.error("Error sending first message:",J),ke(!1)}}},[e.bot.botId,lA,Bi,yC]);ee.useEffect(()=>{Bi&&me&&e?.bot&&dg.length===0&&t&&EA&&(Vg(),localStorage.getItem("webChatAuth")&&JSON.parse(localStorage.getItem("webChatAuth"))&&t?.botNeedsAuth&&Bi&&(ei||Si||si)&&(setTimeout(()=>{dt(Bi)},2e3),localStorage.setItem("webChatAuth","true")))},[me,e?.bot,Bi,t]),ee.useEffect(()=>(Ug==="recording"?Ii.current||(Ii.current=setInterval(()=>{iI.current+=1;const J=Math.floor(iI.current/60).toString().padStart(2,"0"),yA=(iI.current%60).toString().padStart(2,"0");Bg(`${J}:${yA}`)},1e3)):Ii.current&&(clearInterval(Ii.current),Ii.current=null),()=>{Ii.current&&(clearInterval(Ii.current),Ii.current=null)}),[Ug]),ee.useEffect(()=>{qi&&qi.toLowerCase().includes("permission_denied")&&(Ze(!1),Bg("00:00"),iI.current=0,Ii.current&&(clearInterval(Ii.current),Ii.current=null),alert("Microphone permission denied. Please allow access to record audio."))},[qi]),ee.useEffect(()=>{Ug!=="recording"&&Ug!=="paused"&&(Bg("00:00"),iI.current=0)},[Ug]);const rE=ee.useRef(null);ee.useEffect(()=>{if(rE&&rE.current){const J=rE.current;J.style.height="auto";const yA=120;J.scrollHeight>yA?(J.style.height=yA+"px",J.style.overflowY="auto"):(J.style.height=J.scrollHeight+"px",J.style.overflowY="hidden")}},[VA]),ee.useEffect(()=>{(zA||le)&&A.current&&(A.current.scrollTop=A.current.scrollHeight)},[dg,le,zA]);const mQ=J=>{const yA=J.type.toLowerCase();return yA.startsWith("image/")?"image":yA.startsWith("video/")?"video":yA.startsWith("audio/")?"audio":"document"},UI=ee.useCallback((J,yA)=>{const FA=[];Array.from(J).forEach(ZA=>{if(ZA.size>10*1024*1024){alert(`File ${ZA.name} is too large. Maximum size is 10MB.`);return}const Fe={id:Date.now().toString()+Math.random().toString(36).substring(2,9),file:ZA,type:mQ(ZA),url:URL.createObjectURL(ZA),name:ZA.name,size:ZA.size};FA.push(Fe)}),je(ZA=>[...ZA,...FA]),yA&&yA.current&&(yA.current.value="")},[]),aE=ee.useCallback(J=>{J.preventDefault(),Ne.current=0,Ve(!1);const yA=J.dataTransfer.files;yA.length>0&&UI(yA)},[UI]),BB=ee.useCallback(J=>{J.preventDefault(),Ne.current+=1,Ve(!0)},[]),PE=ee.useCallback(J=>{J.preventDefault()},[]),fg=ee.useCallback(J=>{J.preventDefault(),Ne.current-=1,Ne.current<=0&&Ve(!1)},[]),vE=ee.useCallback(J=>{je(yA=>{const FA=yA.find(ZA=>ZA.id===J);return FA&&URL.revokeObjectURL(FA.url),yA.filter(ZA=>ZA.id!==J)})},[]),SQ=J=>{if(J===0)return"0 Bytes";const yA=1024,FA=["Bytes","KB","MB","GB"],ZA=Math.floor(Math.log(J)/Math.log(yA));return Number.parseFloat((J/Math.pow(yA,ZA)).toFixed(2))+" "+FA[ZA]},Li=async(J=VA,yA)=>{if(J.trim()||Re.length!==0){const ZA={id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"user",content:J,attachments:[...Re],timestamp:new Date};if(Zg(Fe=>[...Fe,ZA]),De(""),je([]),ke(!0),e?.bot)try{if(!Bi){ke(!1),Zg(Fe=>[...Fe,{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:dI.current,nMessage:1}]);return}await yC(J,Re,yA)}catch{Zg(Fe=>[...Fe,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"Erreur du serveur",timestamp:new Date,seen:dI.current,nMessage:1}]),ke(!1)}else Zg(Fe=>[...Fe,{id:Date.now().toString()+Math.random().toString(36).substring(2,9),sender:"agent",content:"Aucun bot sélectionné",timestamp:new Date,seen:dI.current,nMessage:1}]),ke(!1)}else return},gt=J=>{switch(lg(!1),J){case"image":g.current?.click();break;case"video":i.current?.click();break;case"audio":I.current?.click();break;case"document":B.current?.click();break}};ee.useEffect(()=>{const J=dg.slice().reverse().find(yA=>yA.sender==="agent");if(J){let yA=!1;Array.isArray(J.content)&&(yA=J.content.some(FA=>FA.type==="text"&&typeof FA.text=="object"&&FA.text.type==="EVFORM")),Ge(yA)}else Ge(!1)},[dg]);const[it,ft]=ee.useState(!1),tB=ee.useRef({x:0,y:0}),nE=J=>{J.preventDefault(),J.stopPropagation(),bA(!0),ft(!1),tB.current={x:J.clientX,y:J.clientY},GA({x:J.clientX-Ye.x,y:J.clientY-Ye.y}),document.body.style.cursor="grabbing",document.body.style.userSelect="none"},xC=J=>{J.preventDefault(),J.stopPropagation();const yA=J.touches[0];bA(!0),ft(!1),tB.current={x:yA.clientX,y:yA.clientY},GA({x:yA.clientX-Ye.x,y:yA.clientY-Ye.y})},zt=J=>{if(J.preventDefault(),J.stopPropagation(),it){ft(!1);return}ce(yA=>!yA),dI.current=!zA,zA||QE(),!EA&&dg.length===0&&Vg()};ee.useEffect(()=>{const J=Fe=>{if(!SA)return;const KA=Math.abs(Fe.clientX-tB.current.x),hg=Math.abs(Fe.clientY-tB.current.y);(KA>5||hg>5)&&ft(!0);const Gg=Fe.clientX-wA.x,Zi=Fe.clientY-wA.y,Kg=67,hi=window.innerWidth-document.body.clientWidth,nI=Math.max(0,Math.min(window.innerWidth-Kg-hi,Gg)),tt=Math.max(0,Math.min(window.innerHeight-Kg,Zi));oe({x:nI,y:tt})},yA=Fe=>{if(!SA)return;Fe.preventDefault();const KA=Fe.touches[0],hg=Math.abs(KA.clientX-tB.current.x),Gg=Math.abs(KA.clientY-tB.current.y);(hg>5||Gg>5)&&ft(!0);const Zi=KA.clientX-wA.x,Kg=KA.clientY-wA.y,hi=67,nI=window.innerWidth-document.body.clientWidth,tt=Math.max(0,Math.min(window.innerWidth-hi-nI,Zi)),ze=Math.max(0,Math.min(window.innerHeight-hi,Kg));oe({x:tt,y:ze})},FA=()=>{SA&&(bA(!1),document.body.style.cursor="",document.body.style.userSelect="")},ZA=()=>{SA&&bA(!1)};return SA&&(document.addEventListener("mousemove",J),document.addEventListener("touchmove",yA,{passive:!1}),document.addEventListener("mouseup",FA),document.addEventListener("touchend",ZA)),()=>{document.removeEventListener("mousemove",J),document.removeEventListener("touchmove",yA),document.removeEventListener("mouseup",FA),document.removeEventListener("touchend",ZA)}},[SA,wA,Ye]),ee.useEffect(()=>{const J=()=>{const FA=window.innerWidth-67,ZA=window.innerHeight-67;oe(Fe=>({x:Math.max(0,Math.min(FA,Fe.x)),y:Math.max(0,Math.min(ZA,Fe.y))}))};return window.addEventListener("resize",J),()=>window.removeEventListener("resize",J)},[]),ee.useEffect(()=>{const J=async()=>{try{await Oi.patch(`${Zs}/widget/endusers/${MA}`,{fiche_contact:{city:Pg.city,platform:Pg.platform,region:Pg.region,country:Pg.country_name,age:0,full_name:ei,gender:"",address:"",company:"","phone 2":"",facebook:"",whatsapp:"",job_title:"",avatar_url:""},user_info:RA(Pg)},{headers:{Authorization:`Bearer ${oA}`}}),localStorage.setItem("enduserUpdated","true")}catch(FA){console.error("Error updating end user info:",FA)}};let yA;return Pg&&Bi&&oA&&dg.length>0&&!localStorage.getItem("enduserUpdated")&&(yA=setTimeout(()=>{J()},5e3)),()=>clearTimeout(yA)},[Pg,t,dg,Bi]);const Uo=/^[\u0600-\u06FF\u0750-\u077F\s\d\p{P}]+$/u,qr=/[\u0600-\u06FF\u0750-\u077F]/,WI=J=>Uo.test(J),PI=J=>qr.test(J),mI=ee.useMemo(()=>({h1:({children:J})=>y.jsx("h1",{className:"sm:text-2xl text-xl font-bold my-2",dir:WI(J)?"rtl":"ltr",children:y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h2:({children:J})=>y.jsx("h2",{className:"sm:text-xl text-lg font-semibold my-2",dir:WI(J)?"rtl":"ltr",children:y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h3:({children:J})=>y.jsx("h3",{className:"sm:text-lg text-base font-semibold my-2",dir:WI(J)?"rtl":"ltr",children:y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h4:({children:J})=>y.jsx("h4",{className:"sm:text-base text-sm font-semibold my-2",dir:WI(J)?"rtl":"ltr",children:y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h5:({children:J})=>y.jsx("h5",{className:"sm:text-base text-sm font-semibold my-2",dir:WI(J)?"rtl":"ltr",children:y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),h6:({children:J})=>y.jsx("h6",{className:"sm:text-base text-sm font-semibold my-2",dir:WI(J)?"rtl":"ltr",children:y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})}),p:({children:J})=>{let yA;return typeof J=="string"&&PI(J)||typeof J=="object"&&!Array.isArray(J)&&J?.props?.children&&WI(J?.props?.children)||typeof J=="object"&&Array.isArray(J)&&J.some(FA=>PI(FA))?yA="rtl":yA="ltr",y.jsx("div",{className:"leading-relaxed",dir:typeof J=="string"||!Array.isArray(J)?yA:"",children:Array.isArray(J)?J.map((FA,ZA)=>{const Fe=PI(FA)?"p":"span";return typeof FA=="string"&&!new RegExp("^(?:\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F|\\s)+$","u").test(FA)?y.jsx(Fe,{dir:PI(FA)?"rtl":"ltr",children:y.jsx(JI,{sequence:[FA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:70})},ZA):FA?.type!=="br"?FA:null}):y.jsx(y.Fragment,{children:J})})},ul:({children:J})=>y.jsx("ul",{className:"list-disc list-inside ml-4 my-2",style:{color:q},dir:PI(J)?"rtl":"ltr",children:J}),ol:({children:J})=>{let yA=!1;return J.filter(FA=>typeof FA!="string").every(FA=>PI(FA?.props?.children))?yA=!0:yA=!1,y.jsx("ol",{className:"list-decimal list-inside ml-4 my-2",style:{color:q},dir:yA?"rtl":"ltr",children:typeof J=="string"?y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):J})},li:({children:J})=>y.jsx("li",{className:"my-1",dir:WI(J)?"rtl":"ltr",style:{color:q},children:typeof J=="string"?y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):J}),a:({href:J,children:yA})=>y.jsx("a",{href:J,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:typeof yA=="string"?y.jsx(JI,{sequence:[yA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):yA}),blockquote:({children:J})=>y.jsx("blockquote",{className:"border-l-4 pl-4 italic my-2",style:{borderColor:T,color:q},children:typeof J=="string"?y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):J}),code({node:J,className:yA,children:FA,...ZA}){const Fe=/language-(\w+)/.exec(yA||"");return Fe?y.jsx(qf,{...ZA,PreTag:"div",children:String(FA).replace(/\n$/,""),language:Fe[1],style:yaA,customStyle:{scrollbarWidth:"thin"}}):y.jsx("code",{className:"px-1 rounded font-mono inline",style:{backgroundColor:l,color:q},...ZA,children:typeof FA=="string"?y.jsx(JI,{sequence:[FA,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):FA})},table:({children:J})=>y.jsx("table",{className:"min-w-full my-2",style:{border:`1px solid ${q}`,color:b,backgroundColor:q},children:J}),thead:({children:J})=>y.jsx("thead",{children:J}),tbody:({children:J})=>y.jsx("tbody",{children:J}),tr:({children:J})=>y.jsx("tr",{style:{border:`1px solid ${b}`},children:J}),th:({children:J})=>y.jsx("th",{className:"px-3 py-2 font-bold text-left",children:J}),td:({children:J})=>y.jsx("td",{className:"px-3 py-2",children:typeof J=="string"?y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):J}),strong:({children:J})=>y.jsx("strong",{className:"font-bold",children:typeof J=="string"?y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):J}),em:({children:J})=>y.jsx("em",{className:"italic ",children:typeof J=="string"?y.jsx(JI,{sequence:[J,0,()=>{A.current&&(A.current.scrollTop=A.current.scrollHeight)}],cursor:!1,speed:92}):J}),hr:()=>y.jsx("hr",{className:"my-4",style:{borderColor:`1px solid ${q}`}})}),[G,q,T,l,F]);ee.useEffect(()=>{const J=yA=>{ve&&yA.target instanceof Element&&!yA.composedPath().some(FA=>FA?.id==="upload-button-toggle"||FA?.id==="document-button"||FA?.id==="image-button"||FA?.id==="video-button"||FA?.id==="audio-button")&&lg(!1)};return document.addEventListener("mousedown",J),()=>{document.removeEventListener("mousedown",J)}},[ve]);const JC=J=>{switch(J.type){case"text":if(Array.isArray(J.text))switch(J.text[0].type){case"products":return y.jsx(_M,{products:J.text[0].items||[],onValidate:FA=>{Li("cart",FA)},agentChatResponseColor:q,agentChatResponseBgColor:b,buttonsBgColor:T,buttonColor:X,chatRoundness:F,panelWidth:mA});case"easyspaceform":return y.jsx(vf,{onValidate:FA=>{Li("easyspace-form-data",FA)},agentChatResponseColor:q,agentChatResponseBgColor:b,buttonsBgColor:T,buttonColor:X,chatRoundness:F,panelWidth:mA,inputBackgroundColor:l});default:return y.jsx(Xo,{remarkPlugins:[_o],components:mI,children:J.text?.replace(/\n/g,`
601
601
  `)})}else try{const FA=typeof J.text=="string"?JSON.parse(J.text):J.text;switch(FA.type.toLowerCase()){case"products":return y.jsx(_M,{products:FA[0].items||[],onValidate:ZA=>{Li("cart",ZA)},agentChatResponseColor:q,agentChatResponseBgColor:b,buttonsBgColor:T,buttonColor:X,chatRoundness:F,panelWidth:mA});case"easyspaceform":return y.jsx(vf,{onValidate:ZA=>{Li("formulaire soumis",ZA)},agentChatResponseColor:q,agentChatResponseBgColor:b,buttonsBgColor:T,buttonColor:X,chatRoundness:F,panelWidth:mA,inputBackgroundColor:l});case"evform":return y.jsx(LwA,{onValidate:ZA=>{Li("formulaire soumis",ZA)},agentChatResponseColor:q,agentChatResponseBgColor:b,buttonsBgColor:T,buttonColor:X,chatRoundness:F,panelWidth:mA,inputBackgroundColor:l,mainColor:$});case"evform-visiteur":return y.jsx(TwA,{onValidate:ZA=>{Li("formulaire soumis",ZA)},agentChatResponseColor:q,agentChatResponseBgColor:b,buttonsBgColor:T,buttonColor:X,chatRoundness:F,panelWidth:mA,inputBackgroundColor:l,mainColor:$});default:return y.jsx(Xo,{remarkPlugins:[_o],components:mI,children:J.text?.replace(/\n/g,`
602
602
  `)})}}catch{return y.jsx(Xo,{remarkPlugins:[_o],components:mI,children:J.text?.replace(/\n/g,`
603
603
  `)})}case"single-choice":return y.jsxs(y.Fragment,{children:[y.jsx(Xo,{remarkPlugins:[_o],components:mI,children:J.text?.replace(/\n/g,`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tybotflow-widget",
3
- "version": "0.5.9",
3
+ "version": "0.6.0",
4
4
  "description": "A modern, customizable React widget for Tybot chat integration.",
5
5
  "license": "ISC",
6
6
  "main": "dist/index.umd.js",