const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/App-BTeV51qh-1792626966883.js","assets/mui-Dq3hqovr-1792626966883.js","assets/vendor-DUn0I1aZ-1792626966883.js"])))=>i.map(i=>d[i]); var Le=Object.defineProperty,Pe=Object.defineProperties;var Ie=Object.getOwnPropertyDescriptors;var ce=Object.getOwnPropertySymbols;var qe=Object.prototype.hasOwnProperty,Ue=Object.prototype.propertyIsEnumerable;var z=(r,e,t)=>e in r?Le(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,$=(r,e)=>{for(var t in e||(e={}))qe.call(e,t)&&z(r,t,e[t]);if(ce)for(var t of ce(e))Ue.call(e,t)&&z(r,t,e[t]);return r},W=(r,e)=>Pe(r,Ie(e));var H=(r,e,t)=>z(r,typeof e!="symbol"?e+"":e,t);var w=(r,e,t)=>new Promise((s,n)=>{var i=c=>{try{a(t.next(c))}catch(g){n(g)}},o=c=>{try{a(t.throw(c))}catch(g){n(g)}},a=c=>c.done?s(c.value):Promise.resolve(c.value).then(i,o);a((t=t.apply(r,e)).next())});import{j as l,B as X,E as je,T as F,a as he,R as Me,C as Ve,b as ze,c as $e,A as le,d as We,e as He,f as Ke,g as Je}from"./mui-Dq3hqovr-1792626966883.js";import{c as Ye,r as p,a as Xe,B as Qe}from"./vendor-DUn0I1aZ-1792626966883.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))s(n);new MutationObserver(n=>{for(const i of n)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&s(o)}).observe(document,{childList:!0,subtree:!0});function t(n){const i={};return n.integrity&&(i.integrity=n.integrity),n.referrerPolicy&&(i.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?i.credentials="include":n.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function s(n){if(n.ep)return;n.ep=!0;const i=t(n);fetch(n.href,i)}})();const Ge="modulepreload",Ze=function(r){return"/"+r},ue={},et=function(e,t,s){let n=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const o=document.querySelector("meta[property=csp-nonce]"),a=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));n=Promise.allSettled(t.map(c=>{if(c=Ze(c),c in ue)return;ue[c]=!0;const g=c.endsWith(".css"),_=g?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${c}"]${_}`))return;const m=document.createElement("link");if(m.rel=g?"stylesheet":Ge,g||(m.as="script"),m.crossOrigin="",m.href=c,a&&m.setAttribute("nonce",a),document.head.appendChild(m),g)return new Promise((k,B)=>{m.addEventListener("load",k),m.addEventListener("error",()=>B(new Error(`Unable to preload CSS for ${c}`)))})}))}function i(o){const a=new Event("vite:preloadError",{cancelable:!0});if(a.payload=o,window.dispatchEvent(a),!a.defaultPrevented)throw o}return n.then(o=>{for(const a of o||[])a.status==="rejected"&&i(a.reason);return e().catch(i)})};var Q={},fe=Ye;Q.createRoot=fe.createRoot,Q.hydrateRoot=fe.hydrateRoot;class tt extends p.Component{constructor(t){super(t);H(this,"handleRetry",()=>{this.setState({hasError:!1,error:null,errorInfo:null}),window.location.reload()});H(this,"toggleDetails",()=>{this.setState(t=>({showDetails:!t.showDetails}))});this.state={hasError:!1,error:null,errorInfo:null,showDetails:!1}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,s){console.error("ErrorBoundary caught an error:",t,s),this.setState({error:t,errorInfo:s})}render(){var t;return this.state.hasError?l.jsxs(X,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"100vh",background:"linear-gradient(135deg, #0F172A 0%, #1E293B 100%)",color:"white",p:3},children:[l.jsx(je,{sx:{fontSize:80,color:"#EF4444",mb:3}}),l.jsx(F,{variant:"h4",sx:{fontWeight:700,mb:2,textAlign:"center"},children:"Something went wrong"}),l.jsx(F,{variant:"body1",sx:{color:"rgba(255, 255, 255, 0.7)",mb:4,textAlign:"center",maxWidth:500},children:"We encountered an unexpected error. Please try refreshing the page or contact support if the problem persists."}),l.jsx(he,{variant:"contained",startIcon:l.jsx(Me,{}),onClick:this.handleRetry,sx:{background:"linear-gradient(135deg, #0EA5E9 0%, #8B5CF6 100%)",color:"white",px:4,py:1.5,borderRadius:"30px",fontWeight:600,mb:3,"&:hover":{transform:"translateY(-2px)",boxShadow:"0 8px 25px rgba(14, 165, 233, 0.4)"},transition:"all 0.3s"},children:"Refresh Page"}),l.jsxs(he,{variant:"text",onClick:this.toggleDetails,endIcon:this.state.showDetails?l.jsx(Ve,{}):l.jsx(ze,{}),sx:{color:"rgba(255, 255, 255, 0.5)","&:hover":{color:"rgba(255, 255, 255, 0.8)"}},children:[this.state.showDetails?"Hide":"Show"," Error Details"]}),l.jsx($e,{in:this.state.showDetails,children:l.jsxs(X,{sx:{mt:3,maxWidth:800,width:"100%"},children:[l.jsx(le,{severity:"error",sx:{mb:2},children:l.jsx(F,{variant:"body2",sx:{fontFamily:"monospace",fontSize:"0.85rem"},children:(t=this.state.error)==null?void 0:t.toString()})}),this.state.errorInfo&&l.jsx(le,{severity:"info",sx:{mb:2},children:l.jsx(F,{variant:"body2",sx:{fontFamily:"monospace",fontSize:"0.85rem",whiteSpace:"pre-wrap"},children:this.state.errorInfo.componentStack})})]})})]}):this.props.children}}const st=({message:r="Loading..."})=>l.jsxs(X,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"100vh",background:"linear-gradient(135deg, #0F172A 0%, #1E293B 100%)",color:"white"},children:[l.jsx(We,{size:60,thickness:4,sx:{color:"#0EA5E9",mb:3}}),l.jsx(F,{variant:"body1",sx:{color:"rgba(255, 255, 255, 0.8)",fontSize:"1.1rem",fontWeight:500},children:r})]}),rt={primary:{main:"#7DD3FC",light:"#BAE6FD",dark:"#38BDF8",contrastText:"#1E293B"},secondary:{main:"#C4B5FD",light:"#DDD6FE",dark:"#A78BFA",contrastText:"#1E293B"},background:{default:"#F0F9FF",paper:"#FFFFFF",dark:"#E0F2FE"},text:{primary:"#0F172A",secondary:"#334155",disabled:"#64748B"},success:{main:"#34D399",light:"#6EE7B7",dark:"#10B981"},error:{main:"#F87171",light:"#FCA5A5",dark:"#EF4444"},warning:{main:"#FBBF24",light:"#FDE68A",dark:"#F59E0B"},info:{main:"#60A5FA",light:"#93C5FD",dark:"#3B82F6"},gradients:{primary:"linear-gradient(135deg, #7DD3FC 0%, #38BDF8 100%)",secondary:"linear-gradient(135deg, #C4B5FD 0%, #A78BFA 100%)",accent:"linear-gradient(135deg, #FBBF24 0%, #F59E0B 100%)",subtle:"linear-gradient(135deg, #F0F9FF 0%, #E0F2FE 100%)",dark:"linear-gradient(135deg, #7DD3FC 0%, #C4B5FD 100%)"},shadows:{sm:"0 1px 2px 0 rgba(14, 165, 233, 0.08)",md:"0 4px 6px -1px rgba(14, 165, 233, 0.12)",lg:"0 10px 15px -3px rgba(14, 165, 233, 0.15)",xl:"0 20px 25px -5px rgba(14, 165, 233, 0.18)",glow:"0 0 30px rgba(125, 211, 252, 0.4)"},borderRadius:{sm:"6px",md:"10px",lg:"14px",xl:"20px",full:"9999px"},transitions:{fast:"150ms",normal:"300ms",slow:"500ms"}},nt={primary:{main:"#38BDF8",light:"#7DD3FC",dark:"#0EA5E9",contrastText:"#FFFFFF"},secondary:{main:"#A78BFA",light:"#C4B5FD",dark:"#8B5CF6",contrastText:"#FFFFFF"},background:{default:"#0F172A",paper:"#1E293B",dark:"#334155"},text:{primary:"#F1F5F9",secondary:"#E2E8F0",disabled:"#94A3B8"},success:{main:"#10B981",light:"#34D399",dark:"#059669"},error:{main:"#EF4444",light:"#F87171",dark:"#DC2626"},warning:{main:"#F59E0B",light:"#FBBF24",dark:"#D97706"},info:{main:"#3B82F6",light:"#60A5FA",dark:"#2563EB"},gradients:{primary:"linear-gradient(135deg, #38BDF8 0%, #0EA5E9 100%)",secondary:"linear-gradient(135deg, #A78BFA 0%, #8B5CF6 100%)",accent:"linear-gradient(135deg, #F59E0B 0%, #D97706 100%)",subtle:"linear-gradient(135deg, #0F172A 0%, #1E293B 100%)",dark:"linear-gradient(135deg, #38BDF8 0%, #A78BFA 100%)"},shadows:{sm:"0 1px 2px 0 rgba(0, 0, 0, 0.3)",md:"0 4px 6px -1px rgba(0, 0, 0, 0.4)",lg:"0 10px 15px -3px rgba(0, 0, 0, 0.5)",xl:"0 20px 25px -5px rgba(0, 0, 0, 0.6)",glow:"0 0 30px rgba(56, 189, 248, 0.3)"},borderRadius:{sm:"6px",md:"10px",lg:"14px",xl:"20px",full:"9999px"},transitions:{fast:"150ms",normal:"300ms",slow:"500ms"}},_e=p.createContext(),it=()=>{const r=p.useContext(_e);if(!r)throw new Error("useTheme must be used within a ThemeProvider");return r},ot=({children:r})=>{const[e,t]=p.useState(()=>{const i=localStorage.getItem("meshai_theme");return i?i==="dark":!1}),s=()=>{t(i=>{const o=!i;return localStorage.setItem("meshai_theme",o?"dark":"light"),o})},n=e?nt:rt;return p.useEffect(()=>{document.documentElement.setAttribute("data-theme",e?"dark":"light")},[e]),l.jsx(_e.Provider,{value:{theme:n,isDarkMode:e,toggleTheme:s},children:r})},A=window.location.origin+"/api";class at{constructor(){this.sessionData=null,this.sessionCheckInterval=null}initialize(){return w(this,null,function*(){try{const e=localStorage.getItem("token"),t=localStorage.getItem("user");if(e&&t){const s=JSON.parse(t);return this.sessionData={token:e,user:s,authenticated:!0,username:s.username,role:s.role},this.startSessionCheck(),this.sessionData}return null}catch(e){return console.error("Session initialization failed:",e),null}})}login(e,t){return w(this,null,function*(){try{console.log("login: Sending request to",`${A}/auth/login`);const s=yield fetch(`${A}/auth/login`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,password:t})});if(console.log("login: Response status:",s.status),s.ok){const i=yield s.json();console.log("login: Response data:",i);const o=i.user||{username:i.username,role:i.role,email:i.email,tier:i.tier||"Free Trial",created_at:i.created_at};return this.sessionData={token:i.token,user:o,session_id:i.session_id,username:i.username,role:i.role,authenticated:!0},localStorage.setItem("token",i.token),localStorage.setItem("user",JSON.stringify(o)),this.startSessionCheck(),{success:!0,data:i}}const n=yield s.json();return console.error("login: Error response:",n),{success:!1,error:n.detail||n.message||"Invalid credentials"}}catch(s){return console.error("Login failed:",s),{success:!1,error:"Network error"}}})}register(e){return w(this,null,function*(){try{console.log("register: Sending request to",`${A}/auth/register`);const t=yield fetch(`${A}/auth/register`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(console.log("register: Response status:",t.status),t.ok){const n=yield t.json();console.log("register: Response data:",n);const i=n.user||{username:n.username,role:n.role,email:n.email,tier:n.tier||"Free Trial",created_at:n.created_at};return this.sessionData={token:n.token,user:i,session_id:n.session_id,username:n.username,role:n.role,authenticated:!0},localStorage.setItem("token",n.token),localStorage.setItem("user",JSON.stringify(i)),this.startSessionCheck(),{success:!0,data:n}}const s=yield t.json();return console.error("register: Error response:",s),{success:!1,error:s.detail||s.message||"Registration failed"}}catch(t){return console.error("Registration failed:",t),{success:!1,error:"Network error"}}})}logout(){return w(this,null,function*(){try{return yield fetch(`${A}/auth/logout`,{method:"POST",credentials:"include"}),this.sessionData=null,this.stopSessionCheck(),localStorage.removeItem("token"),localStorage.removeItem("user"),localStorage.removeItem("meshai_admin_token"),localStorage.removeItem("meshai_admin_user"),{success:!0}}catch(e){return console.error("Logout failed:",e),this.sessionData=null,this.stopSessionCheck(),localStorage.removeItem("token"),localStorage.removeItem("user"),localStorage.removeItem("meshai_admin_token"),localStorage.removeItem("meshai_admin_user"),{success:!1,error:"Network error"}}})}getSession(){return this.sessionData}isAuthenticated(){return this.sessionData!==null}getUser(){var e;return((e=this.sessionData)==null?void 0:e.user)||null}getUserRole(){var e,t;return((t=(e=this.sessionData)==null?void 0:e.user)==null?void 0:t.role)||null}getApiToken(){var e;return((e=this.sessionData)==null?void 0:e.token)||null}authenticatedRequest(s){return w(this,arguments,function*(e,t={}){var i;const n=W($({},t.headers),{"Content-Type":"application/json"});(i=this.sessionData)!=null&&i.token&&(n["X-API-Key"]=this.sessionData.token);try{const o=yield fetch(e,W($({},t),{credentials:"include",headers:n}));return o.status===401?(this.sessionData=null,this.stopSessionCheck(),window.location.href="/auth",null):o}catch(o){throw console.error("Authenticated request failed:",o),o}})}startSessionCheck(){}stopSessionCheck(){this.sessionCheckInterval&&(clearInterval(this.sessionCheckInterval),this.sessionCheckInterval=null)}savePreferences(e){return w(this,null,function*(){try{const t=yield this.authenticatedRequest(`${A}/api/user/preferences`,{method:"PUT",body:JSON.stringify(e)});return t&&t.ok?{success:!0}:{success:!1,error:"Failed to save preferences"}}catch(t){return console.error("Failed to save preferences:",t),{success:!1,error:"Network error"}}})}getPreferences(){return w(this,null,function*(){try{const e=yield this.authenticatedRequest(`${A}/user/preferences`,{method:"GET"});return e&&e.ok?{success:!0,data:yield e.json()}:{success:!1,error:"Failed to get preferences"}}catch(e){return console.error("Failed to get preferences:",e),{success:!1,error:"Network error"}}})}}const C=new at,ct=p.createContext(null),ht=({children:r})=>{const[e,t]=p.useState(null),[s,n]=p.useState(!1),[i,o]=p.useState(!0),[a,c]=p.useState(!1);p.useEffect(()=>{w(void 0,null,function*(){try{console.log("SessionContext: Initializing session...");const u=yield C.initialize();u&&u.authenticated?(console.log("SessionContext: Session authenticated",u.user),t(u.user),n(!0)):(console.log("SessionContext: No active session"),t(null),n(!1)),c(!0),o(!1)}catch(u){console.error("SessionContext: Initialization failed",u),t(null),n(!1),c(!0),o(!1)}})},[]);const g=p.useCallback((d,u)=>w(void 0,null,function*(){try{console.log("SessionContext: Logging in user:",d);const f=yield C.login(d,u);if(f.success){const S=C.getSession();S&&(t(S.user),n(!0),console.log("SessionContext: Login successful",S.user))}return f}catch(f){return console.error("SessionContext: Login failed",f),{success:!1,error:"Login failed"}}}),[]),_=p.useCallback(()=>w(void 0,null,function*(){try{return console.log("SessionContext: Logging out user"),yield C.logout(),t(null),n(!1),console.log("SessionContext: Logout successful"),{success:!0}}catch(d){return console.error("SessionContext: Logout failed",d),{success:!1,error:"Logout failed"}}}),[]),m=p.useCallback(d=>w(void 0,null,function*(){try{console.log("SessionContext: Registering user:",d.username);const u=yield C.register(d);if(u.success){const f=C.getSession();f&&(t(f.user),n(!0),console.log("SessionContext: Registration successful",f.user))}return u}catch(u){return console.error("SessionContext: Registration failed",u),{success:!1,error:"Registration failed"}}}),[]),k=p.useCallback(()=>w(void 0,null,function*(){try{console.log("SessionContext: Refreshing session");const d=yield C.initialize();return d&&d.authenticated?(t(d.user),n(!0)):(t(null),n(!1)),d}catch(d){return console.error("SessionContext: Refresh failed",d),null}}),[]),B={user:e,isAuthenticated:s,isLoading:i,sessionInitialized:a,login:g,logout:_,register:m,refreshSession:k,sessionManager:C};return l.jsx(ct.Provider,{value:B,children:r})},x=Object.create(null);x.open="0";x.close="1";x.ping="2";x.pong="3";x.message="4";x.upgrade="5";x.noop="6";const P=Object.create(null);Object.keys(x).forEach(r=>{P[x[r]]=r});const G={type:"error",data:"parser error"},we=typeof Blob=="function"||typeof Blob!="undefined"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",be=typeof ArrayBuffer=="function",Ee=r=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(r):r&&r.buffer instanceof ArrayBuffer,re=({type:r,data:e},t,s)=>we&&e instanceof Blob?t?s(e):de(e,s):be&&(e instanceof ArrayBuffer||Ee(e))?t?s(e):de(new Blob([e]),s):s(x[r]+(e||"")),de=(r,e)=>{const t=new FileReader;return t.onload=function(){const s=t.result.split(",")[1];e("b"+(s||""))},t.readAsDataURL(r)};function pe(r){return r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}let K;function lt(r,e){if(we&&r.data instanceof Blob)return r.data.arrayBuffer().then(pe).then(e);if(be&&(r.data instanceof ArrayBuffer||Ee(r.data)))return e(pe(r.data));re(r,!1,t=>{K||(K=new TextEncoder),e(K.encode(t))})}const ge="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",N=typeof Uint8Array=="undefined"?[]:new Uint8Array(256);for(let r=0;r{let e=r.length*.75,t=r.length,s,n=0,i,o,a,c;r[r.length-1]==="="&&(e--,r[r.length-2]==="="&&e--);const g=new ArrayBuffer(e),_=new Uint8Array(g);for(s=0;s>4,_[n++]=(o&15)<<4|a>>2,_[n++]=(a&3)<<6|c&63;return g},ft=typeof ArrayBuffer=="function",ne=(r,e)=>{if(typeof r!="string")return{type:"message",data:ke(r,e)};const t=r.charAt(0);return t==="b"?{type:"message",data:dt(r.substring(1),e)}:P[t]?r.length>1?{type:P[t],data:r.substring(1)}:{type:P[t]}:G},dt=(r,e)=>{if(ft){const t=ut(r);return ke(t,e)}else return{base64:!0,data:r}},ke=(r,e)=>{switch(e){case"blob":return r instanceof Blob?r:new Blob([r]);case"arraybuffer":default:return r instanceof ArrayBuffer?r:r.buffer}},ve="",pt=(r,e)=>{const t=r.length,s=new Array(t);let n=0;r.forEach((i,o)=>{re(i,!1,a=>{s[o]=a,++n===t&&e(s.join(ve))})})},gt=(r,e)=>{const t=r.split(ve),s=[];for(let n=0;n{const s=t.length;let n;if(s<126)n=new Uint8Array(1),new DataView(n.buffer).setUint8(0,s);else if(s<65536){n=new Uint8Array(3);const i=new DataView(n.buffer);i.setUint8(0,126),i.setUint16(1,s)}else{n=new Uint8Array(9);const i=new DataView(n.buffer);i.setUint8(0,127),i.setBigUint64(1,BigInt(s))}r.data&&typeof r.data!="string"&&(n[0]|=128),e.enqueue(n),e.enqueue(t)})}})}let J;function D(r){return r.reduce((e,t)=>e+t.length,0)}function L(r,e){if(r[0].length===e)return r.shift();const t=new Uint8Array(e);let s=0;for(let n=0;nMath.pow(2,21)-1){a.enqueue(G);break}n=_*Math.pow(2,32)+g.getUint32(4),s=3}else{if(D(t)r){a.enqueue(G);break}}}})}const xe=4;function y(r){if(r)return _t(r)}function _t(r){for(var e in y.prototype)r[e]=y.prototype[e];return r}y.prototype.on=y.prototype.addEventListener=function(r,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+r]=this._callbacks["$"+r]||[]).push(e),this};y.prototype.once=function(r,e){function t(){this.off(r,t),e.apply(this,arguments)}return t.fn=e,this.on(r,t),this};y.prototype.off=y.prototype.removeListener=y.prototype.removeAllListeners=y.prototype.removeEventListener=function(r,e){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var t=this._callbacks["$"+r];if(!t)return this;if(arguments.length==1)return delete this._callbacks["$"+r],this;for(var s,n=0;nPromise.resolve().then(e):(e,t)=>t(e,0),b=typeof self!="undefined"?self:typeof window!="undefined"?window:Function("return this")(),wt="arraybuffer";function Se(r,...e){return e.reduce((t,s)=>(r.hasOwnProperty(s)&&(t[s]=r[s]),t),{})}const bt=b.setTimeout,Et=b.clearTimeout;function V(r,e){e.useNativeTimers?(r.setTimeoutFn=bt.bind(b),r.clearTimeoutFn=Et.bind(b)):(r.setTimeoutFn=b.setTimeout.bind(b),r.clearTimeoutFn=b.clearTimeout.bind(b))}const kt=1.33;function vt(r){return typeof r=="string"?xt(r):Math.ceil((r.byteLength||r.size)*kt)}function xt(r){let e=0,t=0;for(let s=0,n=r.length;s=57344?t+=3:(s++,t+=4);return t}function Ce(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function St(r){let e="";for(let t in r)r.hasOwnProperty(t)&&(e.length&&(e+="&"),e+=encodeURIComponent(t)+"="+encodeURIComponent(r[t]));return e}function Ct(r){let e={},t=r.split("&");for(let s=0,n=t.length;s{this.readyState="paused",e()};if(this._polling||!this.writable){let s=0;this._polling&&(s++,this.once("pollComplete",function(){--s||t()})),this.writable||(s++,this.once("drain",function(){--s||t()}))}else t()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){const t=s=>{if(this.readyState==="opening"&&s.type==="open"&&this.onOpen(),s.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(s)};gt(e,this.socket.binaryType).forEach(t),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){const e=()=>{this.write([{type:"close"}])};this.readyState==="open"?e():this.once("open",e)}write(e){this.writable=!1,pt(e,t=>{this.doWrite(t,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const e=this.opts.secure?"https":"http",t=this.query||{};return this.opts.timestampRequests!==!1&&(t[this.opts.timestampParam]=Ce()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}}let Ae=!1;try{Ae=typeof XMLHttpRequest!="undefined"&&"withCredentials"in new XMLHttpRequest}catch(r){}const Rt=Ae;function Bt(){}class Ot extends Tt{constructor(e){if(super(e),typeof location!="undefined"){const t=location.protocol==="https:";let s=location.port;s||(s=t?"443":"80"),this.xd=typeof location!="undefined"&&e.hostname!==location.hostname||s!==e.port}}doWrite(e,t){const s=this.request({method:"POST",data:e});s.on("success",t),s.on("error",(n,i)=>{this.onError("xhr post error",n,i)})}doPoll(){const e=this.request();e.on("data",this.onData.bind(this)),e.on("error",(t,s)=>{this.onError("xhr poll error",t,s)}),this.pollXhr=e}}class v extends y{constructor(e,t,s){super(),this.createRequest=e,V(this,s),this._opts=s,this._method=s.method||"GET",this._uri=t,this._data=s.data!==void 0?s.data:null,this._create()}_create(){var e;const t=Se(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this._opts.xd;const s=this._xhr=this.createRequest(t);try{s.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){s.setDisableHeaderCheck&&s.setDisableHeaderCheck(!0);for(let n in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(n)&&s.setRequestHeader(n,this._opts.extraHeaders[n])}}catch(n){}if(this._method==="POST")try{s.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(n){}try{s.setRequestHeader("Accept","*/*")}catch(n){}(e=this._opts.cookieJar)===null||e===void 0||e.addCookies(s),"withCredentials"in s&&(s.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(s.timeout=this._opts.requestTimeout),s.onreadystatechange=()=>{var n;s.readyState===3&&((n=this._opts.cookieJar)===null||n===void 0||n.parseCookies(s.getResponseHeader("set-cookie"))),s.readyState===4&&(s.status===200||s.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof s.status=="number"?s.status:0)},0))},s.send(this._data)}catch(n){this.setTimeoutFn(()=>{this._onError(n)},0);return}typeof document!="undefined"&&(this._index=v.requestsCount++,v.requests[this._index]=this)}_onError(e){this.emitReserved("error",e,this._xhr),this._cleanup(!0)}_cleanup(e){if(!(typeof this._xhr=="undefined"||this._xhr===null)){if(this._xhr.onreadystatechange=Bt,e)try{this._xhr.abort()}catch(t){}typeof document!="undefined"&&delete v.requests[this._index],this._xhr=null}}_onLoad(){const e=this._xhr.responseText;e!==null&&(this.emitReserved("data",e),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}v.requestsCount=0;v.requests={};if(typeof document!="undefined"){if(typeof attachEvent=="function")attachEvent("onunload",me);else if(typeof addEventListener=="function"){const r="onpagehide"in b?"pagehide":"unload";addEventListener(r,me,!1)}}function me(){for(let r in v.requests)v.requests.hasOwnProperty(r)&&v.requests[r].abort()}const Ft=function(){const r=Te({xdomain:!1});return r&&r.responseType!==null}();class Nt extends Ot{constructor(e){super(e);const t=e&&e.forceBase64;this.supportsBinary=Ft&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new v(Te,this.uri(),e)}}function Te(r){const e=r.xdomain;try{if(typeof XMLHttpRequest!="undefined"&&(!e||Rt))return new XMLHttpRequest}catch(t){}if(!e)try{return new b[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch(t){}}const Re=typeof navigator!="undefined"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class Dt extends ie{get name(){return"websocket"}doOpen(){const e=this.uri(),t=this.opts.protocols,s=Re?{}:Se(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(s.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(e,t,s)}catch(n){return this.emitReserved("error",n)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let t=0;t{try{this.doWrite(s,i)}catch(o){}n&&M(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws!="undefined"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const e=this.opts.secure?"wss":"ws",t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=Ce()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}}const Y=b.WebSocket||b.MozWebSocket;class Lt extends Dt{createSocket(e,t,s){return Re?new Y(e,t,s):t?new Y(e,t):new Y(e)}doWrite(e,t){this.ws.send(t)}}class Pt extends ie{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(e){return this.emitReserved("error",e)}this._transport.closed.then(()=>{this.onClose()}).catch(e=>{this.onError("webtransport error",e)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(e=>{const t=yt(Number.MAX_SAFE_INTEGER,this.socket.binaryType),s=e.readable.pipeThrough(t).getReader(),n=mt();n.readable.pipeTo(e.writable),this._writer=n.writable.getWriter();const i=()=>{s.read().then(({done:a,value:c})=>{a||(this.onPacket(c),i())}).catch(a=>{})};i();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this._writer.write(o).then(()=>this.onOpen())})})}write(e){this.writable=!1;for(let t=0;t{n&&M(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;(e=this._transport)===null||e===void 0||e.close()}}const It={websocket:Lt,webtransport:Pt,polling:Nt},qt=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Ut=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function Z(r){if(r.length>8e3)throw"URI too long";const e=r,t=r.indexOf("["),s=r.indexOf("]");t!=-1&&s!=-1&&(r=r.substring(0,t)+r.substring(t,s).replace(/:/g,";")+r.substring(s,r.length));let n=qt.exec(r||""),i={},o=14;for(;o--;)i[Ut[o]]=n[o]||"";return t!=-1&&s!=-1&&(i.source=e,i.host=i.host.substring(1,i.host.length-1).replace(/;/g,":"),i.authority=i.authority.replace("[","").replace("]","").replace(/;/g,":"),i.ipv6uri=!0),i.pathNames=jt(i,i.path),i.queryKey=Mt(i,i.query),i}function jt(r,e){const t=/\/{2,9}/g,s=e.replace(t,"/").split("/");return(e.slice(0,1)=="/"||e.length===0)&&s.splice(0,1),e.slice(-1)=="/"&&s.splice(s.length-1,1),s}function Mt(r,e){const t={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(s,n,i){n&&(t[n]=i)}),t}const ee=typeof addEventListener=="function"&&typeof removeEventListener=="function",I=[];ee&&addEventListener("offline",()=>{I.forEach(r=>r())},!1);let Be=class T extends y{constructor(e,t={}){var s,n;if(super(),this.binaryType=wt,this.writeBuffer=[],this._prevBufferLen=0,this._upgrades=[],this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,e&&typeof e=="object"&&(t=e,e=null),e){const i=Z(e);t.hostname=i.host,t.secure=i.protocol==="https"||i.protocol==="wss",t.port=i.port,i.query&&(t.query=i.query)}else t.host&&(t.hostname=Z(t.host).host);if(V(this,t),this.secure=t.secure!=null?t.secure:typeof location!="undefined"&&location.protocol==="https:",t.hostname&&!t.port&&(t.port=this.secure?"443":"80"),this.hostname=t.hostname||(typeof location!="undefined"?location.hostname:"localhost"),this.port=t.port||(typeof location!="undefined"&&location.port?location.port:this.secure?"443":"80"),t.transportImplementations&&t.transports)throw new Error("specifying both 'transportImplementations' and 'transports' options is not supported");t.transportImplementations||!((s=t.transports)===null||s===void 0)&&s.length&&typeof t.transports[0]=="function"?(this.transports=[],this._transportsByName=Object.create(null),((n=t.transportImplementations)!==null&&n!==void 0?n:t.transports).forEach(i=>{const o=i.prototype.name;this.transports.push(o),this._transportsByName[o]=i})):(this.transports=t.transports?[...t.transports]:["polling","websocket","webtransport"],this._transportsByName=It),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},t),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=Ct(this.opts.query)),ee&&(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"})},I.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(e){const t=Object.assign({},this.opts.query);t.EIO=xe,t.transport=e,this.id&&(t.sid=this.id);const s=Object.assign({},this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return new this._transportsByName[e](s)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}const e=this.opts.rememberUpgrade&&T.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";const t=this.createTransport(e);t.open(),this.setTransport(t)}setTransport(e){this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",t=>this._onClose("transport close",t))}_probe(e){let t=this.createTransport(e),s=!1;T.priorWebsocketSuccess=!1;const n=()=>{s||(t.send([{type:"ping",data:"probe"}]),t.once("packet",m=>{if(!s)if(m.type==="pong"&&m.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",t),!t)return;T.priorWebsocketSuccess=t.name==="websocket",this.transport.pause(()=>{s||this.readyState!=="closed"&&(_(),this.setTransport(t),t.send([{type:"upgrade"}]),this.emitReserved("upgrade",t),t=null,this.upgrading=!1,this.flush())})}else{const k=new Error("probe error");k.transport=t.name,this.emitReserved("upgradeError",k)}}))};function i(){s||(s=!0,_(),t.close(),t=null)}const o=m=>{const k=new Error("probe error: "+m);k.transport=t.name,i(),this.emitReserved("upgradeError",k)};function a(){o("transport closed")}function c(){o("socket closed")}function g(m){t&&m.name!==t.name&&i()}const _=()=>{t.removeListener("open",n),t.removeListener("error",o),t.removeListener("close",a),this.off("close",c),this.off("upgrading",g)};t.once("open",n),t.once("error",o),t.once("close",a),this.once("close",c),this.once("upgrading",g),this._upgrades.indexOf("webtransport")!==-1&&e!=="webtransport"?this.setTimeoutFn(()=>{s||t.open()},200):t.open()}onOpen(){if(this.readyState="open",T.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush(),this.readyState==="open"&&this.opts.upgrade)for(let e=0;e{this._onClose("ping timeout")},e),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 e=this._getWritablePackets();this.transport.send(e),this._prevBufferLen=e.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let s=0;s0&&t>this._maxPayload)return this.writeBuffer.slice(0,s);t+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const e=Date.now()>this._pingTimeoutTime;return e&&(this._pingTimeoutTime=0,M(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),e}write(e,t,s){return this._sendPacket("message",e,t,s),this}send(e,t,s){return this._sendPacket("message",e,t,s),this}_sendPacket(e,t,s,n){if(typeof t=="function"&&(n=t,t=void 0),typeof s=="function"&&(n=s,s=null),this.readyState==="closing"||this.readyState==="closed")return;s=s||{},s.compress=s.compress!==!1;const i={type:e,data:t,options:s};this.emitReserved("packetCreate",i),this.writeBuffer.push(i),n&&this.once("flush",n),this.flush()}close(){const e=()=>{this._onClose("forced close"),this.transport.close()},t=()=>{this.off("upgrade",t),this.off("upgradeError",t),e()},s=()=>{this.once("upgrade",t),this.once("upgradeError",t)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?s():e()}):this.upgrading?s():e()),this}_onError(e){if(T.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",e),this._onClose("transport error",e)}_onClose(e,t){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(),ee&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const s=I.indexOf(this._offlineEventListener);s!==-1&&I.splice(s,1)}this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this._prevBufferLen=0}}_filterUpgrades(e){const t=[];for(let s=0;stypeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(r):r.buffer instanceof ArrayBuffer,Oe=Object.prototype.toString,Wt=typeof Blob=="function"||typeof Blob!="undefined"&&Oe.call(Blob)==="[object BlobConstructor]",Ht=typeof File=="function"||typeof File!="undefined"&&Oe.call(File)==="[object FileConstructor]";function oe(r){return zt&&(r instanceof ArrayBuffer||$t(r))||Wt&&r instanceof Blob||Ht&&r instanceof File}function q(r,e){if(!r||typeof r!="object")return!1;if(Array.isArray(r)){for(let t=0,s=r.length;t=0&&r.numthis.opts.maxAttachments)throw new Error("too many attachments");s.attachments=a}if(e.charAt(t+1)==="/"){const i=t+1;for(;++t&&!(e.charAt(t)===","||t===e.length););s.nsp=e.substring(i,t)}else s.nsp="/";const n=e.charAt(t+1);if(n!==""&&Number(n)==n){const i=t+1;for(;++t;){const o=e.charAt(t);if(o==null||Number(o)!=o){--t;break}if(t===e.length)break}s.id=Number(e.substring(i,t+1))}if(e.charAt(++t)){const i=this.tryParse(e.substr(t));if(ae.isPayloadValid(s.type,i))s.data=i;else throw new Error("invalid payload")}return s}tryParse(e){try{return JSON.parse(e,this.opts.reviver)}catch(t){return!1}}static isPayloadValid(e,t){switch(e){case h.CONNECT:return ye(t);case h.DISCONNECT:return t===void 0;case h.CONNECT_ERROR:return typeof t=="string"||ye(t);case h.EVENT:case h.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]=="number"||typeof t[0]=="string"&&Yt.indexOf(t[0])===-1);case h.ACK:case h.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class Qt{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){const t=Jt(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const Gt=Number.isInteger||function(r){return typeof r=="number"&&isFinite(r)&&Math.floor(r)===r};function ye(r){return Object.prototype.toString.call(r)==="[object Object]"}const Zt=Object.freeze(Object.defineProperty({__proto__:null,Decoder:ae,Encoder:Xt,get PacketType(){return h}},Symbol.toStringTag,{value:"Module"}));function E(r,e,t){return r.on(e,t),function(){r.off(e,t)}}const es=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Fe extends y{constructor(e,t,s){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=e,this.nsp=t,s&&s.auth&&(this.auth=s.auth),this._opts=Object.assign({},s),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const e=this.io;this.subs=[E(e,"open",this.onopen.bind(this)),E(e,"packet",this.onpacket.bind(this)),E(e,"error",this.onerror.bind(this)),E(e,"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(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...t){var s,n,i;if(es.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(t.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(t),this;const o={type:h.EVENT,data:t};if(o.options={},o.options.compress=this.flags.compress!==!1,typeof t[t.length-1]=="function"){const _=this.ids++,m=t.pop();this._registerAckCallback(_,m),o.id=_}const a=(n=(s=this.io.engine)===null||s===void 0?void 0:s.transport)===null||n===void 0?void 0:n.writable,c=this.connected&&!(!((i=this.io.engine)===null||i===void 0)&&i._hasPingExpired());return this.flags.volatile&&!a||(c?(this.notifyOutgoingListeners(o),this.packet(o)):this.sendBuffer.push(o)),this.flags={},this}_registerAckCallback(e,t){var s;const n=(s=this.flags.timeout)!==null&&s!==void 0?s:this._opts.ackTimeout;if(n===void 0){this.acks[e]=t;return}const i=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let a=0;a{this.io.clearTimeoutFn(i),t.apply(this,a)};o.withError=!0,this.acks[e]=o}emitWithAck(e,...t){return new Promise((s,n)=>{const i=(o,a)=>o?n(o):s(a);i.withError=!0,t.push(i),this.emit(e,...t)})}_addToQueue(e){let t;typeof e[e.length-1]=="function"&&(t=e.pop());const s={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((n,...i)=>(this._queue[0],n!==null?s.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(n)):(this._queue.shift(),t&&t(null,...i)),s.pending=!1,this._drainQueue())),this._queue.push(s),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||this._queue.length===0)return;const t=this._queue[0];t.pending&&!e||(t.pending=!0,t.tryCount++,this.flags=t.flags,this.emit.apply(this,t.args))}packet(e){e.nsp=this.nsp,this.io._packet(e)}onopen(){typeof this.auth=="function"?this.auth(e=>{this._sendConnectPacket(e)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(e){this.packet({type:h.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e})}onerror(e){this.connected||this.emitReserved("connect_error",e)}onclose(e,t){this.connected=!1,delete this.id,this.emitReserved("disconnect",e,t),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(e=>{if(!this.sendBuffer.some(s=>String(s.id)===e)){const s=this.acks[e];delete this.acks[e],s.withError&&s.call(this,new Error("socket has been disconnected"))}})}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case h.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.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 h.EVENT:case h.BINARY_EVENT:this.onevent(e);break;case h.ACK:case h.BINARY_ACK:this.onack(e);break;case h.DISCONNECT:this.ondisconnect();break;case h.CONNECT_ERROR:this.destroy();const s=new Error(e.data.message);s.data=e.data.data,this.emitReserved("connect_error",s);break}}onevent(e){const t=e.data||[];e.id!=null&&t.push(this.ack(e.id)),this.connected?this.emitEvent(t):this.receiveBuffer.push(Object.freeze(t))}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){const t=this._anyListeners.slice();for(const s of t)s.apply(this,e)}super.emit.apply(this,e),this._pid&&e.length&&typeof e[e.length-1]=="string"&&(this._lastOffset=e[e.length-1])}ack(e){const t=this;let s=!1;return function(...n){s||(s=!0,t.packet({type:h.ACK,id:e,data:n}))}}onack(e){const t=this.acks[e.id];typeof t=="function"&&(delete this.acks[e.id],t.withError&&e.data.unshift(null),t.apply(this,e.data))}onconnect(e,t){this.id=e,this.recovered=t&&this._pid===t,this._pid=t,this.connected=!0,this.emitBuffered(),this._drainQueue(!0),this.emitReserved("connect")}emitBuffered(){this.receiveBuffer.forEach(e=>this.emitEvent(e)),this.receiveBuffer=[],this.sendBuffer.forEach(e=>{this.notifyOutgoingListeners(e),this.packet(e)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(e=>e()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:h.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){const t=this._anyListeners;for(let s=0;s0&&r.jitter<=1?r.jitter:0,this.attempts=0}R.prototype.duration=function(){var r=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),t=Math.floor(e*this.jitter*r);r=Math.floor(e*10)&1?r+t:r-t}return Math.min(r,this.max)|0};R.prototype.reset=function(){this.attempts=0};R.prototype.setMin=function(r){this.ms=r};R.prototype.setMax=function(r){this.max=r};R.prototype.setJitter=function(r){this.jitter=r};class se extends y{constructor(e,t){var s;super(),this.nsps={},this.subs=[],e&&typeof e=="object"&&(t=e,e=void 0),t=t||{},t.path=t.path||"/socket.io",this.opts=t,V(this,t),this.reconnection(t.reconnection!==!1),this.reconnectionAttempts(t.reconnectionAttempts||1/0),this.reconnectionDelay(t.reconnectionDelay||1e3),this.reconnectionDelayMax(t.reconnectionDelayMax||5e3),this.randomizationFactor((s=t.randomizationFactor)!==null&&s!==void 0?s:.5),this.backoff=new R({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(t.timeout==null?2e4:t.timeout),this._readyState="closed",this.uri=e;const n=t.parser||Zt;this.encoder=new n.Encoder,this.decoder=new n.Decoder,this._autoConnect=t.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(e){return arguments.length?(this._reconnection=!!e,e||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(e){return e===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var t;return e===void 0?this._reconnectionDelay:(this._reconnectionDelay=e,(t=this.backoff)===null||t===void 0||t.setMin(e),this)}randomizationFactor(e){var t;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(t=this.backoff)===null||t===void 0||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(t=this.backoff)===null||t===void 0||t.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(e){if(~this._readyState.indexOf("open"))return this;this.engine=new Be(this.uri,this.opts);const t=this.engine,s=this;this._readyState="opening",this.skipReconnect=!1;const n=E(t,"open",function(){s.onopen(),e&&e()}),i=a=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",a),e?e(a):this.maybeReconnectOnOpen()},o=E(t,"error",i);if(this._timeout!==!1){const a=this._timeout,c=this.setTimeoutFn(()=>{n(),i(new Error("timeout")),t.close()},a);this.opts.autoUnref&&c.unref(),this.subs.push(()=>{this.clearTimeoutFn(c)})}return this.subs.push(n),this.subs.push(o),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const e=this.engine;this.subs.push(E(e,"ping",this.onping.bind(this)),E(e,"data",this.ondata.bind(this)),E(e,"error",this.onerror.bind(this)),E(e,"close",this.onclose.bind(this)),E(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(e){try{this.decoder.add(e)}catch(t){this.onclose("parse error",t)}}ondecoded(e){M(()=>{this.emitReserved("packet",e)},this.setTimeoutFn)}onerror(e){this.emitReserved("error",e)}socket(e,t){let s=this.nsps[e];return s?this._autoConnect&&!s.active&&s.connect():(s=new Fe(this,e,t),this.nsps[e]=s),s}_destroy(e){const t=Object.keys(this.nsps);for(const s of t)if(this.nsps[s].active)return;this._close()}_packet(e){const t=this.encoder.encode(e);for(let s=0;se()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(e,t){var s;this.cleanup(),(s=this.engine)===null||s===void 0||s.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,t),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const t=this.backoff.duration();this._reconnecting=!0;const s=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved("reconnect_attempt",e.backoff.attempts),!e.skipReconnect&&e.open(n=>{n?(e._reconnecting=!1,e.reconnect(),this.emitReserved("reconnect_error",n)):e.onreconnect()}))},t);this.opts.autoUnref&&s.unref(),this.subs.push(()=>{this.clearTimeoutFn(s)})}}onreconnect(){const e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",e)}}const O={};function j(r,e){typeof r=="object"&&(e=r,r=void 0),e=e||{};const t=Vt(r,e.path||"/socket.io"),s=t.source,n=t.id,i=t.path,o=O[n]&&i in O[n].nsps,a=e.forceNew||e["force new connection"]||e.multiplex===!1||o;let c;return a?c=new se(s,e):(O[n]||(O[n]=new se(s,e)),c=O[n]),t.query&&!e.query&&(e.query=t.queryKey),c.socket(t.path,e)}Object.assign(j,{Manager:se,Socket:Fe,io:j,connect:j});const Ne=p.createContext(),as=()=>{const r=p.useContext(Ne);if(!r)throw new Error("useSocket must be used within a SocketProvider");return r},ts=({children:r})=>{const[e,t]=p.useState(null),[s,n]=p.useState(!1),[i,o]=p.useState([]),[a,c]=p.useState([]);p.useEffect(()=>{const d=window.location.origin,u=j(d,{transports:["websocket","polling"],reconnection:!0,reconnectionAttempts:5,reconnectionDelay:1e3});return u.on("connect",()=>{console.log("Socket.IO connected:",u.id),n(!0)}),u.on("disconnect",()=>{console.log("Socket.IO disconnected"),n(!1)}),u.on("message",f=>{console.log("New message:",f),c(S=>[...S,f])}),u.on("user_joined",f=>{console.log("User joined:",f.username),o(S=>[...S,f.username])}),u.on("user_left",f=>{console.log("User left:",f.username),o(S=>S.filter(De=>De!==f.username))}),u.on("online_users",f=>{console.log("Online users:",f.users),o(f.users)}),u.on("chat_history",f=>{console.log("Chat history loaded:",f.messages.length,"messages"),c(f.messages)}),u.on("user_typing",f=>{console.log("User typing:",f.username,f.typing)}),t(u),()=>{u.disconnect()}},[]);const B={socket:e,isConnected:s,onlineUsers:i,messages:a,joinRoom:(d,u="public")=>{e&&s&&e.emit("join",{username:d,room:u})},leaveRoom:(d="public")=>{e&&s&&e.emit("leave",{room:d})},sendMessage:(d,u="public")=>{e&&s&&e.emit("send_message",{content:d,room:u})},sendTyping:(d,u="public")=>{e&&s&&e.emit("typing",{typing:d,room:u})}};return l.jsx(Ne.Provider,{value:B,children:r})},ss=p.lazy(()=>et(()=>import("./App-BTeV51qh-1792626966883.js"),__vite__mapDeps([0,1,2]))),rs=({children:r})=>{const{isDarkMode:e}=it(),t=He({palette:{mode:e?"dark":"light"}});return l.jsxs(Ke,{theme:t,children:[l.jsx(Je,{}),r]})};window.addEventListener("error",r=>{console.error("Global error:",r.error)});window.addEventListener("unhandledrejection",r=>{console.error("Unhandled promise rejection:",r.reason)});Q.createRoot(document.getElementById("root")).render(l.jsx(Xe.StrictMode,{children:l.jsx(tt,{children:l.jsx(Qe,{children:l.jsx(ht,{children:l.jsx(ts,{children:l.jsx(ot,{children:l.jsx(rs,{children:l.jsx(p.Suspense,{fallback:l.jsx(st,{}),children:l.jsx(ss,{})})})})})})})})}));export{as as a,C as s,it as u};