@onedeskpro/chatbot-core 0.3.0 → 0.3.1

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.cjs CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r},n=3e4,r=12e4;function i(e){return typeof e==`object`&&!!e&&typeof e.message==`string`}function a(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.type==`string`&&typeof t.url==`string`&&typeof t.fileName==`string`&&typeof t.size==`number`}function o(e){return e instanceof Error&&`apiError`in e&&`status`in e&&typeof e.status==`number`&&i(e.apiError)}var s=class{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,``),this.apiKey=e.apiKey,this.timeoutMs=e.timeoutMs??3e4,this.uploadTimeoutMs=e.uploadTimeoutMs??r}fail(e,t,n,r){let i={statusCode:t,message:e,code:n,timestamp:new Date().toISOString(),path:r};throw Object.assign(Error(e),{apiError:i,status:t})}async request(e,t,n,r,a,o=this.timeoutMs){let s=new URL(`${this.baseUrl}${t}`);if(r)for(let[e,t]of Object.entries(r))s.searchParams.set(e,t);let c=typeof FormData<`u`&&n instanceof FormData,l={...c?{}:{"Content-Type":`application/json`},"X-API-Key":this.apiKey,...a},u=new AbortController,d=setTimeout(()=>u.abort(),o),f;try{f=await fetch(s.toString(),{method:e,headers:l,signal:u.signal,...n===void 0?{}:{body:c?n:JSON.stringify(n)}})}catch(e){u.signal.aborted&&this.fail(`Request timed out after ${o}ms.`,0,`TIMEOUT`,t),this.fail(e instanceof Error?e.message:`Network request failed.`,0,`NETWORK_ERROR`,t)}finally{clearTimeout(d)}let p=await f.text(),m=null;if(p)try{m=JSON.parse(p)}catch{m=null}if(!f.ok){if(i(m))throw Object.assign(Error(m.message),{apiError:m,status:f.status});this.fail(`Request failed with status ${f.status} ${f.statusText}`.trim(),f.status,`HTTP_ERROR`,t)}return m===null&&this.fail(`The server returned an empty or malformed response.`,f.status,`BAD_RESPONSE`,t),m.data}async identify(e){return this.request(`POST`,`/sdk/identify`,e)}async verifyVisitor(e){return this.request(`GET`,`/sdk/visitor`,void 0,void 0,{"X-Visitor-Token":e})}async sendMessage(e){return this.request(`POST`,`/sdk/chat`,e)}async uploadAttachment(e,t){let n=new FormData;n.append(`file`,e,e.name);let r=await this.request(`POST`,`/sdk/upload`,n,void 0,{"X-Visitor-Token":t},this.uploadTimeoutMs);return a(r)||this.fail(`The server returned an unexpected upload response.`,200,`BAD_RESPONSE`,`/sdk/upload`),r}async fetchConfig(){return this.request(`GET`,`/sdk/config`)}async requestHuman(e){return this.request(`POST`,`/sdk/human-request`,{visitorToken:e})}async fetchTicketStatus(e){return this.request(`GET`,`/sdk/ticket-status`,void 0,void 0,{"X-Visitor-Token":e})}},c=`https://api.onedeskpro.com`,l=10485760,u=10;function d(e){if(e.length>10)return`You can send up to 10 files at a time.`;let t=e.find(e=>e.size>l);if(t){let e=Math.round(l/1048576);return`"${t.name||`This file`}" is larger than ${e} MB.`}return null}function f(e){return/^(https?:\/\/|blob:)/i.test(e)}function p(e){return typeof URL>`u`||typeof URL.createObjectURL!=`function`?``:URL.createObjectURL(e)}function m(e){e.startsWith(`blob:`)&&typeof URL<`u`&&typeof URL.revokeObjectURL==`function`&&URL.revokeObjectURL(e)}function ee(e){return{type:e.type||`application/octet-stream`,url:p(e),fileName:e.name||`attachment`,size:e.size}}function te(e){return!Number.isFinite(e)||e<0?``:e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(+(e<10240))} KB`:`${(e/1048576).toFixed(1)} MB`}function ne(e){if(!e||typeof e!=`object`)return[];let t=e,n=t.attachments;if(!Array.isArray(n)&&t.message&&typeof t.message==`object`&&(n=t.message.attachments),!Array.isArray(n))return[];let r=[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=e;typeof t.url==`string`&&/^https?:\/\//i.test(t.url)&&r.push({type:typeof t.type==`string`&&t.type?t.type:`application/octet-stream`,url:t.url,fileName:typeof t.fileName==`string`&&t.fileName?t.fileName:`attachment`,size:typeof t.size==`number`&&t.size>=0?t.size:0,...typeof t.durationSeconds==`number`?{durationSeconds:t.durationSeconds}:{}})}return r}function re(e,t){let n=e.trim();return n?t.length===0?!1:t.some(e=>e.fileName===n)||/^\d+ files?$/.test(n)?!0:[`Image`,`Video`,`Audio`,`Attachment`].includes(n):!0}var h=16e3;function g(e){return(e??``).split(`;`)[0].trim().toLowerCase()||`audio/webm`}function ie(e){return e.includes(`mpeg`)||e.includes(`mp3`)?`mp3`:e.includes(`wav`)?`wav`:e.includes(`mp4`)||e.includes(`m4a`)?`m4a`:e.includes(`ogg`)?`ogg`:`webm`}function _(e){if(!Number.isFinite(e)||e<0)return`0:00`;let t=Math.floor(e),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,`0`)}`}function ae(){if(typeof window>`u`)return null;let e=window;return e.AudioContext??e.webkitAudioContext??null}function oe(){if(typeof window>`u`)return null;let e=window;return e.OfflineAudioContext??e.webkitOfflineAudioContext??null}async function se(e){let t=ae();if(!t)return null;let n=new t;try{let t=await e.arrayBuffer();return await n.decodeAudioData(t.slice(0))}catch{return null}finally{await n.close().catch(()=>void 0)}}async function ce(e){let t=oe();if(t)try{let n=new t(1,Math.max(1,Math.ceil(e.duration*h)),h),r=n.createBufferSource();return r.buffer=e,r.connect(n.destination),r.start(0),{samples:(await n.startRendering()).getChannelData(0),sampleRate:h}}catch{}return{samples:e.getChannelData(0),sampleRate:e.sampleRate}}function le(e,t){let n=e.length*2,r=new ArrayBuffer(44+n),i=new DataView(r),a=(e,t)=>{for(let n=0;n<t.length;n++)i.setUint8(e+n,t.charCodeAt(n))};a(0,`RIFF`),i.setUint32(4,36+n,!0),a(8,`WAVE`),a(12,`fmt `),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,1,!0),i.setUint32(24,t,!0),i.setUint32(28,t*2,!0),i.setUint16(32,2,!0),i.setUint16(34,16,!0),a(36,`data`),i.setUint32(40,n,!0);let o=44;for(let t=0;t<e.length;t++){let n=Math.max(-1,Math.min(1,e[t]??0));i.setInt16(o,Math.round(n<0?n*32768:n*32767),!0),o+=2}return new Blob([r],{type:`audio/wav`})}function ue(e,t=48){if(e.length===0)return[];let n=Math.max(1,Math.floor(e.length/t)),r=[],i=0;for(let a=0;a<t;a++){let t=a*n,o=Math.min(t+n,e.length),s=0;for(let n=t;n<o;n++){let t=e[n]??0;s+=t*t}let c=o>t?Math.sqrt(s/(o-t)):0;r.push(c),c>i&&(i=c)}return r.map(e=>i>0?Math.max(8,Math.min(100,Math.round(e/i*100))):8)}async function de(e){let t=Date.now(),n=Math.max(1,Math.round(e.durationSeconds||1)),r=g(e.mimeType??e.blob.type),i=await se(e.blob);if(!i)return{file:new File([e.blob],`voice-message-${t}.${ie(r)}`,{type:r}),durationSeconds:n};let{samples:a,sampleRate:o}=await ce(i);return{file:new File([le(a,o)],`voice-message-${t}.wav`,{type:`audio/wav`}),durationSeconds:Math.max(1,Math.round(i.duration||n)),waveform:ue(a)}}var fe=class{constructor(){this._listeners={}}on(e,t){return this._listeners[e]||(this._listeners[e]=[]),this._listeners[e].push(t),()=>this.off(e,t)}off(e,t){let n=this._listeners[e];n&&(this._listeners[e]=n.filter(e=>e!==t))}emit(e,...t){let n=this._listeners[e];if(n)for(let e of n)e(...t)}removeAllListeners(){for(let e of Object.keys(this._listeners))delete this._listeners[e]}},v=Object.create(null);v.open=`0`,v.close=`1`,v.ping=`2`,v.pong=`3`,v.message=`4`,v.upgrade=`5`,v.noop=`6`;var y=Object.create(null);Object.keys(v).forEach(e=>{y[v[e]]=e});var b={type:`error`,data:`parser error`},pe=typeof Blob==`function`||typeof Blob<`u`&&Object.prototype.toString.call(Blob)===`[object BlobConstructor]`,me=typeof ArrayBuffer==`function`,he=e=>typeof ArrayBuffer.isView==`function`?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,x=({type:e,data:t},n,r)=>pe&&t instanceof Blob?n?r(t):ge(t,r):me&&(t instanceof ArrayBuffer||he(t))?n?r(t):ge(new Blob([t]),r):r(v[e]+(t||``)),ge=(e,t)=>{let n=new FileReader;return n.onload=function(){let e=n.result.split(`,`)[1];t(`b`+(e||``))},n.readAsDataURL(e)};function _e(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var ve;function ye(e,t){if(pe&&e.data instanceof Blob)return e.data.arrayBuffer().then(_e).then(t);if(me&&(e.data instanceof ArrayBuffer||he(e.data)))return t(_e(e.data));x(e,!1,e=>{ve||=new TextEncoder,t(ve.encode(e))})}var be=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,S=typeof Uint8Array>`u`?[]:new Uint8Array(256);for(let e=0;e<64;e++)S[be.charCodeAt(e)]=e;var xe=e=>{let t=e.length*.75,n=e.length,r,i=0,a,o,s,c;e[e.length-1]===`=`&&(t--,e[e.length-2]===`=`&&t--);let l=new ArrayBuffer(t),u=new Uint8Array(l);for(r=0;r<n;r+=4)a=S[e.charCodeAt(r)],o=S[e.charCodeAt(r+1)],s=S[e.charCodeAt(r+2)],c=S[e.charCodeAt(r+3)],u[i++]=a<<2|o>>4,u[i++]=(o&15)<<4|s>>2,u[i++]=(s&3)<<6|c&63;return l},Se=typeof ArrayBuffer==`function`,C=(e,t)=>{if(typeof e!=`string`)return{type:`message`,data:we(e,t)};let n=e.charAt(0);return n===`b`?{type:`message`,data:Ce(e.substring(1),t)}:y[n]?e.length>1?{type:y[n],data:e.substring(1)}:{type:y[n]}:b},Ce=(e,t)=>Se?we(xe(e),t):{base64:!0,data:e},we=(e,t)=>{switch(t){case`blob`:return e instanceof Blob?e:new Blob([e]);default:return e instanceof ArrayBuffer?e:e.buffer}},Te=``,Ee=(e,t)=>{let n=e.length,r=Array(n),i=0;e.forEach((e,a)=>{x(e,!1,e=>{r[a]=e,++i===n&&t(r.join(Te))})})},De=(e,t)=>{let n=e.split(Te),r=[];for(let e=0;e<n.length;e++){let i=C(n[e],t);if(r.push(i),i.type===`error`)break}return r};function Oe(){return new TransformStream({transform(e,t){ye(e,n=>{let r=n.length,i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);let e=new DataView(i.buffer);e.setUint8(0,126),e.setUint16(1,r)}else{i=new Uint8Array(9);let e=new DataView(i.buffer);e.setUint8(0,127),e.setBigUint64(1,BigInt(r))}e.data&&typeof e.data!=`string`&&(i[0]|=128),t.enqueue(i),t.enqueue(n)})}})}var ke;function w(e){return e.reduce((e,t)=>e+t.length,0)}function T(e,t){if(e[0].length===t)return e.shift();let n=new Uint8Array(t),r=0;for(let i=0;i<t;i++)n[i]=e[0][r++],r===e[0].length&&(e.shift(),r=0);return e.length&&r<e[0].length&&(e[0]=e[0].slice(r)),n}function Ae(e,t){ke||=new TextDecoder;let n=[],r=0,i=-1,a=!1;return new TransformStream({transform(o,s){for(n.push(o);;){if(r===0){if(w(n)<1)break;let e=T(n,1);a=(e[0]&128)==128,i=e[0]&127,r=i<126?3:i===126?1:2}else if(r===1){if(w(n)<2)break;let e=T(n,2);i=new DataView(e.buffer,e.byteOffset,e.length).getUint16(0),r=3}else if(r===2){if(w(n)<8)break;let e=T(n,8),t=new DataView(e.buffer,e.byteOffset,e.length),a=t.getUint32(0);if(a>2**21-1){s.enqueue(b);break}i=a*2**32+t.getUint32(4),r=3}else{if(w(n)<i)break;let e=T(n,i);s.enqueue(C(a?e:ke.decode(e),t)),r=0}if(i===0||i>e){s.enqueue(b);break}}}})}function E(e){if(e)return je(e)}function je(e){for(var t in E.prototype)e[t]=E.prototype[t];return e}E.prototype.on=E.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks[`$`+e]=this._callbacks[`$`+e]||[]).push(t),this},E.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},E.prototype.off=E.prototype.removeListener=E.prototype.removeAllListeners=E.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks[`$`+e];if(!n)return this;if(arguments.length==1)return delete this._callbacks[`$`+e],this;for(var r,i=0;i<n.length;i++)if(r=n[i],r===t||r.fn===t){n.splice(i,1);break}return n.length===0&&delete this._callbacks[`$`+e],this},E.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=Array(arguments.length-1),n=this._callbacks[`$`+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(n){n=n.slice(0);for(var r=0,i=n.length;r<i;++r)n[r].apply(this,t)}return this},E.prototype.emitReserved=E.prototype.emit,E.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks[`$`+e]||[]},E.prototype.hasListeners=function(e){return!!this.listeners(e).length};var D=typeof Promise==`function`&&typeof Promise.resolve==`function`?e=>Promise.resolve().then(e):(e,t)=>t(e,0),O=typeof self<`u`?self:typeof window<`u`?window:Function(`return this`)(),Me=`arraybuffer`;function Ne(e,...t){return t.reduce((t,n)=>(e.hasOwnProperty(n)&&(t[n]=e[n]),t),{})}var Pe=O.setTimeout,Fe=O.clearTimeout;function k(e,t){t.useNativeTimers?(e.setTimeoutFn=Pe.bind(O),e.clearTimeoutFn=Fe.bind(O)):(e.setTimeoutFn=O.setTimeout.bind(O),e.clearTimeoutFn=O.clearTimeout.bind(O))}var Ie=1.33;function Le(e){return typeof e==`string`?Re(e):Math.ceil((e.byteLength||e.size)*Ie)}function Re(e){let t=0,n=0;for(let r=0,i=e.length;r<i;r++)t=e.charCodeAt(r),t<128?n+=1:t<2048?n+=2:t<55296||t>=57344?n+=3:(r++,n+=4);return n}function ze(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function Be(e){let t=``;for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+=`&`),t+=encodeURIComponent(n)+`=`+encodeURIComponent(e[n]));return t}function Ve(e){let t={},n=e.split(`&`);for(let e=0,r=n.length;e<r;e++){let r=n[e].split(`=`);t[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return t}var He=class extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type=`TransportError`}},A=class extends E{constructor(e){super(),this.writable=!1,k(this,e),this.opts=e,this.query=e.query,this.socket=e.socket,this.supportsBinary=!e.forceBase64}onError(e,t,n){return super.emitReserved(`error`,new He(e,t,n)),this}open(){return this.readyState=`opening`,this.doOpen(),this}close(){return(this.readyState===`opening`||this.readyState===`open`)&&(this.doClose(),this.onClose()),this}send(e){this.readyState===`open`&&this.write(e)}onOpen(){this.readyState=`open`,this.writable=!0,super.emitReserved(`open`)}onData(e){let t=C(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved(`packet`,e)}onClose(e){this.readyState=`closed`,super.emitReserved(`close`,e)}pause(e){}createUri(e,t={}){return e+`://`+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){let e=this.opts.hostname;return e.indexOf(`:`)===-1?e:`[`+e+`]`}_port(){return this.opts.port&&(this.opts.secure&&Number(this.opts.port)!==443||!this.opts.secure&&Number(this.opts.port)!==80)?`:`+this.opts.port:``}_query(e){let t=Be(e);return t.length?`?`+t:``}},Ue=class extends A{constructor(){super(...arguments),this._polling=!1}get name(){return`polling`}doOpen(){this._poll()}pause(e){this.readyState=`pausing`;let t=()=>{this.readyState=`paused`,e()};if(this._polling||!this.writable){let e=0;this._polling&&(e++,this.once(`pollComplete`,function(){--e||t()})),this.writable||(e++,this.once(`drain`,function(){--e||t()}))}else t()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved(`poll`)}onData(e){De(e,this.socket.binaryType).forEach(e=>{if(this.readyState===`opening`&&e.type===`open`&&this.onOpen(),e.type===`close`)return this.onClose({description:`transport closed by the server`}),!1;this.onPacket(e)}),this.readyState!==`closed`&&(this._polling=!1,this.emitReserved(`pollComplete`),this.readyState===`open`&&this._poll())}doClose(){let e=()=>{this.write([{type:`close`}])};this.readyState===`open`?e():this.once(`open`,e)}write(e){this.writable=!1,Ee(e,e=>{this.doWrite(e,()=>{this.writable=!0,this.emitReserved(`drain`)})})}uri(){let e=this.opts.secure?`https`:`http`,t=this.query||{};return!1!==this.opts.timestampRequests&&(t[this.opts.timestampParam]=ze()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}},We=!1;try{We=typeof XMLHttpRequest<`u`&&`withCredentials`in new XMLHttpRequest}catch{}var Ge=We;function Ke(){}var qe=class extends Ue{constructor(e){if(super(e),typeof location<`u`){let t=location.protocol===`https:`,n=location.port;n||=t?`443`:`80`,this.xd=typeof location<`u`&&e.hostname!==location.hostname||n!==e.port}}doWrite(e,t){let n=this.request({method:`POST`,data:e});n.on(`success`,t),n.on(`error`,(e,t)=>{this.onError(`xhr post error`,e,t)})}doPoll(){let e=this.request();e.on(`data`,this.onData.bind(this)),e.on(`error`,(e,t)=>{this.onError(`xhr poll error`,e,t)}),this.pollXhr=e}},j=class e extends E{constructor(e,t,n){super(),this.createRequest=e,k(this,n),this._opts=n,this._method=n.method||`GET`,this._uri=t,this._data=n.data===void 0?null:n.data,this._create()}_create(){var t;let n=Ne(this._opts,`agent`,`pfx`,`key`,`passphrase`,`cert`,`ca`,`ciphers`,`rejectUnauthorized`,`autoUnref`);n.xdomain=!!this._opts.xd;let r=this._xhr=this.createRequest(n);try{r.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let e in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(e)&&r.setRequestHeader(e,this._opts.extraHeaders[e])}}catch{}if(this._method===`POST`)try{r.setRequestHeader(`Content-type`,`text/plain;charset=UTF-8`)}catch{}try{r.setRequestHeader(`Accept`,`*/*`)}catch{}(t=this._opts.cookieJar)==null||t.addCookies(r),`withCredentials`in r&&(r.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(r.timeout=this._opts.requestTimeout),r.onreadystatechange=()=>{var e;r.readyState===3&&((e=this._opts.cookieJar)==null||e.parseCookies(r.getResponseHeader(`set-cookie`))),r.readyState===4&&(r.status===200||r.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof r.status==`number`?r.status:0)},0))},r.send(this._data)}catch(e){this.setTimeoutFn(()=>{this._onError(e)},0);return}typeof document<`u`&&(this._index=e.requestsCount++,e.requests[this._index]=this)}_onError(e){this.emitReserved(`error`,e,this._xhr),this._cleanup(!0)}_cleanup(t){if(this._xhr!==void 0&&this._xhr!==null){if(this._xhr.onreadystatechange=Ke,t)try{this._xhr.abort()}catch{}typeof document<`u`&&delete e.requests[this._index],this._xhr=null}}_onLoad(){let e=this._xhr.responseText;e!==null&&(this.emitReserved(`data`,e),this.emitReserved(`success`),this._cleanup())}abort(){this._cleanup()}};if(j.requestsCount=0,j.requests={},typeof document<`u`){if(typeof attachEvent==`function`)attachEvent(`onunload`,Je);else if(typeof addEventListener==`function`){let e=`onpagehide`in O?`pagehide`:`unload`;addEventListener(e,Je,!1)}}function Je(){for(let e in j.requests)j.requests.hasOwnProperty(e)&&j.requests[e].abort()}var Ye=(function(){let e=Ze({xdomain:!1});return e&&e.responseType!==null})(),Xe=class extends qe{constructor(e){super(e);let t=e&&e.forceBase64;this.supportsBinary=Ye&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new j(Ze,this.uri(),e)}};function Ze(e){let t=e.xdomain;try{if(typeof XMLHttpRequest<`u`&&(!t||Ge))return new XMLHttpRequest}catch{}if(!t)try{return new O[[`Active`,`Object`].join(`X`)](`Microsoft.XMLHTTP`)}catch{}}var Qe=typeof navigator<`u`&&typeof navigator.product==`string`&&navigator.product.toLowerCase()===`reactnative`,$e=class extends A{get name(){return`websocket`}doOpen(){let e=this.uri(),t=this.opts.protocols,n=Qe?{}:Ne(this.opts,`agent`,`perMessageDeflate`,`pfx`,`key`,`passphrase`,`cert`,`ca`,`ciphers`,`rejectUnauthorized`,`localAddress`,`protocolVersion`,`origin`,`maxPayload`,`family`,`checkServerIdentity`);this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(e,t,n)}catch(e){return this.emitReserved(`error`,e)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=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<e.length;t++){let n=e[t],r=t===e.length-1;x(n,this.supportsBinary,e=>{try{this.doWrite(n,e)}catch{}r&&D(()=>{this.writable=!0,this.emitReserved(`drain`)},this.setTimeoutFn)})}}doClose(){this.ws!==void 0&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){let e=this.opts.secure?`wss`:`ws`,t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=ze()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}},M=O.WebSocket||O.MozWebSocket,et={websocket:class extends $e{createSocket(e,t,n){return Qe?new M(e,t,n):t?new M(e,t):new M(e)}doWrite(e,t){this.ws.send(t)}},webtransport:class extends A{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=>{let t=Ae(2**53-1,this.socket.binaryType),n=e.readable.pipeThrough(t).getReader(),r=Oe();r.readable.pipeTo(e.writable),this._writer=r.writable.getWriter();let i=()=>{n.read().then(({done:e,value:t})=>{e||(this.onPacket(t),i())}).catch(e=>{})};i();let a={type:`open`};this.query.sid&&(a.data=`{"sid":"${this.query.sid}"}`),this._writer.write(a).then(()=>this.onOpen())})})}write(e){this.writable=!1;for(let t=0;t<e.length;t++){let n=e[t],r=t===e.length-1;this._writer.write(n).then(()=>{r&&D(()=>{this.writable=!0,this.emitReserved(`drain`)},this.setTimeoutFn)})}}doClose(){var e;(e=this._transport)==null||e.close()}},polling:Xe},tt=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,nt=[`source`,`protocol`,`authority`,`userInfo`,`user`,`password`,`host`,`port`,`relative`,`path`,`directory`,`file`,`query`,`anchor`];function N(e){if(e.length>8e3)throw`URI too long`;let t=e,n=e.indexOf(`[`),r=e.indexOf(`]`);n!=-1&&r!=-1&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,`;`)+e.substring(r,e.length));let i=tt.exec(e||``),a={},o=14;for(;o--;)a[nt[o]]=i[o]||``;return n!=-1&&r!=-1&&(a.source=t,a.host=a.host.substring(1,a.host.length-1).replace(/;/g,`:`),a.authority=a.authority.replace(`[`,``).replace(`]`,``).replace(/;/g,`:`),a.ipv6uri=!0),a.pathNames=rt(a,a.path),a.queryKey=it(a,a.query),a}function rt(e,t){let n=t.replace(/\/{2,9}/g,`/`).split(`/`);return(t.slice(0,1)==`/`||t.length===0)&&n.splice(0,1),t.slice(-1)==`/`&&n.splice(n.length-1,1),n}function it(e,t){let n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(e,t,r){t&&(n[t]=r)}),n}var P=typeof addEventListener==`function`&&typeof removeEventListener==`function`,F=[];P&&addEventListener(`offline`,()=>{F.forEach(e=>e())},!1);var I=class e extends E{constructor(e,t){if(super(),this.binaryType=Me,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,e&&typeof e==`object`&&(t=e,e=null),e){let n=N(e);t.hostname=n.host,t.secure=n.protocol===`https`||n.protocol===`wss`,t.port=n.port,n.query&&(t.query=n.query)}else t.host&&(t.hostname=N(t.host).host);k(this,t),this.secure=t.secure==null?typeof location<`u`&&location.protocol===`https:`:t.secure,t.hostname&&!t.port&&(t.port=this.secure?`443`:`80`),this.hostname=t.hostname||(typeof location<`u`?location.hostname:`localhost`),this.port=t.port||(typeof location<`u`&&location.port?location.port:this.secure?`443`:`80`),this.transports=[],this._transportsByName={},t.transports.forEach(e=>{let t=e.prototype.name;this.transports.push(t),this._transportsByName[t]=e}),this.opts=Object.assign({path:`/engine.io`,agent:!1,withCredentials:!1,upgrade:!0,timestampParam:`t`,rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,``)+(this.opts.addTrailingSlash?`/`:``),typeof this.opts.query==`string`&&(this.opts.query=Ve(this.opts.query)),P&&(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`})},F.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(e){let t=Object.assign({},this.opts.query);t.EIO=4,t.transport=e,this.id&&(t.sid=this.id);let n=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](n)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved(`error`,`No transports available`)},0);return}let t=this.opts.rememberUpgrade&&e.priorWebsocketSuccess&&this.transports.indexOf(`websocket`)!==-1?`websocket`:this.transports[0];this.readyState=`opening`;let n=this.createTransport(t);n.open(),this.setTransport(n)}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`,e=>this._onClose(`transport close`,e))}onOpen(){this.readyState=`open`,e.priorWebsocketSuccess=this.transport.name===`websocket`,this.emitReserved(`open`),this.flush()}_onPacket(e){if(this.readyState===`opening`||this.readyState===`open`||this.readyState===`closing`)switch(this.emitReserved(`packet`,e),this.emitReserved(`heartbeat`),e.type){case`open`:this.onHandshake(JSON.parse(e.data));break;case`ping`:this._sendPacket(`pong`),this.emitReserved(`ping`),this.emitReserved(`pong`),this._resetPingTimeout();break;case`error`:let t=Error(`server error`);t.code=e.data,this._onError(t);break;case`message`:this.emitReserved(`data`,e.data),this.emitReserved(`message`,e.data)}}onHandshake(e){this.emitReserved(`handshake`,e),this.id=e.sid,this.transport.query.sid=e.sid,this._pingInterval=e.pingInterval,this._pingTimeout=e.pingTimeout,this._maxPayload=e.maxPayload,this.onOpen(),this.readyState!==`closed`&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let e=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+e,this._pingTimeoutTimer=this.setTimeoutFn(()=>{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){let 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 e=1;for(let t=0;t<this.writeBuffer.length;t++){let n=this.writeBuffer[t].data;if(n&&(e+=Le(n)),t>0&&e>this._maxPayload)return this.writeBuffer.slice(0,t);e+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;let e=Date.now()>this._pingTimeoutTime;return e&&(this._pingTimeoutTime=0,D(()=>{this._onClose(`ping timeout`)},this.setTimeoutFn)),e}write(e,t,n){return this._sendPacket(`message`,e,t,n),this}send(e,t,n){return this._sendPacket(`message`,e,t,n),this}_sendPacket(e,t,n,r){if(typeof t==`function`&&(r=t,t=void 0),typeof n==`function`&&(r=n,n=null),this.readyState===`closing`||this.readyState===`closed`)return;n||={},n.compress=!1!==n.compress;let i={type:e,data:t,options:n};this.emitReserved(`packetCreate`,i),this.writeBuffer.push(i),r&&this.once(`flush`,r),this.flush()}close(){let e=()=>{this._onClose(`forced close`),this.transport.close()},t=()=>{this.off(`upgrade`,t),this.off(`upgradeError`,t),e()},n=()=>{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?n():e()}):this.upgrading?n():e()),this}_onError(t){if(e.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState===`opening`)return this.transports.shift(),this._open();this.emitReserved(`error`,t),this._onClose(`transport error`,t)}_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(),P&&(this._beforeunloadEventListener&&removeEventListener(`beforeunload`,this._beforeunloadEventListener,!1),this._offlineEventListener)){let e=F.indexOf(this._offlineEventListener);e!==-1&&F.splice(e,1)}this.readyState=`closed`,this.id=null,this.emitReserved(`close`,e,t),this.writeBuffer=[],this._prevBufferLen=0}}};I.protocol=4;var at=class extends I{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState===`open`&&this.opts.upgrade)for(let e=0;e<this._upgrades.length;e++)this._probe(this._upgrades[e])}_probe(e){let t=this.createTransport(e),n=!1;I.priorWebsocketSuccess=!1;let r=()=>{n||(t.send([{type:`ping`,data:`probe`}]),t.once(`packet`,e=>{if(!n){if(e.type===`pong`&&e.data===`probe`){if(this.upgrading=!0,this.emitReserved(`upgrading`,t),!t)return;I.priorWebsocketSuccess=t.name===`websocket`,this.transport.pause(()=>{n||this.readyState!==`closed`&&(l(),this.setTransport(t),t.send([{type:`upgrade`}]),this.emitReserved(`upgrade`,t),t=null,this.upgrading=!1,this.flush())})}else{let e=Error(`probe error`);e.transport=t.name,this.emitReserved(`upgradeError`,e)}}}))};function i(){n||(n=!0,l(),t.close(),t=null)}let a=e=>{let n=Error(`probe error: `+e);n.transport=t.name,i(),this.emitReserved(`upgradeError`,n)};function o(){a(`transport closed`)}function s(){a(`socket closed`)}function c(e){t&&e.name!==t.name&&i()}let l=()=>{t.removeListener(`open`,r),t.removeListener(`error`,a),t.removeListener(`close`,o),this.off(`close`,s),this.off(`upgrading`,c)};t.once(`open`,r),t.once(`error`,a),t.once(`close`,o),this.once(`close`,s),this.once(`upgrading`,c),this._upgrades.indexOf(`webtransport`)!==-1&&e!==`webtransport`?this.setTimeoutFn(()=>{n||t.open()},200):t.open()}onHandshake(e){this._upgrades=this._filterUpgrades(e.upgrades),super.onHandshake(e)}_filterUpgrades(e){let t=[];for(let n=0;n<e.length;n++)~this.transports.indexOf(e[n])&&t.push(e[n]);return t}},ot=class extends at{constructor(e,t={}){let n=typeof e==`object`,r=n?{...e}:{...t};(!r.transports||r.transports&&typeof r.transports[0]==`string`)&&(r.transports=(r.transports||[`polling`,`websocket`,`webtransport`]).map(e=>et[e]).filter(e=>!!e)),super(n?r:e,r)}};ot.protocol;function st(e,t=``,n){let r=e;n||=typeof location<`u`&&location,e??=n.protocol+`//`+n.host,typeof e==`string`&&(e.charAt(0)===`/`&&(e=e.charAt(1)===`/`?n.protocol+e:n.host+e),/^(https?|wss?):\/\//.test(e)||(e=n===void 0?`https://`+e:n.protocol+`//`+e),r=N(e)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port=`80`:/^(http|ws)s$/.test(r.protocol)&&(r.port=`443`)),r.path=r.path||`/`;let i=r.host.indexOf(`:`)===-1?r.host:`[`+r.host+`]`;return r.id=r.protocol+`://`+i+`:`+r.port+t,r.href=r.protocol+`://`+i+(n&&n.port===r.port?``:`:`+r.port),r}var ct=typeof ArrayBuffer==`function`,lt=e=>typeof ArrayBuffer.isView==`function`?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,ut=Object.prototype.toString,dt=typeof Blob==`function`||typeof Blob<`u`&&ut.call(Blob)===`[object BlobConstructor]`,ft=typeof File==`function`||typeof File<`u`&&ut.call(File)===`[object FileConstructor]`;function L(e){return ct&&(e instanceof ArrayBuffer||lt(e))||dt&&e instanceof Blob||ft&&e instanceof File}function R(e,t){if(!e||typeof e!=`object`)return!1;if(Array.isArray(e)){for(let t=0,n=e.length;t<n;t++)if(R(e[t]))return!0;return!1}if(L(e))return!0;if(e.toJSON&&typeof e.toJSON==`function`&&arguments.length===1)return R(e.toJSON(),!0);for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t)&&R(e[t]))return!0;return!1}function pt(e){let t=[],n=e.data,r=e;return r.data=z(n,t),r.attachments=t.length,{packet:r,buffers:t}}function z(e,t,n){if(!e)return e;if(L(e)){let n={_placeholder:!0,num:t.length};return t.push(e),n}if(Array.isArray(e)){let n=Array(e.length);for(let r=0;r<e.length;r++)n[r]=z(e[r],t);return n}if(typeof e==`object`&&!(e instanceof Date)){if(e.toJSON&&typeof e.toJSON==`function`&&!n)return z(e.toJSON(),t,!0);let r={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=z(e[n],t));return r}return e}function mt(e,t){return e.data=B(e.data,t),delete e.attachments,e}function B(e,t){if(!e)return e;if(e&&e._placeholder===!0){if(typeof e.num==`number`&&e.num>=0&&e.num<t.length)return t[e.num];throw Error(`illegal attachments`)}if(Array.isArray(e))for(let n=0;n<e.length;n++)e[n]=B(e[n],t);else if(typeof e==`object`)for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(e[n]=B(e[n],t));return e}var ht=t({Decoder:()=>vt,Encoder:()=>_t,PacketType:()=>V,isPacketValid:()=>wt,protocol:()=>5}),gt=[`connect`,`connect_error`,`disconnect`,`disconnecting`,`newListener`,`removeListener`],V;(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`})(V||={});var _t=class{constructor(e){this.replacer=e}encode(e){return(e.type===V.EVENT||e.type===V.ACK)&&R(e)?this.encodeAsBinary({type:e.type===V.EVENT?V.BINARY_EVENT:V.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let t=``+e.type;return(e.type===V.BINARY_EVENT||e.type===V.BINARY_ACK)&&(t+=e.attachments+`-`),e.nsp&&e.nsp!==`/`&&(t+=e.nsp+`,`),e.id!=null&&(t+=e.id),e.data!=null&&(t+=JSON.stringify(e.data,this.replacer)),t}encodeAsBinary(e){let t=pt(e),n=this.encodeAsString(t.packet),r=t.buffers;return r.unshift(n),r}},vt=class e extends E{constructor(e){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},typeof e==`function`?{reviver:e}:e)}add(e){let t;if(typeof e==`string`){if(this.reconstructor)throw Error(`got plaintext data when reconstructing a packet`);t=this.decodeString(e);let n=t.type===V.BINARY_EVENT;n||t.type===V.BINARY_ACK?(t.type=n?V.EVENT:V.ACK,this.reconstructor=new yt(t)):super.emitReserved(`decoded`,t)}else if(L(e)||e.base64){if(this.reconstructor)t=this.reconstructor.takeBinaryData(e),t&&(this.reconstructor=null,super.emitReserved(`decoded`,t));else throw Error(`got binary data when not reconstructing a packet`)}else throw Error(`Unknown type: `+e)}decodeString(t){let n=0,r={type:Number(t.charAt(0))};if(V[r.type]===void 0)throw Error(`unknown packet type `+r.type);if(r.type===V.BINARY_EVENT||r.type===V.BINARY_ACK){let e=n+1;for(;t.charAt(++n)!==`-`&&n!=t.length;);let i=t.substring(e,n);if(i!=Number(i)||t.charAt(n)!==`-`)throw Error(`Illegal attachments`);let a=Number(i);if(!xt(a)||a<1)throw Error(`Illegal attachments`);if(a>this.opts.maxAttachments)throw Error(`too many attachments`);r.attachments=a}if(t.charAt(n+1)===`/`){let e=n+1;for(;++n&&t.charAt(n)!==`,`&&n!==t.length;);r.nsp=t.substring(e,n)}else r.nsp=`/`;let i=t.charAt(n+1);if(i!==``&&Number(i)==i){let e=n+1;for(;++n;){let e=t.charAt(n);if(e==null||Number(e)!=e){--n;break}if(n===t.length)break}r.id=Number(t.substring(e,n+1))}if(t.charAt(++n)){let i=this.tryParse(t.substr(n));if(e.isPayloadValid(r.type,i))r.data=i;else throw Error(`invalid payload`)}return r}tryParse(e){try{return JSON.parse(e,this.opts.reviver)}catch{return!1}}static isPayloadValid(e,t){switch(e){case V.CONNECT:return H(t);case V.DISCONNECT:return t===void 0;case V.CONNECT_ERROR:return typeof t==`string`||H(t);case V.EVENT:case V.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]==`number`||typeof t[0]==`string`&&gt.indexOf(t[0])===-1);case V.ACK:case V.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&=(this.reconstructor.finishedReconstruction(),null)}},yt=class{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){let e=mt(this.reconPack,this.buffers);return this.finishedReconstruction(),e}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};function bt(e){return typeof e==`string`}var xt=Number.isInteger||function(e){return typeof e==`number`&&isFinite(e)&&Math.floor(e)===e};function St(e){return e===void 0||xt(e)}function H(e){return Object.prototype.toString.call(e)===`[object Object]`}function Ct(e,t){switch(e){case V.CONNECT:return t===void 0||H(t);case V.DISCONNECT:return t===void 0;case V.EVENT:return Array.isArray(t)&&(typeof t[0]==`number`||typeof t[0]==`string`&&gt.indexOf(t[0])===-1);case V.ACK:return Array.isArray(t);case V.CONNECT_ERROR:return typeof t==`string`||H(t);default:return!1}}function wt(e){return bt(e.nsp)&&St(e.id)&&Ct(e.type,e.data)}function U(e,t,n){return e.on(t,n),function(){e.off(t,n)}}var Tt=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),Et=class extends E{constructor(e,t,n){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,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;let e=this.io;this.subs=[U(e,`open`,this.onopen.bind(this)),U(e,`packet`,this.onpacket.bind(this)),U(e,`error`,this.onerror.bind(this)),U(e,`close`,this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(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){if(Tt.hasOwnProperty(e))throw 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;let n={type:V.EVENT,data:t};if(n.options={},n.options.compress=this.flags.compress!==!1,typeof t[t.length-1]==`function`){let e=this.ids++,r=t.pop();this._registerAckCallback(e,r),n.id=e}let r=this.io.engine?.transport?.writable,i=this.connected&&!this.io.engine?._hasPingExpired();return this.flags.volatile&&!r||(i?(this.notifyOutgoingListeners(n),this.packet(n)):this.sendBuffer.push(n)),this.flags={},this}_registerAckCallback(e,t){let n=this.flags.timeout??this._opts.ackTimeout;if(n===void 0){this.acks[e]=t;return}let r=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let t=0;t<this.sendBuffer.length;t++)this.sendBuffer[t].id===e&&this.sendBuffer.splice(t,1);t.call(this,Error(`operation has timed out`))},n),i=(...e)=>{this.io.clearTimeoutFn(r),t.apply(this,e)};i.withError=!0,this.acks[e]=i}emitWithAck(e,...t){return new Promise((n,r)=>{let i=(e,t)=>e?r(e):n(t);i.withError=!0,t.push(i),this.emit(e,...t)})}_addToQueue(e){let t;typeof e[e.length-1]==`function`&&(t=e.pop());let n={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((e,...r)=>(this._queue[0],e===null?(this._queue.shift(),t&&t(null,...r)):n.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(e)),n.pending=!1,this._drainQueue())),this._queue.push(n),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||this._queue.length===0)return;let 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:V.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(t=>String(t.id)===e)){let t=this.acks[e];delete this.acks[e],t.withError&&t.call(this,Error(`socket has been disconnected`))}})}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case V.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved(`connect_error`,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 V.EVENT:case V.BINARY_EVENT:this.onevent(e);break;case V.ACK:case V.BINARY_ACK:this.onack(e);break;case V.DISCONNECT:this.ondisconnect();break;case V.CONNECT_ERROR:this.destroy();let t=Error(e.data.message);t.data=e.data.data,this.emitReserved(`connect_error`,t)}}onevent(e){let 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){let t=this._anyListeners.slice();for(let n of t)n.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){let t=this,n=!1;return function(...r){n||(n=!0,t.packet({type:V.ACK,id:e,data:r}))}}onack(e){let 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()),void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:V.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){let t=this._anyListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){let t=this._anyOutgoingListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){let t=this._anyOutgoingListeners.slice();for(let n of t)n.apply(this,e.data)}}};function W(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}W.prototype.duration=function(){var e=this.ms*this.factor**+this.attempts++;if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=Math.floor(t*10)&1?e+n:e-n}return Math.min(e,this.max)|0},W.prototype.reset=function(){this.attempts=0},W.prototype.setMin=function(e){this.ms=e},W.prototype.setMax=function(e){this.max=e},W.prototype.setJitter=function(e){this.jitter=e};var G=class extends E{constructor(e,t){super(),this.nsps={},this.subs=[],e&&typeof e==`object`&&(t=e,e=void 0),t||={},t.path=t.path||`/socket.io`,this.opts=t,k(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(t.randomizationFactor??.5),this.backoff=new W({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(t.timeout==null?2e4:t.timeout),this._readyState=`closed`,this.uri=e;let n=t.parser||ht;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.setMin(e),this)}randomizationFactor(e){var t;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(t=this.backoff)==null||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(t=this.backoff)==null||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 ot(this.uri,this.opts);let t=this.engine,n=this;this._readyState=`opening`,this.skipReconnect=!1;let r=U(t,`open`,function(){n.onopen(),e&&e()}),i=t=>{this.cleanup(),this._readyState=`closed`,this.emitReserved(`error`,t),e?e(t):this.maybeReconnectOnOpen()},a=U(t,`error`,i);if(!1!==this._timeout){let e=this._timeout,n=this.setTimeoutFn(()=>{r(),i(Error(`timeout`)),t.close()},e);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}return this.subs.push(r),this.subs.push(a),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState=`open`,this.emitReserved(`open`);let e=this.engine;this.subs.push(U(e,`ping`,this.onping.bind(this)),U(e,`data`,this.ondata.bind(this)),U(e,`error`,this.onerror.bind(this)),U(e,`close`,this.onclose.bind(this)),U(this.decoder,`decoded`,this.ondecoded.bind(this)))}onping(){this.emitReserved(`ping`)}ondata(e){try{this.decoder.add(e)}catch(e){this.onclose(`parse error`,e)}}ondecoded(e){D(()=>{this.emitReserved(`packet`,e)},this.setTimeoutFn)}onerror(e){this.emitReserved(`error`,e)}socket(e,t){let n=this.nsps[e];return n?this._autoConnect&&!n.active&&n.connect():(n=new Et(this,e,t),this.nsps[e]=n),n}_destroy(e){let t=Object.keys(this.nsps);for(let e of t)if(this.nsps[e].active)return;this._close()}_packet(e){let t=this.encoder.encode(e);for(let n=0;n<t.length;n++)this.engine.write(t[n],e.options)}cleanup(){this.subs.forEach(e=>e()),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 n;this.cleanup(),(n=this.engine)==null||n.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;let e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved(`reconnect_failed`),this._reconnecting=!1;else{let t=this.backoff.duration();this._reconnecting=!0;let n=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved(`reconnect_attempt`,e.backoff.attempts),!e.skipReconnect&&e.open(t=>{t?(e._reconnecting=!1,e.reconnect(),this.emitReserved(`reconnect_error`,t)):e.onreconnect()}))},t);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}}onreconnect(){let e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved(`reconnect`,e)}},K={};function q(e,t){typeof e==`object`&&(t=e,e=void 0),t||={};let n=st(e,t.path||`/socket.io`),r=n.source,i=n.id,a=n.path,o=K[i]&&a in K[i].nsps,s=t.forceNew||t[`force new connection`]||!1===t.multiplex||o,c;return s?c=new G(r,t):(K[i]||(K[i]=new G(r,t)),c=K[i]),n.query&&!t.query&&(t.query=n.queryKey),c.socket(n.path,t)}Object.assign(q,{Manager:G,Socket:Et,io:q,connect:q});function Dt(e){let t=e.replace(/\/$/,``);try{return`${new URL(t).origin}/sdk`}catch{return`${t}/sdk`}}var Ot=class{constructor(){this.socket=null}get connected(){return this.socket?.connected??!1}connect(e){this.disconnect();let t=Dt(e.baseUrl);this.socket=q(t,{auth:{apiKey:e.apiKey,visitorToken:e.visitorToken},transports:[`websocket`,`polling`],autoConnect:!0,reconnection:!0});let n=!1;this.socket.on(`connect`,()=>{n?e.onReconnect?.():n=!0}),this.socket.on(`ticket:status`,t=>{e.onTicketStatus?.(t)}),this.socket.on(`message:receive`,t=>{e.onMessageReceive?.(t)}),this.socket.on(`connect_error`,t=>{e.onConnectError?.(t)})}disconnect(){this.socket&&=(this.socket.removeAllListeners(),this.socket.disconnect(),null)}},J=`onedeskpro_visitor_token`;function kt(e){try{return typeof window<`u`?window.localStorage.getItem(e):null}catch{return null}}function At(e,t){try{typeof window<`u`&&window.localStorage.setItem(e,t)}catch{}}function jt(e){try{typeof window<`u`&&window.localStorage.removeItem(e)}catch{}}var Mt=class{constructor(){this.token=null,this.storageKey=J}setScope(e){this.storageKey=e?.trim()?`${J}:${e.trim()}`:J,this.token=kt(this.storageKey)}get(){return this.token??kt(this.storageKey)}set(e){this.token=e,At(this.storageKey,e)}clear(){this.token=null,jt(this.storageKey)}},Nt=300,Pt=250,Ft=100,It=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg;codecs=opus`];function Lt(){return typeof MediaRecorder>`u`||typeof MediaRecorder.isTypeSupported!=`function`?`audio/webm`:It.find(e=>MediaRecorder.isTypeSupported(e))??`audio/webm`}function Rt(e){let t=e instanceof DOMException?e.name:``;return t===`NotAllowedError`||t===`PermissionDeniedError`||t===`SecurityError`?`Microphone access was denied.`:t===`NotFoundError`||t===`DevicesNotFoundError`?`No microphone was found.`:`Could not start recording.`}var Y=class e{constructor(e,t=300){this.onChange=e,this.maxDurationSeconds=t,this.recorder=null,this.stream=null,this.chunks=[],this.mimeType=`audio/webm`,this.startedAt=0,this.tickTimer=null,this.levelTimer=null,this.maxTimer=null,this.audioContext=null,this.analyser=null,this.snapshot={state:`idle`,elapsedSeconds:0,level:0,result:null}}static isSupported(){return typeof navigator<`u`&&typeof navigator.mediaDevices?.getUserMedia==`function`&&typeof MediaRecorder<`u`}getSnapshot(){return{...this.snapshot}}async start(){if(!e.isSupported())throw Error(`Voice messages are not supported in this browser.`);this.release(),this.chunks=[];let t;try{t=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){throw Error(Rt(e))}try{this.mimeType=Lt();let e=new MediaRecorder(t,{mimeType:this.mimeType});e.ondataavailable=e=>{e.data.size>0&&this.chunks.push(e.data)},this.stream=t,this.recorder=e,this.startedAt=Date.now(),e.start(200)}catch(e){throw t.getTracks().forEach(e=>e.stop()),this.stream=null,this.recorder=null,Error(Rt(e))}this.startLevelMeter(t),this.tickTimer=setInterval(()=>{this.update({elapsedSeconds:Math.floor(this.elapsedMs()/1e3)})},Pt),this.maxTimer=setTimeout(()=>void this.stop(),this.maxDurationSeconds*1e3),this.update({state:`recording`,elapsedSeconds:0,level:0,result:null})}async stop(){let e=this.recorder;if(!e||e.state===`inactive`)return this.release(),null;let t=Math.max(1,Math.round(this.elapsedMs()/1e3));this.clearTimers();let n=await new Promise(t=>{e.onstop=()=>{let e=this.chunks;this.chunks=[],t(new Blob(e,{type:g(this.mimeType)}))};try{e.stop()}catch{t(new Blob(this.chunks,{type:g(this.mimeType)}))}});this.releaseMedia();let r={blob:n,mimeType:g(this.mimeType),durationSeconds:t};return this.update({state:`preview`,elapsedSeconds:t,level:0,result:r}),r}cancel(){this.release(),this.update({state:`idle`,elapsedSeconds:0,level:0,result:null})}destroy(){this.release(),this.snapshot={state:`idle`,elapsedSeconds:0,level:0,result:null}}update(e){this.snapshot={...this.snapshot,...e},this.onChange({...this.snapshot})}elapsedMs(){return this.startedAt>0?Date.now()-this.startedAt:0}startLevelMeter(e){let t=typeof window>`u`?null:window,n=t?.AudioContext??t?.webkitAudioContext;if(n)try{let t=new n,r=t.createAnalyser();r.fftSize=256,t.createMediaStreamSource(e).connect(r),t.resume().catch(()=>void 0),this.audioContext=t,this.analyser=r;let i=new Uint8Array(r.frequencyBinCount);this.levelTimer=setInterval(()=>{r.getByteTimeDomainData(i);let e=0;for(let t=0;t<i.length;t++){let n=((i[t]??128)-128)/128;e+=n*n}this.update({level:Math.min(1,Math.sqrt(e/i.length)*3.2)})},Ft)}catch{}}clearTimers(){this.tickTimer&&clearInterval(this.tickTimer),this.levelTimer&&clearInterval(this.levelTimer),this.maxTimer&&clearTimeout(this.maxTimer),this.tickTimer=null,this.levelTimer=null,this.maxTimer=null}releaseMedia(){this.stream?.getTracks().forEach(e=>e.stop()),this.stream=null,this.recorder=null,this.analyser=null,this.audioContext&&=(this.audioContext.close().catch(()=>void 0),null),this.startedAt=0}release(){if(this.clearTimers(),this.recorder&&this.recorder.state!==`inactive`){this.recorder.onstop=null;try{this.recorder.stop()}catch{}}this.chunks=[],this.releaseMedia()}},X=[{iso:`BD`,name:`Bangladesh`,dial:`880`,flag:`🇧🇩`},{iso:`US`,name:`United States`,dial:`1`,flag:`🇺🇸`},{iso:`GB`,name:`United Kingdom`,dial:`44`,flag:`🇬🇧`},{iso:`IN`,name:`India`,dial:`91`,flag:`🇮🇳`},{iso:`PK`,name:`Pakistan`,dial:`92`,flag:`🇵🇰`},{iso:`AE`,name:`United Arab Emirates`,dial:`971`,flag:`🇦🇪`},{iso:`SA`,name:`Saudi Arabia`,dial:`966`,flag:`🇸🇦`},{iso:`CA`,name:`Canada`,dial:`1`,flag:`🇨🇦`},{iso:`AU`,name:`Australia`,dial:`61`,flag:`🇦🇺`},{iso:`DE`,name:`Germany`,dial:`49`,flag:`🇩🇪`},{iso:`FR`,name:`France`,dial:`33`,flag:`🇫🇷`},{iso:`IT`,name:`Italy`,dial:`39`,flag:`🇮🇹`},{iso:`ES`,name:`Spain`,dial:`34`,flag:`🇪🇸`},{iso:`NL`,name:`Netherlands`,dial:`31`,flag:`🇳🇱`},{iso:`SE`,name:`Sweden`,dial:`46`,flag:`🇸🇪`},{iso:`NO`,name:`Norway`,dial:`47`,flag:`🇳🇴`},{iso:`DK`,name:`Denmark`,dial:`45`,flag:`🇩🇰`},{iso:`FI`,name:`Finland`,dial:`358`,flag:`🇫🇮`},{iso:`IE`,name:`Ireland`,dial:`353`,flag:`🇮🇪`},{iso:`CH`,name:`Switzerland`,dial:`41`,flag:`🇨🇭`},{iso:`AT`,name:`Austria`,dial:`43`,flag:`🇦🇹`},{iso:`BE`,name:`Belgium`,dial:`32`,flag:`🇧🇪`},{iso:`PT`,name:`Portugal`,dial:`351`,flag:`🇵🇹`},{iso:`PL`,name:`Poland`,dial:`48`,flag:`🇵🇱`},{iso:`CZ`,name:`Czechia`,dial:`420`,flag:`🇨🇿`},{iso:`RO`,name:`Romania`,dial:`40`,flag:`🇷🇴`},{iso:`HU`,name:`Hungary`,dial:`36`,flag:`🇭🇺`},{iso:`GR`,name:`Greece`,dial:`30`,flag:`🇬🇷`},{iso:`TR`,name:`Turkey`,dial:`90`,flag:`🇹🇷`},{iso:`RU`,name:`Russia`,dial:`7`,flag:`🇷🇺`},{iso:`UA`,name:`Ukraine`,dial:`380`,flag:`🇺🇦`},{iso:`CN`,name:`China`,dial:`86`,flag:`🇨🇳`},{iso:`JP`,name:`Japan`,dial:`81`,flag:`🇯🇵`},{iso:`KR`,name:`South Korea`,dial:`82`,flag:`🇰🇷`},{iso:`SG`,name:`Singapore`,dial:`65`,flag:`🇸🇬`},{iso:`MY`,name:`Malaysia`,dial:`60`,flag:`🇲🇾`},{iso:`ID`,name:`Indonesia`,dial:`62`,flag:`🇮🇩`},{iso:`TH`,name:`Thailand`,dial:`66`,flag:`🇹🇭`},{iso:`VN`,name:`Vietnam`,dial:`84`,flag:`🇻🇳`},{iso:`PH`,name:`Philippines`,dial:`63`,flag:`🇵🇭`},{iso:`HK`,name:`Hong Kong`,dial:`852`,flag:`🇭🇰`},{iso:`TW`,name:`Taiwan`,dial:`886`,flag:`🇹🇼`},{iso:`NZ`,name:`New Zealand`,dial:`64`,flag:`🇳🇿`},{iso:`ZA`,name:`South Africa`,dial:`27`,flag:`🇿🇦`},{iso:`NG`,name:`Nigeria`,dial:`234`,flag:`🇳🇬`},{iso:`KE`,name:`Kenya`,dial:`254`,flag:`🇰🇪`},{iso:`EG`,name:`Egypt`,dial:`20`,flag:`🇪🇬`},{iso:`MA`,name:`Morocco`,dial:`212`,flag:`🇲🇦`},{iso:`BR`,name:`Brazil`,dial:`55`,flag:`🇧🇷`},{iso:`MX`,name:`Mexico`,dial:`52`,flag:`🇲🇽`},{iso:`AR`,name:`Argentina`,dial:`54`,flag:`🇦🇷`},{iso:`CL`,name:`Chile`,dial:`56`,flag:`🇨🇱`},{iso:`CO`,name:`Colombia`,dial:`57`,flag:`🇨🇴`},{iso:`PE`,name:`Peru`,dial:`51`,flag:`🇵🇪`},{iso:`IL`,name:`Israel`,dial:`972`,flag:`🇮🇱`},{iso:`QA`,name:`Qatar`,dial:`974`,flag:`🇶🇦`},{iso:`KW`,name:`Kuwait`,dial:`965`,flag:`🇰🇼`},{iso:`BH`,name:`Bahrain`,dial:`973`,flag:`🇧🇭`},{iso:`OM`,name:`Oman`,dial:`968`,flag:`🇴🇲`},{iso:`LK`,name:`Sri Lanka`,dial:`94`,flag:`🇱🇰`},{iso:`NP`,name:`Nepal`,dial:`977`,flag:`🇳🇵`}],zt=X.find(e=>e.iso===`BD`)??X[0];function Bt(e,t){let n=t.trim();if(n.startsWith(`+`)){let e=n.replace(/\D/g,``);return e?`+${e}`:``}let r=n.replace(/\D/g,``);return!r||(r=r.replace(/^0+/,``),!r)?``:`+${e}${r}`}var Vt=`(max-width: 640px), (max-height: 500px) and (pointer: coarse)`;function Ht(e,t){let n=`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r},n=3e4,r=12e4;function i(e){return typeof e==`object`&&!!e&&typeof e.message==`string`}function a(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.type==`string`&&typeof t.url==`string`&&typeof t.fileName==`string`&&typeof t.size==`number`}function o(e){return e instanceof Error&&`apiError`in e&&`status`in e&&typeof e.status==`number`&&i(e.apiError)}var s=class{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,``),this.apiKey=e.apiKey,this.timeoutMs=e.timeoutMs??3e4,this.uploadTimeoutMs=e.uploadTimeoutMs??r}fail(e,t,n,r){let i={statusCode:t,message:e,code:n,timestamp:new Date().toISOString(),path:r};throw Object.assign(Error(e),{apiError:i,status:t})}async request(e,t,n,r,a,o=this.timeoutMs){let s=new URL(`${this.baseUrl}${t}`);if(r)for(let[e,t]of Object.entries(r))s.searchParams.set(e,t);let c=typeof FormData<`u`&&n instanceof FormData,l={...c?{}:{"Content-Type":`application/json`},"X-API-Key":this.apiKey,...a},u=new AbortController,d=setTimeout(()=>u.abort(),o),f;try{f=await fetch(s.toString(),{method:e,headers:l,signal:u.signal,...n===void 0?{}:{body:c?n:JSON.stringify(n)}})}catch(e){u.signal.aborted&&this.fail(`Request timed out after ${o}ms.`,0,`TIMEOUT`,t),this.fail(e instanceof Error?e.message:`Network request failed.`,0,`NETWORK_ERROR`,t)}finally{clearTimeout(d)}let p=await f.text(),m=null;if(p)try{m=JSON.parse(p)}catch{m=null}if(!f.ok){if(i(m))throw Object.assign(Error(m.message),{apiError:m,status:f.status});this.fail(`Request failed with status ${f.status} ${f.statusText}`.trim(),f.status,`HTTP_ERROR`,t)}return m===null&&this.fail(`The server returned an empty or malformed response.`,f.status,`BAD_RESPONSE`,t),m.data}async identify(e){return this.request(`POST`,`/sdk/identify`,e)}async verifyVisitor(e){return this.request(`GET`,`/sdk/visitor`,void 0,void 0,{"X-Visitor-Token":e})}async sendMessage(e){return this.request(`POST`,`/sdk/chat`,e)}async uploadAttachment(e,t){let n=new FormData;n.append(`file`,e,e.name);let r=await this.request(`POST`,`/sdk/upload`,n,void 0,{"X-Visitor-Token":t},this.uploadTimeoutMs);return a(r)||this.fail(`The server returned an unexpected upload response.`,200,`BAD_RESPONSE`,`/sdk/upload`),r}async fetchConfig(){return this.request(`GET`,`/sdk/config`)}async requestHuman(e){return this.request(`POST`,`/sdk/human-request`,{visitorToken:e})}async fetchTicketStatus(e){return this.request(`GET`,`/sdk/ticket-status`,void 0,void 0,{"X-Visitor-Token":e})}},c=`https://api.onedeskpro.com`,l=10485760,u=10;function d(e){if(e.length>10)return`You can send up to 10 files at a time.`;let t=e.find(e=>e.size>l);if(t){let e=Math.round(l/1048576);return`"${t.name||`This file`}" is larger than ${e} MB.`}return null}function f(e){return/^(https?:\/\/|blob:)/i.test(e)}function p(e){return typeof URL>`u`||typeof URL.createObjectURL!=`function`?``:URL.createObjectURL(e)}function m(e){e.startsWith(`blob:`)&&typeof URL<`u`&&typeof URL.revokeObjectURL==`function`&&URL.revokeObjectURL(e)}function ee(e){return{type:e.type||`application/octet-stream`,url:p(e),fileName:e.name||`attachment`,size:e.size}}function te(e){return!Number.isFinite(e)||e<0?``:e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(+(e<10240))} KB`:`${(e/1048576).toFixed(1)} MB`}function ne(e){if(!e||typeof e!=`object`)return[];let t=e,n=t.attachments;if(!Array.isArray(n)&&t.message&&typeof t.message==`object`&&(n=t.message.attachments),!Array.isArray(n))return[];let r=[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=e;typeof t.url==`string`&&/^https?:\/\//i.test(t.url)&&r.push({type:typeof t.type==`string`&&t.type?t.type:`application/octet-stream`,url:t.url,fileName:typeof t.fileName==`string`&&t.fileName?t.fileName:`attachment`,size:typeof t.size==`number`&&t.size>=0?t.size:0,...typeof t.durationSeconds==`number`?{durationSeconds:t.durationSeconds}:{}})}return r}function re(e,t){let n=e.trim();return n?t.length===0?!1:t.some(e=>e.fileName===n)||/^\d+ files?$/.test(n)?!0:[`Image`,`Video`,`Audio`,`Attachment`].includes(n):!0}var h=16e3;function g(e){return(e??``).split(`;`)[0].trim().toLowerCase()||`audio/webm`}function ie(e){return e.includes(`mpeg`)||e.includes(`mp3`)?`mp3`:e.includes(`wav`)?`wav`:e.includes(`mp4`)||e.includes(`m4a`)?`m4a`:e.includes(`ogg`)?`ogg`:`webm`}function _(e){if(!Number.isFinite(e)||e<0)return`0:00`;let t=Math.floor(e),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,`0`)}`}function ae(){if(typeof window>`u`)return null;let e=window;return e.AudioContext??e.webkitAudioContext??null}function oe(){if(typeof window>`u`)return null;let e=window;return e.OfflineAudioContext??e.webkitOfflineAudioContext??null}async function se(e){let t=ae();if(!t)return null;let n=new t;try{let t=await e.arrayBuffer();return await n.decodeAudioData(t.slice(0))}catch{return null}finally{await n.close().catch(()=>void 0)}}async function ce(e){let t=oe();if(t)try{let n=new t(1,Math.max(1,Math.ceil(e.duration*h)),h),r=n.createBufferSource();return r.buffer=e,r.connect(n.destination),r.start(0),{samples:(await n.startRendering()).getChannelData(0),sampleRate:h}}catch{}return{samples:e.getChannelData(0),sampleRate:e.sampleRate}}function le(e,t){let n=e.length*2,r=new ArrayBuffer(44+n),i=new DataView(r),a=(e,t)=>{for(let n=0;n<t.length;n++)i.setUint8(e+n,t.charCodeAt(n))};a(0,`RIFF`),i.setUint32(4,36+n,!0),a(8,`WAVE`),a(12,`fmt `),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,1,!0),i.setUint32(24,t,!0),i.setUint32(28,t*2,!0),i.setUint16(32,2,!0),i.setUint16(34,16,!0),a(36,`data`),i.setUint32(40,n,!0);let o=44;for(let t=0;t<e.length;t++){let n=Math.max(-1,Math.min(1,e[t]??0));i.setInt16(o,Math.round(n<0?n*32768:n*32767),!0),o+=2}return new Blob([r],{type:`audio/wav`})}function ue(e,t=48){if(e.length===0)return[];let n=Math.max(1,Math.floor(e.length/t)),r=[],i=0;for(let a=0;a<t;a++){let t=a*n,o=Math.min(t+n,e.length),s=0;for(let n=t;n<o;n++){let t=e[n]??0;s+=t*t}let c=o>t?Math.sqrt(s/(o-t)):0;r.push(c),c>i&&(i=c)}return r.map(e=>i>0?Math.max(8,Math.min(100,Math.round(e/i*100))):8)}async function de(e){let t=Date.now(),n=Math.max(1,Math.round(e.durationSeconds||1)),r=g(e.mimeType??e.blob.type),i=await se(e.blob);if(!i)return{file:new File([e.blob],`voice-message-${t}.${ie(r)}`,{type:r}),durationSeconds:n};let{samples:a,sampleRate:o}=await ce(i);return{file:new File([le(a,o)],`voice-message-${t}.wav`,{type:`audio/wav`}),durationSeconds:Math.max(1,Math.round(i.duration||n)),waveform:ue(a)}}var fe=class{constructor(){this._listeners={}}on(e,t){return this._listeners[e]||(this._listeners[e]=[]),this._listeners[e].push(t),()=>this.off(e,t)}off(e,t){let n=this._listeners[e];n&&(this._listeners[e]=n.filter(e=>e!==t))}emit(e,...t){let n=this._listeners[e];if(n)for(let e of n)e(...t)}removeAllListeners(){for(let e of Object.keys(this._listeners))delete this._listeners[e]}},v=Object.create(null);v.open=`0`,v.close=`1`,v.ping=`2`,v.pong=`3`,v.message=`4`,v.upgrade=`5`,v.noop=`6`;var y=Object.create(null);Object.keys(v).forEach(e=>{y[v[e]]=e});var b={type:`error`,data:`parser error`},pe=typeof Blob==`function`||typeof Blob<`u`&&Object.prototype.toString.call(Blob)===`[object BlobConstructor]`,me=typeof ArrayBuffer==`function`,he=e=>typeof ArrayBuffer.isView==`function`?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,x=({type:e,data:t},n,r)=>pe&&t instanceof Blob?n?r(t):ge(t,r):me&&(t instanceof ArrayBuffer||he(t))?n?r(t):ge(new Blob([t]),r):r(v[e]+(t||``)),ge=(e,t)=>{let n=new FileReader;return n.onload=function(){let e=n.result.split(`,`)[1];t(`b`+(e||``))},n.readAsDataURL(e)};function _e(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var ve;function ye(e,t){if(pe&&e.data instanceof Blob)return e.data.arrayBuffer().then(_e).then(t);if(me&&(e.data instanceof ArrayBuffer||he(e.data)))return t(_e(e.data));x(e,!1,e=>{ve||=new TextEncoder,t(ve.encode(e))})}var be=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,S=typeof Uint8Array>`u`?[]:new Uint8Array(256);for(let e=0;e<64;e++)S[be.charCodeAt(e)]=e;var xe=e=>{let t=e.length*.75,n=e.length,r,i=0,a,o,s,c;e[e.length-1]===`=`&&(t--,e[e.length-2]===`=`&&t--);let l=new ArrayBuffer(t),u=new Uint8Array(l);for(r=0;r<n;r+=4)a=S[e.charCodeAt(r)],o=S[e.charCodeAt(r+1)],s=S[e.charCodeAt(r+2)],c=S[e.charCodeAt(r+3)],u[i++]=a<<2|o>>4,u[i++]=(o&15)<<4|s>>2,u[i++]=(s&3)<<6|c&63;return l},Se=typeof ArrayBuffer==`function`,C=(e,t)=>{if(typeof e!=`string`)return{type:`message`,data:we(e,t)};let n=e.charAt(0);return n===`b`?{type:`message`,data:Ce(e.substring(1),t)}:y[n]?e.length>1?{type:y[n],data:e.substring(1)}:{type:y[n]}:b},Ce=(e,t)=>Se?we(xe(e),t):{base64:!0,data:e},we=(e,t)=>{switch(t){case`blob`:return e instanceof Blob?e:new Blob([e]);default:return e instanceof ArrayBuffer?e:e.buffer}},Te=``,Ee=(e,t)=>{let n=e.length,r=Array(n),i=0;e.forEach((e,a)=>{x(e,!1,e=>{r[a]=e,++i===n&&t(r.join(Te))})})},De=(e,t)=>{let n=e.split(Te),r=[];for(let e=0;e<n.length;e++){let i=C(n[e],t);if(r.push(i),i.type===`error`)break}return r};function Oe(){return new TransformStream({transform(e,t){ye(e,n=>{let r=n.length,i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);let e=new DataView(i.buffer);e.setUint8(0,126),e.setUint16(1,r)}else{i=new Uint8Array(9);let e=new DataView(i.buffer);e.setUint8(0,127),e.setBigUint64(1,BigInt(r))}e.data&&typeof e.data!=`string`&&(i[0]|=128),t.enqueue(i),t.enqueue(n)})}})}var ke;function w(e){return e.reduce((e,t)=>e+t.length,0)}function T(e,t){if(e[0].length===t)return e.shift();let n=new Uint8Array(t),r=0;for(let i=0;i<t;i++)n[i]=e[0][r++],r===e[0].length&&(e.shift(),r=0);return e.length&&r<e[0].length&&(e[0]=e[0].slice(r)),n}function Ae(e,t){ke||=new TextDecoder;let n=[],r=0,i=-1,a=!1;return new TransformStream({transform(o,s){for(n.push(o);;){if(r===0){if(w(n)<1)break;let e=T(n,1);a=(e[0]&128)==128,i=e[0]&127,r=i<126?3:i===126?1:2}else if(r===1){if(w(n)<2)break;let e=T(n,2);i=new DataView(e.buffer,e.byteOffset,e.length).getUint16(0),r=3}else if(r===2){if(w(n)<8)break;let e=T(n,8),t=new DataView(e.buffer,e.byteOffset,e.length),a=t.getUint32(0);if(a>2**21-1){s.enqueue(b);break}i=a*2**32+t.getUint32(4),r=3}else{if(w(n)<i)break;let e=T(n,i);s.enqueue(C(a?e:ke.decode(e),t)),r=0}if(i===0||i>e){s.enqueue(b);break}}}})}function E(e){if(e)return je(e)}function je(e){for(var t in E.prototype)e[t]=E.prototype[t];return e}E.prototype.on=E.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks[`$`+e]=this._callbacks[`$`+e]||[]).push(t),this},E.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},E.prototype.off=E.prototype.removeListener=E.prototype.removeAllListeners=E.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks[`$`+e];if(!n)return this;if(arguments.length==1)return delete this._callbacks[`$`+e],this;for(var r,i=0;i<n.length;i++)if(r=n[i],r===t||r.fn===t){n.splice(i,1);break}return n.length===0&&delete this._callbacks[`$`+e],this},E.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=Array(arguments.length-1),n=this._callbacks[`$`+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(n){n=n.slice(0);for(var r=0,i=n.length;r<i;++r)n[r].apply(this,t)}return this},E.prototype.emitReserved=E.prototype.emit,E.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks[`$`+e]||[]},E.prototype.hasListeners=function(e){return!!this.listeners(e).length};var D=typeof Promise==`function`&&typeof Promise.resolve==`function`?e=>Promise.resolve().then(e):(e,t)=>t(e,0),O=typeof self<`u`?self:typeof window<`u`?window:Function(`return this`)(),Me=`arraybuffer`;function Ne(e,...t){return t.reduce((t,n)=>(e.hasOwnProperty(n)&&(t[n]=e[n]),t),{})}var Pe=O.setTimeout,Fe=O.clearTimeout;function k(e,t){t.useNativeTimers?(e.setTimeoutFn=Pe.bind(O),e.clearTimeoutFn=Fe.bind(O)):(e.setTimeoutFn=O.setTimeout.bind(O),e.clearTimeoutFn=O.clearTimeout.bind(O))}var Ie=1.33;function Le(e){return typeof e==`string`?Re(e):Math.ceil((e.byteLength||e.size)*Ie)}function Re(e){let t=0,n=0;for(let r=0,i=e.length;r<i;r++)t=e.charCodeAt(r),t<128?n+=1:t<2048?n+=2:t<55296||t>=57344?n+=3:(r++,n+=4);return n}function ze(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function Be(e){let t=``;for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+=`&`),t+=encodeURIComponent(n)+`=`+encodeURIComponent(e[n]));return t}function Ve(e){let t={},n=e.split(`&`);for(let e=0,r=n.length;e<r;e++){let r=n[e].split(`=`);t[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return t}var He=class extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type=`TransportError`}},A=class extends E{constructor(e){super(),this.writable=!1,k(this,e),this.opts=e,this.query=e.query,this.socket=e.socket,this.supportsBinary=!e.forceBase64}onError(e,t,n){return super.emitReserved(`error`,new He(e,t,n)),this}open(){return this.readyState=`opening`,this.doOpen(),this}close(){return(this.readyState===`opening`||this.readyState===`open`)&&(this.doClose(),this.onClose()),this}send(e){this.readyState===`open`&&this.write(e)}onOpen(){this.readyState=`open`,this.writable=!0,super.emitReserved(`open`)}onData(e){let t=C(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved(`packet`,e)}onClose(e){this.readyState=`closed`,super.emitReserved(`close`,e)}pause(e){}createUri(e,t={}){return e+`://`+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){let e=this.opts.hostname;return e.indexOf(`:`)===-1?e:`[`+e+`]`}_port(){return this.opts.port&&(this.opts.secure&&Number(this.opts.port)!==443||!this.opts.secure&&Number(this.opts.port)!==80)?`:`+this.opts.port:``}_query(e){let t=Be(e);return t.length?`?`+t:``}},Ue=class extends A{constructor(){super(...arguments),this._polling=!1}get name(){return`polling`}doOpen(){this._poll()}pause(e){this.readyState=`pausing`;let t=()=>{this.readyState=`paused`,e()};if(this._polling||!this.writable){let e=0;this._polling&&(e++,this.once(`pollComplete`,function(){--e||t()})),this.writable||(e++,this.once(`drain`,function(){--e||t()}))}else t()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved(`poll`)}onData(e){De(e,this.socket.binaryType).forEach(e=>{if(this.readyState===`opening`&&e.type===`open`&&this.onOpen(),e.type===`close`)return this.onClose({description:`transport closed by the server`}),!1;this.onPacket(e)}),this.readyState!==`closed`&&(this._polling=!1,this.emitReserved(`pollComplete`),this.readyState===`open`&&this._poll())}doClose(){let e=()=>{this.write([{type:`close`}])};this.readyState===`open`?e():this.once(`open`,e)}write(e){this.writable=!1,Ee(e,e=>{this.doWrite(e,()=>{this.writable=!0,this.emitReserved(`drain`)})})}uri(){let e=this.opts.secure?`https`:`http`,t=this.query||{};return!1!==this.opts.timestampRequests&&(t[this.opts.timestampParam]=ze()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}},We=!1;try{We=typeof XMLHttpRequest<`u`&&`withCredentials`in new XMLHttpRequest}catch{}var Ge=We;function Ke(){}var qe=class extends Ue{constructor(e){if(super(e),typeof location<`u`){let t=location.protocol===`https:`,n=location.port;n||=t?`443`:`80`,this.xd=typeof location<`u`&&e.hostname!==location.hostname||n!==e.port}}doWrite(e,t){let n=this.request({method:`POST`,data:e});n.on(`success`,t),n.on(`error`,(e,t)=>{this.onError(`xhr post error`,e,t)})}doPoll(){let e=this.request();e.on(`data`,this.onData.bind(this)),e.on(`error`,(e,t)=>{this.onError(`xhr poll error`,e,t)}),this.pollXhr=e}},j=class e extends E{constructor(e,t,n){super(),this.createRequest=e,k(this,n),this._opts=n,this._method=n.method||`GET`,this._uri=t,this._data=n.data===void 0?null:n.data,this._create()}_create(){var t;let n=Ne(this._opts,`agent`,`pfx`,`key`,`passphrase`,`cert`,`ca`,`ciphers`,`rejectUnauthorized`,`autoUnref`);n.xdomain=!!this._opts.xd;let r=this._xhr=this.createRequest(n);try{r.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let e in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(e)&&r.setRequestHeader(e,this._opts.extraHeaders[e])}}catch{}if(this._method===`POST`)try{r.setRequestHeader(`Content-type`,`text/plain;charset=UTF-8`)}catch{}try{r.setRequestHeader(`Accept`,`*/*`)}catch{}(t=this._opts.cookieJar)==null||t.addCookies(r),`withCredentials`in r&&(r.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(r.timeout=this._opts.requestTimeout),r.onreadystatechange=()=>{var e;r.readyState===3&&((e=this._opts.cookieJar)==null||e.parseCookies(r.getResponseHeader(`set-cookie`))),r.readyState===4&&(r.status===200||r.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof r.status==`number`?r.status:0)},0))},r.send(this._data)}catch(e){this.setTimeoutFn(()=>{this._onError(e)},0);return}typeof document<`u`&&(this._index=e.requestsCount++,e.requests[this._index]=this)}_onError(e){this.emitReserved(`error`,e,this._xhr),this._cleanup(!0)}_cleanup(t){if(this._xhr!==void 0&&this._xhr!==null){if(this._xhr.onreadystatechange=Ke,t)try{this._xhr.abort()}catch{}typeof document<`u`&&delete e.requests[this._index],this._xhr=null}}_onLoad(){let e=this._xhr.responseText;e!==null&&(this.emitReserved(`data`,e),this.emitReserved(`success`),this._cleanup())}abort(){this._cleanup()}};if(j.requestsCount=0,j.requests={},typeof document<`u`){if(typeof attachEvent==`function`)attachEvent(`onunload`,Je);else if(typeof addEventListener==`function`){let e=`onpagehide`in O?`pagehide`:`unload`;addEventListener(e,Je,!1)}}function Je(){for(let e in j.requests)j.requests.hasOwnProperty(e)&&j.requests[e].abort()}var Ye=(function(){let e=Ze({xdomain:!1});return e&&e.responseType!==null})(),Xe=class extends qe{constructor(e){super(e);let t=e&&e.forceBase64;this.supportsBinary=Ye&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new j(Ze,this.uri(),e)}};function Ze(e){let t=e.xdomain;try{if(typeof XMLHttpRequest<`u`&&(!t||Ge))return new XMLHttpRequest}catch{}if(!t)try{return new O.ActiveXObject(`Microsoft.XMLHTTP`)}catch{}}var Qe=typeof navigator<`u`&&typeof navigator.product==`string`&&navigator.product.toLowerCase()===`reactnative`,$e=class extends A{get name(){return`websocket`}doOpen(){let e=this.uri(),t=this.opts.protocols,n=Qe?{}:Ne(this.opts,`agent`,`perMessageDeflate`,`pfx`,`key`,`passphrase`,`cert`,`ca`,`ciphers`,`rejectUnauthorized`,`localAddress`,`protocolVersion`,`origin`,`maxPayload`,`family`,`checkServerIdentity`);this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(e,t,n)}catch(e){return this.emitReserved(`error`,e)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=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<e.length;t++){let n=e[t],r=t===e.length-1;x(n,this.supportsBinary,e=>{try{this.doWrite(n,e)}catch{}r&&D(()=>{this.writable=!0,this.emitReserved(`drain`)},this.setTimeoutFn)})}}doClose(){this.ws!==void 0&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){let e=this.opts.secure?`wss`:`ws`,t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=ze()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}},M=O.WebSocket||O.MozWebSocket,et={websocket:class extends $e{createSocket(e,t,n){return Qe?new M(e,t,n):t?new M(e,t):new M(e)}doWrite(e,t){this.ws.send(t)}},webtransport:class extends A{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=>{let t=Ae(2**53-1,this.socket.binaryType),n=e.readable.pipeThrough(t).getReader(),r=Oe();r.readable.pipeTo(e.writable),this._writer=r.writable.getWriter();let i=()=>{n.read().then(({done:e,value:t})=>{e||(this.onPacket(t),i())}).catch(e=>{})};i();let a={type:`open`};this.query.sid&&(a.data=`{"sid":"${this.query.sid}"}`),this._writer.write(a).then(()=>this.onOpen())})})}write(e){this.writable=!1;for(let t=0;t<e.length;t++){let n=e[t],r=t===e.length-1;this._writer.write(n).then(()=>{r&&D(()=>{this.writable=!0,this.emitReserved(`drain`)},this.setTimeoutFn)})}}doClose(){var e;(e=this._transport)==null||e.close()}},polling:Xe},tt=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,nt=[`source`,`protocol`,`authority`,`userInfo`,`user`,`password`,`host`,`port`,`relative`,`path`,`directory`,`file`,`query`,`anchor`];function N(e){if(e.length>8e3)throw`URI too long`;let t=e,n=e.indexOf(`[`),r=e.indexOf(`]`);n!=-1&&r!=-1&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,`;`)+e.substring(r,e.length));let i=tt.exec(e||``),a={},o=14;for(;o--;)a[nt[o]]=i[o]||``;return n!=-1&&r!=-1&&(a.source=t,a.host=a.host.substring(1,a.host.length-1).replace(/;/g,`:`),a.authority=a.authority.replace(`[`,``).replace(`]`,``).replace(/;/g,`:`),a.ipv6uri=!0),a.pathNames=rt(a,a.path),a.queryKey=it(a,a.query),a}function rt(e,t){let n=t.replace(/\/{2,9}/g,`/`).split(`/`);return(t.slice(0,1)==`/`||t.length===0)&&n.splice(0,1),t.slice(-1)==`/`&&n.splice(n.length-1,1),n}function it(e,t){let n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(e,t,r){t&&(n[t]=r)}),n}var P=typeof addEventListener==`function`&&typeof removeEventListener==`function`,F=[];P&&addEventListener(`offline`,()=>{F.forEach(e=>e())},!1);var I=class e extends E{constructor(e,t){if(super(),this.binaryType=Me,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,e&&typeof e==`object`&&(t=e,e=null),e){let n=N(e);t.hostname=n.host,t.secure=n.protocol===`https`||n.protocol===`wss`,t.port=n.port,n.query&&(t.query=n.query)}else t.host&&(t.hostname=N(t.host).host);k(this,t),this.secure=t.secure==null?typeof location<`u`&&location.protocol===`https:`:t.secure,t.hostname&&!t.port&&(t.port=this.secure?`443`:`80`),this.hostname=t.hostname||(typeof location<`u`?location.hostname:`localhost`),this.port=t.port||(typeof location<`u`&&location.port?location.port:this.secure?`443`:`80`),this.transports=[],this._transportsByName={},t.transports.forEach(e=>{let t=e.prototype.name;this.transports.push(t),this._transportsByName[t]=e}),this.opts=Object.assign({path:`/engine.io`,agent:!1,withCredentials:!1,upgrade:!0,timestampParam:`t`,rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,``)+(this.opts.addTrailingSlash?`/`:``),typeof this.opts.query==`string`&&(this.opts.query=Ve(this.opts.query)),P&&(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`})},F.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(e){let t=Object.assign({},this.opts.query);t.EIO=4,t.transport=e,this.id&&(t.sid=this.id);let n=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](n)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved(`error`,`No transports available`)},0);return}let t=this.opts.rememberUpgrade&&e.priorWebsocketSuccess&&this.transports.indexOf(`websocket`)!==-1?`websocket`:this.transports[0];this.readyState=`opening`;let n=this.createTransport(t);n.open(),this.setTransport(n)}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`,e=>this._onClose(`transport close`,e))}onOpen(){this.readyState=`open`,e.priorWebsocketSuccess=this.transport.name===`websocket`,this.emitReserved(`open`),this.flush()}_onPacket(e){if(this.readyState===`opening`||this.readyState===`open`||this.readyState===`closing`)switch(this.emitReserved(`packet`,e),this.emitReserved(`heartbeat`),e.type){case`open`:this.onHandshake(JSON.parse(e.data));break;case`ping`:this._sendPacket(`pong`),this.emitReserved(`ping`),this.emitReserved(`pong`),this._resetPingTimeout();break;case`error`:let t=Error(`server error`);t.code=e.data,this._onError(t);break;case`message`:this.emitReserved(`data`,e.data),this.emitReserved(`message`,e.data)}}onHandshake(e){this.emitReserved(`handshake`,e),this.id=e.sid,this.transport.query.sid=e.sid,this._pingInterval=e.pingInterval,this._pingTimeout=e.pingTimeout,this._maxPayload=e.maxPayload,this.onOpen(),this.readyState!==`closed`&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let e=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+e,this._pingTimeoutTimer=this.setTimeoutFn(()=>{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){let 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 e=1;for(let t=0;t<this.writeBuffer.length;t++){let n=this.writeBuffer[t].data;if(n&&(e+=Le(n)),t>0&&e>this._maxPayload)return this.writeBuffer.slice(0,t);e+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;let e=Date.now()>this._pingTimeoutTime;return e&&(this._pingTimeoutTime=0,D(()=>{this._onClose(`ping timeout`)},this.setTimeoutFn)),e}write(e,t,n){return this._sendPacket(`message`,e,t,n),this}send(e,t,n){return this._sendPacket(`message`,e,t,n),this}_sendPacket(e,t,n,r){if(typeof t==`function`&&(r=t,t=void 0),typeof n==`function`&&(r=n,n=null),this.readyState===`closing`||this.readyState===`closed`)return;n||={},n.compress=!1!==n.compress;let i={type:e,data:t,options:n};this.emitReserved(`packetCreate`,i),this.writeBuffer.push(i),r&&this.once(`flush`,r),this.flush()}close(){let e=()=>{this._onClose(`forced close`),this.transport.close()},t=()=>{this.off(`upgrade`,t),this.off(`upgradeError`,t),e()},n=()=>{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?n():e()}):this.upgrading?n():e()),this}_onError(t){if(e.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState===`opening`)return this.transports.shift(),this._open();this.emitReserved(`error`,t),this._onClose(`transport error`,t)}_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(),P&&(this._beforeunloadEventListener&&removeEventListener(`beforeunload`,this._beforeunloadEventListener,!1),this._offlineEventListener)){let e=F.indexOf(this._offlineEventListener);e!==-1&&F.splice(e,1)}this.readyState=`closed`,this.id=null,this.emitReserved(`close`,e,t),this.writeBuffer=[],this._prevBufferLen=0}}};I.protocol=4;var at=class extends I{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState===`open`&&this.opts.upgrade)for(let e=0;e<this._upgrades.length;e++)this._probe(this._upgrades[e])}_probe(e){let t=this.createTransport(e),n=!1;I.priorWebsocketSuccess=!1;let r=()=>{n||(t.send([{type:`ping`,data:`probe`}]),t.once(`packet`,e=>{if(!n){if(e.type===`pong`&&e.data===`probe`){if(this.upgrading=!0,this.emitReserved(`upgrading`,t),!t)return;I.priorWebsocketSuccess=t.name===`websocket`,this.transport.pause(()=>{n||this.readyState!==`closed`&&(l(),this.setTransport(t),t.send([{type:`upgrade`}]),this.emitReserved(`upgrade`,t),t=null,this.upgrading=!1,this.flush())})}else{let e=Error(`probe error`);e.transport=t.name,this.emitReserved(`upgradeError`,e)}}}))};function i(){n||(n=!0,l(),t.close(),t=null)}let a=e=>{let n=Error(`probe error: `+e);n.transport=t.name,i(),this.emitReserved(`upgradeError`,n)};function o(){a(`transport closed`)}function s(){a(`socket closed`)}function c(e){t&&e.name!==t.name&&i()}let l=()=>{t.removeListener(`open`,r),t.removeListener(`error`,a),t.removeListener(`close`,o),this.off(`close`,s),this.off(`upgrading`,c)};t.once(`open`,r),t.once(`error`,a),t.once(`close`,o),this.once(`close`,s),this.once(`upgrading`,c),this._upgrades.indexOf(`webtransport`)!==-1&&e!==`webtransport`?this.setTimeoutFn(()=>{n||t.open()},200):t.open()}onHandshake(e){this._upgrades=this._filterUpgrades(e.upgrades),super.onHandshake(e)}_filterUpgrades(e){let t=[];for(let n=0;n<e.length;n++)~this.transports.indexOf(e[n])&&t.push(e[n]);return t}},ot=class extends at{constructor(e,t={}){let n=typeof e==`object`,r=n?{...e}:{...t};(!r.transports||r.transports&&typeof r.transports[0]==`string`)&&(r.transports=(r.transports||[`polling`,`websocket`,`webtransport`]).map(e=>et[e]).filter(e=>!!e)),super(n?r:e,r)}};ot.protocol;function st(e,t=``,n){let r=e;n||=typeof location<`u`&&location,e??=n.protocol+`//`+n.host,typeof e==`string`&&(e.charAt(0)===`/`&&(e=e.charAt(1)===`/`?n.protocol+e:n.host+e),/^(https?|wss?):\/\//.test(e)||(e=n===void 0?`https://`+e:n.protocol+`//`+e),r=N(e)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port=`80`:/^(http|ws)s$/.test(r.protocol)&&(r.port=`443`)),r.path=r.path||`/`;let i=r.host.indexOf(`:`)===-1?r.host:`[`+r.host+`]`;return r.id=r.protocol+`://`+i+`:`+r.port+t,r.href=r.protocol+`://`+i+(n&&n.port===r.port?``:`:`+r.port),r}var ct=typeof ArrayBuffer==`function`,lt=e=>typeof ArrayBuffer.isView==`function`?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,ut=Object.prototype.toString,dt=typeof Blob==`function`||typeof Blob<`u`&&ut.call(Blob)===`[object BlobConstructor]`,ft=typeof File==`function`||typeof File<`u`&&ut.call(File)===`[object FileConstructor]`;function L(e){return ct&&(e instanceof ArrayBuffer||lt(e))||dt&&e instanceof Blob||ft&&e instanceof File}function R(e,t){if(!e||typeof e!=`object`)return!1;if(Array.isArray(e)){for(let t=0,n=e.length;t<n;t++)if(R(e[t]))return!0;return!1}if(L(e))return!0;if(e.toJSON&&typeof e.toJSON==`function`&&arguments.length===1)return R(e.toJSON(),!0);for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t)&&R(e[t]))return!0;return!1}function pt(e){let t=[],n=e.data,r=e;return r.data=z(n,t),r.attachments=t.length,{packet:r,buffers:t}}function z(e,t,n){if(!e)return e;if(L(e)){let n={_placeholder:!0,num:t.length};return t.push(e),n}if(Array.isArray(e)){let n=Array(e.length);for(let r=0;r<e.length;r++)n[r]=z(e[r],t);return n}if(typeof e==`object`&&!(e instanceof Date)){if(e.toJSON&&typeof e.toJSON==`function`&&!n)return z(e.toJSON(),t,!0);let r={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=z(e[n],t));return r}return e}function mt(e,t){return e.data=B(e.data,t),delete e.attachments,e}function B(e,t){if(!e)return e;if(e&&e._placeholder===!0){if(typeof e.num==`number`&&e.num>=0&&e.num<t.length)return t[e.num];throw Error(`illegal attachments`)}if(Array.isArray(e))for(let n=0;n<e.length;n++)e[n]=B(e[n],t);else if(typeof e==`object`)for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(e[n]=B(e[n],t));return e}var ht=t({Decoder:()=>vt,Encoder:()=>_t,PacketType:()=>V,isPacketValid:()=>wt,protocol:()=>5}),gt=[`connect`,`connect_error`,`disconnect`,`disconnecting`,`newListener`,`removeListener`],V;(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`})(V||={});var _t=class{constructor(e){this.replacer=e}encode(e){return(e.type===V.EVENT||e.type===V.ACK)&&R(e)?this.encodeAsBinary({type:e.type===V.EVENT?V.BINARY_EVENT:V.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let t=``+e.type;return(e.type===V.BINARY_EVENT||e.type===V.BINARY_ACK)&&(t+=e.attachments+`-`),e.nsp&&e.nsp!==`/`&&(t+=e.nsp+`,`),e.id!=null&&(t+=e.id),e.data!=null&&(t+=JSON.stringify(e.data,this.replacer)),t}encodeAsBinary(e){let t=pt(e),n=this.encodeAsString(t.packet),r=t.buffers;return r.unshift(n),r}},vt=class e extends E{constructor(e){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},typeof e==`function`?{reviver:e}:e)}add(e){let t;if(typeof e==`string`){if(this.reconstructor)throw Error(`got plaintext data when reconstructing a packet`);t=this.decodeString(e);let n=t.type===V.BINARY_EVENT;n||t.type===V.BINARY_ACK?(t.type=n?V.EVENT:V.ACK,this.reconstructor=new yt(t)):super.emitReserved(`decoded`,t)}else if(L(e)||e.base64){if(this.reconstructor)t=this.reconstructor.takeBinaryData(e),t&&(this.reconstructor=null,super.emitReserved(`decoded`,t));else throw Error(`got binary data when not reconstructing a packet`)}else throw Error(`Unknown type: `+e)}decodeString(t){let n=0,r={type:Number(t.charAt(0))};if(V[r.type]===void 0)throw Error(`unknown packet type `+r.type);if(r.type===V.BINARY_EVENT||r.type===V.BINARY_ACK){let e=n+1;for(;t.charAt(++n)!==`-`&&n!=t.length;);let i=t.substring(e,n);if(i!=Number(i)||t.charAt(n)!==`-`)throw Error(`Illegal attachments`);let a=Number(i);if(!xt(a)||a<1)throw Error(`Illegal attachments`);if(a>this.opts.maxAttachments)throw Error(`too many attachments`);r.attachments=a}if(t.charAt(n+1)===`/`){let e=n+1;for(;++n&&t.charAt(n)!==`,`&&n!==t.length;);r.nsp=t.substring(e,n)}else r.nsp=`/`;let i=t.charAt(n+1);if(i!==``&&Number(i)==i){let e=n+1;for(;++n;){let e=t.charAt(n);if(e==null||Number(e)!=e){--n;break}if(n===t.length)break}r.id=Number(t.substring(e,n+1))}if(t.charAt(++n)){let i=this.tryParse(t.substr(n));if(e.isPayloadValid(r.type,i))r.data=i;else throw Error(`invalid payload`)}return r}tryParse(e){try{return JSON.parse(e,this.opts.reviver)}catch{return!1}}static isPayloadValid(e,t){switch(e){case V.CONNECT:return H(t);case V.DISCONNECT:return t===void 0;case V.CONNECT_ERROR:return typeof t==`string`||H(t);case V.EVENT:case V.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]==`number`||typeof t[0]==`string`&&gt.indexOf(t[0])===-1);case V.ACK:case V.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&=(this.reconstructor.finishedReconstruction(),null)}},yt=class{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){let e=mt(this.reconPack,this.buffers);return this.finishedReconstruction(),e}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};function bt(e){return typeof e==`string`}var xt=Number.isInteger||function(e){return typeof e==`number`&&isFinite(e)&&Math.floor(e)===e};function St(e){return e===void 0||xt(e)}function H(e){return Object.prototype.toString.call(e)===`[object Object]`}function Ct(e,t){switch(e){case V.CONNECT:return t===void 0||H(t);case V.DISCONNECT:return t===void 0;case V.EVENT:return Array.isArray(t)&&(typeof t[0]==`number`||typeof t[0]==`string`&&gt.indexOf(t[0])===-1);case V.ACK:return Array.isArray(t);case V.CONNECT_ERROR:return typeof t==`string`||H(t);default:return!1}}function wt(e){return bt(e.nsp)&&St(e.id)&&Ct(e.type,e.data)}function U(e,t,n){return e.on(t,n),function(){e.off(t,n)}}var Tt=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),Et=class extends E{constructor(e,t,n){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,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;let e=this.io;this.subs=[U(e,`open`,this.onopen.bind(this)),U(e,`packet`,this.onpacket.bind(this)),U(e,`error`,this.onerror.bind(this)),U(e,`close`,this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(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){if(Tt.hasOwnProperty(e))throw 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;let n={type:V.EVENT,data:t};if(n.options={},n.options.compress=this.flags.compress!==!1,typeof t[t.length-1]==`function`){let e=this.ids++,r=t.pop();this._registerAckCallback(e,r),n.id=e}let r=this.io.engine?.transport?.writable,i=this.connected&&!this.io.engine?._hasPingExpired();return this.flags.volatile&&!r||(i?(this.notifyOutgoingListeners(n),this.packet(n)):this.sendBuffer.push(n)),this.flags={},this}_registerAckCallback(e,t){let n=this.flags.timeout??this._opts.ackTimeout;if(n===void 0){this.acks[e]=t;return}let r=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let t=0;t<this.sendBuffer.length;t++)this.sendBuffer[t].id===e&&this.sendBuffer.splice(t,1);t.call(this,Error(`operation has timed out`))},n),i=(...e)=>{this.io.clearTimeoutFn(r),t.apply(this,e)};i.withError=!0,this.acks[e]=i}emitWithAck(e,...t){return new Promise((n,r)=>{let i=(e,t)=>e?r(e):n(t);i.withError=!0,t.push(i),this.emit(e,...t)})}_addToQueue(e){let t;typeof e[e.length-1]==`function`&&(t=e.pop());let n={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((e,...r)=>(this._queue[0],e===null?(this._queue.shift(),t&&t(null,...r)):n.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(e)),n.pending=!1,this._drainQueue())),this._queue.push(n),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||this._queue.length===0)return;let 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:V.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(t=>String(t.id)===e)){let t=this.acks[e];delete this.acks[e],t.withError&&t.call(this,Error(`socket has been disconnected`))}})}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case V.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved(`connect_error`,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 V.EVENT:case V.BINARY_EVENT:this.onevent(e);break;case V.ACK:case V.BINARY_ACK:this.onack(e);break;case V.DISCONNECT:this.ondisconnect();break;case V.CONNECT_ERROR:this.destroy();let t=Error(e.data.message);t.data=e.data.data,this.emitReserved(`connect_error`,t)}}onevent(e){let 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){let t=this._anyListeners.slice();for(let n of t)n.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){let t=this,n=!1;return function(...r){n||(n=!0,t.packet({type:V.ACK,id:e,data:r}))}}onack(e){let 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()),void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:V.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){let t=this._anyListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){let t=this._anyOutgoingListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){let t=this._anyOutgoingListeners.slice();for(let n of t)n.apply(this,e.data)}}};function W(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}W.prototype.duration=function(){var e=this.ms*this.factor**+this.attempts++;if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=Math.floor(t*10)&1?e+n:e-n}return Math.min(e,this.max)|0},W.prototype.reset=function(){this.attempts=0},W.prototype.setMin=function(e){this.ms=e},W.prototype.setMax=function(e){this.max=e},W.prototype.setJitter=function(e){this.jitter=e};var G=class extends E{constructor(e,t){super(),this.nsps={},this.subs=[],e&&typeof e==`object`&&(t=e,e=void 0),t||={},t.path=t.path||`/socket.io`,this.opts=t,k(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(t.randomizationFactor??.5),this.backoff=new W({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(t.timeout==null?2e4:t.timeout),this._readyState=`closed`,this.uri=e;let n=t.parser||ht;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.setMin(e),this)}randomizationFactor(e){var t;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(t=this.backoff)==null||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(t=this.backoff)==null||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 ot(this.uri,this.opts);let t=this.engine,n=this;this._readyState=`opening`,this.skipReconnect=!1;let r=U(t,`open`,function(){n.onopen(),e&&e()}),i=t=>{this.cleanup(),this._readyState=`closed`,this.emitReserved(`error`,t),e?e(t):this.maybeReconnectOnOpen()},a=U(t,`error`,i);if(!1!==this._timeout){let e=this._timeout,n=this.setTimeoutFn(()=>{r(),i(Error(`timeout`)),t.close()},e);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}return this.subs.push(r),this.subs.push(a),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState=`open`,this.emitReserved(`open`);let e=this.engine;this.subs.push(U(e,`ping`,this.onping.bind(this)),U(e,`data`,this.ondata.bind(this)),U(e,`error`,this.onerror.bind(this)),U(e,`close`,this.onclose.bind(this)),U(this.decoder,`decoded`,this.ondecoded.bind(this)))}onping(){this.emitReserved(`ping`)}ondata(e){try{this.decoder.add(e)}catch(e){this.onclose(`parse error`,e)}}ondecoded(e){D(()=>{this.emitReserved(`packet`,e)},this.setTimeoutFn)}onerror(e){this.emitReserved(`error`,e)}socket(e,t){let n=this.nsps[e];return n?this._autoConnect&&!n.active&&n.connect():(n=new Et(this,e,t),this.nsps[e]=n),n}_destroy(e){let t=Object.keys(this.nsps);for(let e of t)if(this.nsps[e].active)return;this._close()}_packet(e){let t=this.encoder.encode(e);for(let n=0;n<t.length;n++)this.engine.write(t[n],e.options)}cleanup(){this.subs.forEach(e=>e()),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 n;this.cleanup(),(n=this.engine)==null||n.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;let e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved(`reconnect_failed`),this._reconnecting=!1;else{let t=this.backoff.duration();this._reconnecting=!0;let n=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved(`reconnect_attempt`,e.backoff.attempts),!e.skipReconnect&&e.open(t=>{t?(e._reconnecting=!1,e.reconnect(),this.emitReserved(`reconnect_error`,t)):e.onreconnect()}))},t);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}}onreconnect(){let e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved(`reconnect`,e)}},K={};function q(e,t){typeof e==`object`&&(t=e,e=void 0),t||={};let n=st(e,t.path||`/socket.io`),r=n.source,i=n.id,a=n.path,o=K[i]&&a in K[i].nsps,s=t.forceNew||t[`force new connection`]||!1===t.multiplex||o,c;return s?c=new G(r,t):(K[i]||(K[i]=new G(r,t)),c=K[i]),n.query&&!t.query&&(t.query=n.queryKey),c.socket(n.path,t)}Object.assign(q,{Manager:G,Socket:Et,io:q,connect:q});function Dt(e){let t=e.replace(/\/$/,``);try{return`${new URL(t).origin}/sdk`}catch{return`${t}/sdk`}}var Ot=class{constructor(){this.socket=null}get connected(){return this.socket?.connected??!1}connect(e){this.disconnect();let t=Dt(e.baseUrl);this.socket=q(t,{auth:{apiKey:e.apiKey,visitorToken:e.visitorToken},transports:[`websocket`,`polling`],autoConnect:!0,reconnection:!0});let n=!1;this.socket.on(`connect`,()=>{n?e.onReconnect?.():n=!0}),this.socket.on(`ticket:status`,t=>{e.onTicketStatus?.(t)}),this.socket.on(`message:receive`,t=>{e.onMessageReceive?.(t)}),this.socket.on(`connect_error`,t=>{e.onConnectError?.(t)})}disconnect(){this.socket&&=(this.socket.removeAllListeners(),this.socket.disconnect(),null)}},J=`onedeskpro_visitor_token`;function kt(e){try{return typeof window<`u`?window.localStorage.getItem(e):null}catch{return null}}function At(e,t){try{typeof window<`u`&&window.localStorage.setItem(e,t)}catch{}}function jt(e){try{typeof window<`u`&&window.localStorage.removeItem(e)}catch{}}var Mt=class{constructor(){this.token=null,this.storageKey=J}setScope(e){this.storageKey=e?.trim()?`${J}:${e.trim()}`:J,this.token=kt(this.storageKey)}get(){return this.token??kt(this.storageKey)}set(e){this.token=e,At(this.storageKey,e)}clear(){this.token=null,jt(this.storageKey)}},Nt=300,Pt=250,Ft=100,It=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg;codecs=opus`];function Lt(){return typeof MediaRecorder>`u`||typeof MediaRecorder.isTypeSupported!=`function`?`audio/webm`:It.find(e=>MediaRecorder.isTypeSupported(e))??`audio/webm`}function Rt(e){let t=e instanceof DOMException?e.name:``;return t===`NotAllowedError`||t===`PermissionDeniedError`||t===`SecurityError`?`Microphone access was denied.`:t===`NotFoundError`||t===`DevicesNotFoundError`?`No microphone was found.`:`Could not start recording.`}var Y=class e{constructor(e,t=300){this.onChange=e,this.maxDurationSeconds=t,this.recorder=null,this.stream=null,this.chunks=[],this.mimeType=`audio/webm`,this.startedAt=0,this.tickTimer=null,this.levelTimer=null,this.maxTimer=null,this.audioContext=null,this.analyser=null,this.snapshot={state:`idle`,elapsedSeconds:0,level:0,result:null}}static isSupported(){return typeof navigator<`u`&&typeof navigator.mediaDevices?.getUserMedia==`function`&&typeof MediaRecorder<`u`}getSnapshot(){return{...this.snapshot}}async start(){if(!e.isSupported())throw Error(`Voice messages are not supported in this browser.`);this.release(),this.chunks=[];let t;try{t=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){throw Error(Rt(e))}try{this.mimeType=Lt();let e=new MediaRecorder(t,{mimeType:this.mimeType});e.ondataavailable=e=>{e.data.size>0&&this.chunks.push(e.data)},this.stream=t,this.recorder=e,this.startedAt=Date.now(),e.start(200)}catch(e){throw t.getTracks().forEach(e=>e.stop()),this.stream=null,this.recorder=null,Error(Rt(e))}this.startLevelMeter(t),this.tickTimer=setInterval(()=>{this.update({elapsedSeconds:Math.floor(this.elapsedMs()/1e3)})},Pt),this.maxTimer=setTimeout(()=>void this.stop(),this.maxDurationSeconds*1e3),this.update({state:`recording`,elapsedSeconds:0,level:0,result:null})}async stop(){let e=this.recorder;if(!e||e.state===`inactive`)return this.release(),null;let t=Math.max(1,Math.round(this.elapsedMs()/1e3));this.clearTimers();let n=await new Promise(t=>{e.onstop=()=>{let e=this.chunks;this.chunks=[],t(new Blob(e,{type:g(this.mimeType)}))};try{e.stop()}catch{t(new Blob(this.chunks,{type:g(this.mimeType)}))}});this.releaseMedia();let r={blob:n,mimeType:g(this.mimeType),durationSeconds:t};return this.update({state:`preview`,elapsedSeconds:t,level:0,result:r}),r}cancel(){this.release(),this.update({state:`idle`,elapsedSeconds:0,level:0,result:null})}destroy(){this.release(),this.snapshot={state:`idle`,elapsedSeconds:0,level:0,result:null}}update(e){this.snapshot={...this.snapshot,...e},this.onChange({...this.snapshot})}elapsedMs(){return this.startedAt>0?Date.now()-this.startedAt:0}startLevelMeter(e){let t=typeof window>`u`?null:window,n=t?.AudioContext??t?.webkitAudioContext;if(n)try{let t=new n,r=t.createAnalyser();r.fftSize=256,t.createMediaStreamSource(e).connect(r),t.resume().catch(()=>void 0),this.audioContext=t,this.analyser=r;let i=new Uint8Array(r.frequencyBinCount);this.levelTimer=setInterval(()=>{r.getByteTimeDomainData(i);let e=0;for(let t=0;t<i.length;t++){let n=((i[t]??128)-128)/128;e+=n*n}this.update({level:Math.min(1,Math.sqrt(e/i.length)*3.2)})},Ft)}catch{}}clearTimers(){this.tickTimer&&clearInterval(this.tickTimer),this.levelTimer&&clearInterval(this.levelTimer),this.maxTimer&&clearTimeout(this.maxTimer),this.tickTimer=null,this.levelTimer=null,this.maxTimer=null}releaseMedia(){this.stream?.getTracks().forEach(e=>e.stop()),this.stream=null,this.recorder=null,this.analyser=null,this.audioContext&&=(this.audioContext.close().catch(()=>void 0),null),this.startedAt=0}release(){if(this.clearTimers(),this.recorder&&this.recorder.state!==`inactive`){this.recorder.onstop=null;try{this.recorder.stop()}catch{}}this.chunks=[],this.releaseMedia()}},X=[{iso:`BD`,name:`Bangladesh`,dial:`880`,flag:`🇧🇩`},{iso:`US`,name:`United States`,dial:`1`,flag:`🇺🇸`},{iso:`GB`,name:`United Kingdom`,dial:`44`,flag:`🇬🇧`},{iso:`IN`,name:`India`,dial:`91`,flag:`🇮🇳`},{iso:`PK`,name:`Pakistan`,dial:`92`,flag:`🇵🇰`},{iso:`AE`,name:`United Arab Emirates`,dial:`971`,flag:`🇦🇪`},{iso:`SA`,name:`Saudi Arabia`,dial:`966`,flag:`🇸🇦`},{iso:`CA`,name:`Canada`,dial:`1`,flag:`🇨🇦`},{iso:`AU`,name:`Australia`,dial:`61`,flag:`🇦🇺`},{iso:`DE`,name:`Germany`,dial:`49`,flag:`🇩🇪`},{iso:`FR`,name:`France`,dial:`33`,flag:`🇫🇷`},{iso:`IT`,name:`Italy`,dial:`39`,flag:`🇮🇹`},{iso:`ES`,name:`Spain`,dial:`34`,flag:`🇪🇸`},{iso:`NL`,name:`Netherlands`,dial:`31`,flag:`🇳🇱`},{iso:`SE`,name:`Sweden`,dial:`46`,flag:`🇸🇪`},{iso:`NO`,name:`Norway`,dial:`47`,flag:`🇳🇴`},{iso:`DK`,name:`Denmark`,dial:`45`,flag:`🇩🇰`},{iso:`FI`,name:`Finland`,dial:`358`,flag:`🇫🇮`},{iso:`IE`,name:`Ireland`,dial:`353`,flag:`🇮🇪`},{iso:`CH`,name:`Switzerland`,dial:`41`,flag:`🇨🇭`},{iso:`AT`,name:`Austria`,dial:`43`,flag:`🇦🇹`},{iso:`BE`,name:`Belgium`,dial:`32`,flag:`🇧🇪`},{iso:`PT`,name:`Portugal`,dial:`351`,flag:`🇵🇹`},{iso:`PL`,name:`Poland`,dial:`48`,flag:`🇵🇱`},{iso:`CZ`,name:`Czechia`,dial:`420`,flag:`🇨🇿`},{iso:`RO`,name:`Romania`,dial:`40`,flag:`🇷🇴`},{iso:`HU`,name:`Hungary`,dial:`36`,flag:`🇭🇺`},{iso:`GR`,name:`Greece`,dial:`30`,flag:`🇬🇷`},{iso:`TR`,name:`Turkey`,dial:`90`,flag:`🇹🇷`},{iso:`RU`,name:`Russia`,dial:`7`,flag:`🇷🇺`},{iso:`UA`,name:`Ukraine`,dial:`380`,flag:`🇺🇦`},{iso:`CN`,name:`China`,dial:`86`,flag:`🇨🇳`},{iso:`JP`,name:`Japan`,dial:`81`,flag:`🇯🇵`},{iso:`KR`,name:`South Korea`,dial:`82`,flag:`🇰🇷`},{iso:`SG`,name:`Singapore`,dial:`65`,flag:`🇸🇬`},{iso:`MY`,name:`Malaysia`,dial:`60`,flag:`🇲🇾`},{iso:`ID`,name:`Indonesia`,dial:`62`,flag:`🇮🇩`},{iso:`TH`,name:`Thailand`,dial:`66`,flag:`🇹🇭`},{iso:`VN`,name:`Vietnam`,dial:`84`,flag:`🇻🇳`},{iso:`PH`,name:`Philippines`,dial:`63`,flag:`🇵🇭`},{iso:`HK`,name:`Hong Kong`,dial:`852`,flag:`🇭🇰`},{iso:`TW`,name:`Taiwan`,dial:`886`,flag:`🇹🇼`},{iso:`NZ`,name:`New Zealand`,dial:`64`,flag:`🇳🇿`},{iso:`ZA`,name:`South Africa`,dial:`27`,flag:`🇿🇦`},{iso:`NG`,name:`Nigeria`,dial:`234`,flag:`🇳🇬`},{iso:`KE`,name:`Kenya`,dial:`254`,flag:`🇰🇪`},{iso:`EG`,name:`Egypt`,dial:`20`,flag:`🇪🇬`},{iso:`MA`,name:`Morocco`,dial:`212`,flag:`🇲🇦`},{iso:`BR`,name:`Brazil`,dial:`55`,flag:`🇧🇷`},{iso:`MX`,name:`Mexico`,dial:`52`,flag:`🇲🇽`},{iso:`AR`,name:`Argentina`,dial:`54`,flag:`🇦🇷`},{iso:`CL`,name:`Chile`,dial:`56`,flag:`🇨🇱`},{iso:`CO`,name:`Colombia`,dial:`57`,flag:`🇨🇴`},{iso:`PE`,name:`Peru`,dial:`51`,flag:`🇵🇪`},{iso:`IL`,name:`Israel`,dial:`972`,flag:`🇮🇱`},{iso:`QA`,name:`Qatar`,dial:`974`,flag:`🇶🇦`},{iso:`KW`,name:`Kuwait`,dial:`965`,flag:`🇰🇼`},{iso:`BH`,name:`Bahrain`,dial:`973`,flag:`🇧🇭`},{iso:`OM`,name:`Oman`,dial:`968`,flag:`🇴🇲`},{iso:`LK`,name:`Sri Lanka`,dial:`94`,flag:`🇱🇰`},{iso:`NP`,name:`Nepal`,dial:`977`,flag:`🇳🇵`}],zt=X.find(e=>e.iso===`BD`)??X[0];function Bt(e,t){let n=t.trim();if(n.startsWith(`+`)){let e=n.replace(/\D/g,``);return e?`+${e}`:``}let r=n.replace(/\D/g,``);return!r||(r=r.replace(/^0+/,``),!r)?``:`+${e}${r}`}var Vt=`(max-width: 640px), (max-height: 500px) and (pointer: coarse)`;function Ht(e,t){let n=`
2
2
  --ttcb-bg: #ffffff;
3
3
  --ttcb-bg-secondary: #f3f4f6;
4
4
  --ttcb-text: #111827;
@@ -761,7 +761,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
761
761
  </svg>`}function dn(){return`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg">
762
762
  <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
763
763
  <polyline points="14 2 14 8 20 8"/>
764
- </svg>`}function fn(e){let t=f(e.url)?e.url:``,n=e.type.toLowerCase();if(t&&n.startsWith(`image/`)){let n=document.createElement(`a`);n.className=`ttcb-attachment ttcb-attachment-image`,n.href=t,n.target=`_blank`,n.rel=`noopener noreferrer`,n.setAttribute(`aria-label`,`Open ${e.fileName}`);let r=document.createElement(`img`);return r.src=t,r.alt=e.fileName,r.loading=`lazy`,n.appendChild(r),n}if(t&&n.startsWith(`video/`)){let n=document.createElement(`video`);return n.className=`ttcb-attachment ttcb-attachment-video`,n.controls=!0,n.preload=`metadata`,n.src=t,n.setAttribute(`aria-label`,e.fileName),n}if(t&&n.startsWith(`audio/`)){let n=document.createElement(`div`);n.className=`ttcb-attachment ttcb-attachment-voice`;let r=document.createElement(`audio`);if(r.className=`ttcb-attachment-audio`,r.controls=!0,r.preload=`metadata`,r.src=t,r.setAttribute(`aria-label`,e.fileName),n.appendChild(r),typeof e.durationSeconds==`number`&&e.durationSeconds>0){let t=document.createElement(`span`);t.className=`ttcb-attachment-duration`,t.textContent=_(e.durationSeconds),n.appendChild(t)}return n}let r=document.createElement(t?`a`:`div`);r.className=`ttcb-attachment ttcb-attachment-file`,r instanceof HTMLAnchorElement&&(r.href=t,r.target=`_blank`,r.rel=`noopener noreferrer`);let i=document.createElement(`span`);i.className=`ttcb-attachment-icon`,i.setAttribute(`aria-hidden`,`true`),i.innerHTML=dn();let a=document.createElement(`span`);a.className=`ttcb-attachment-meta`;let o=document.createElement(`span`);o.className=`ttcb-attachment-name`,o.textContent=e.fileName,a.appendChild(o);let s=te(e.size);if(s){let e=document.createElement(`span`);e.className=`ttcb-attachment-size`,e.textContent=s,a.appendChild(e)}return r.appendChild(i),r.appendChild(a),r}function pn(e){let{type:t,content:n}=e,r=e.attachments??[],i=document.createElement(`div`);i.className=`ttcb-msg ${t}`,e.pending&&i.classList.add(`ttcb-pending`);let a=document.createElement(`div`);a.className=`ttcb-msg-avatar`,a.innerHTML=t===`human`?Yt():t===`agent`?Xt():Z();let o=document.createElement(`div`);if(o.className=`ttcb-msg-body`,t===`agent`){let e=document.createElement(`span`);e.className=`ttcb-msg-label`,e.textContent=`Agent`,o.appendChild(e)}if(r.length>0){let e=document.createElement(`div`);e.className=`ttcb-attachments`;for(let t of r)e.appendChild(fn(t));o.appendChild(e)}if(r.length===0||!re(n,r)){let e=document.createElement(`div`);e.className=`ttcb-bubble`,t===`human`?e.textContent=n:e.innerHTML=Wt(n),o.appendChild(e)}if(e.pending){let e=document.createElement(`span`);e.className=`ttcb-msg-status`,e.textContent=`Uploading…`,o.appendChild(e)}return i.appendChild(a),i.appendChild(o),i}function mn(){let e=document.createElement(`div`);e.className=`ttcb-msg ai`,e.id=`ttcb-typing`;let t=document.createElement(`div`);t.className=`ttcb-msg-avatar`,t.innerHTML=Z();let n=document.createElement(`div`);return n.className=`ttcb-typing`,n.innerHTML=`<span></span><span></span><span></span>`,e.appendChild(t),e.appendChild(n),e}var hn=[`image/jpeg`,`image/png`,`image/gif`,`video/mp4`,`video/webm`,`audio/ogg`,`audio/mpeg`,`audio/wav`,`audio/x-m4a`,`audio/aac`,`audio/opus`,`application/pdf`,`text/csv`].join(`,`),gn=`image/jpeg,image/png,image/gif`,_n=class{constructor(e,t){this.stopViewportSync=null,this.pendingFiles=[],this.attachMenuOpen=!1,this.recorder=null,this.voicePreviewUrl=``,this.selectedCountry=zt,this.countryOpen=!1,this.isOpen=!1,this.destroyed=!1,this.position=e.position??`bottom-right`,this.callbacks=t,this.autoOpen=e.autoOpen===!0,this.mount(e)}mount(e){this.host=document.createElement(`div`),this.host.id=`onedeskpro-chatbot-host`,this.host.style.display=`none`,this.shadow=this.host.attachShadow({mode:`closed`});let t=document.createElement(`style`);t.textContent=Ht(e.primaryColor??`#2563EB`,e.theme??`auto`),this.shadow.appendChild(t),this.fab=document.createElement(`button`),this.fab.className=`ttcb-fab ${this.position}`,this.fab.setAttribute(`aria-label`,`Open chat`),this.fab.innerHTML=Kt(),this.fab.addEventListener(`click`,()=>this.toggle()),this.shadow.appendChild(this.fab),this.panel=document.createElement(`div`),this.panel.className=`ttcb-panel ${this.position} hidden ttcb-mode-compact`,this.panel.tabIndex=-1,this.panel.setAttribute(`role`,`dialog`),this.panel.setAttribute(`aria-modal`,`true`),this.panel.setAttribute(`aria-label`,e.chatbotName??`AI Assistant`),this.panel.appendChild(this.buildHeader(e)),this.identifyContainer=document.createElement(`div`),this.identifyContainer.className=`ttcb-identify`,this.buildIdentifyForm(this.identifyContainer),this.panel.appendChild(this.identifyContainer),this.messagesContainer=document.createElement(`div`),this.messagesContainer.className=`ttcb-messages`,this.messagesContainer.setAttribute(`aria-live`,`polite`),this.messagesContainer.setAttribute(`aria-label`,`Chat messages`),this.panel.appendChild(this.messagesContainer),this.modeBanner=document.createElement(`div`),this.modeBanner.className=`ttcb-mode-banner`,this.modeBanner.setAttribute(`role`,`status`),this.panel.appendChild(this.modeBanner),this.footer=document.createElement(`div`),this.footer.className=`ttcb-footer`,this.pendingTray=document.createElement(`div`),this.pendingTray.className=`ttcb-pending-tray`,this.pendingTray.setAttribute(`role`,`list`),this.pendingTray.setAttribute(`aria-label`,`Files to send`),this.footer.appendChild(this.pendingTray),this.composeError=document.createElement(`p`),this.composeError.className=`ttcb-compose-error`,this.composeError.setAttribute(`role`,`alert`),this.footer.appendChild(this.composeError),this.footer.appendChild(this.buildVoiceBar()),this.footer.appendChild(this.buildVoicePreview());let n=document.createElement(`form`);n.className=`ttcb-form`,n.addEventListener(`submit`,e=>{e.preventDefault(),this.handleSend()}),this.composeForm=n,n.appendChild(this.buildAttachControls()),this.input=document.createElement(`input`),this.input.type=`text`,this.input.className=`ttcb-input`,this.input.placeholder=e.placeholder??`Type your message…`,this.input.setAttribute(`aria-label`,`Message input`),this.input.setAttribute(`autocomplete`,`off`),this.sendBtn=document.createElement(`button`),this.sendBtn.type=`submit`,this.sendBtn.className=`ttcb-send-btn`,this.sendBtn.innerHTML=Jt(),this.sendBtn.setAttribute(`aria-label`,`Send message`),this.micBtn=document.createElement(`button`),this.micBtn.type=`button`,this.micBtn.className=`ttcb-mic-btn`,this.micBtn.setAttribute(`aria-label`,`Record voice message`),this.micBtn.title=`Record voice message`,this.micBtn.innerHTML=cn(),this.micBtn.addEventListener(`click`,()=>void this.startVoice()),n.appendChild(this.input),n.appendChild(this.micBtn),n.appendChild(this.sendBtn),this.footer.appendChild(n),this.panel.appendChild(this.footer),this.shadow.appendChild(this.panel),this.shadow.addEventListener(`click`,e=>{let t=e.target;this.attachMenuOpen&&!(t&&(this.attachBtn.contains(t)||this.attachMenu.contains(t)))&&this.closeAttachMenu(),this.countryOpen&&(t&&(this.dialBtn.contains(t)||this.countryPopover.contains(t))||this.closeCountryPopover())}),this.panel.addEventListener(`keydown`,e=>{e.key===`Escape`&&this.attachMenuOpen&&(e.stopPropagation(),this.closeAttachMenu(),this.attachBtn.focus())}),this.attachToDocument(),this.showInitialLoading()}reveal(){this.host.style.removeProperty(`display`),this.autoOpen&&!this.isOpen&&this.open()}buildHeader(e){let t=document.createElement(`div`);t.className=`ttcb-header`;let n=document.createElement(`div`);n.className=`ttcb-avatar-wrap`;let r=document.createElement(`div`);r.className=`ttcb-avatar`,r.innerHTML=Z(),n.appendChild(r);let i=document.createElement(`div`);i.className=`ttcb-header-main`;let a=document.createElement(`div`);a.className=`ttcb-header-title-row`,this.headerTitle=document.createElement(`span`),this.headerTitle.className=`ttcb-header-title`,this.headerTitle.textContent=e.chatbotName??`AI Assistant`;let o=document.createElement(`span`);o.className=`ttcb-verified`,o.setAttribute(`aria-label`,`Verified`),o.innerHTML=tn(),a.appendChild(this.headerTitle),a.appendChild(o);let s=document.createElement(`div`);s.className=`ttcb-header-meta`;let c=document.createElement(`span`);c.className=`ttcb-meta-online`,c.textContent=`Online`;let l=document.createElement(`span`);l.className=`ttcb-meta-sep`,l.setAttribute(`aria-hidden`,`true`);let u=document.createElement(`span`);u.className=`ttcb-meta-replies`,u.innerHTML=`${nn()}<span>Replies instantly</span>`,s.appendChild(c),s.appendChild(l),s.appendChild(u),i.appendChild(a),i.appendChild(s);let d=document.createElement(`div`);d.className=`ttcb-header-actions`,this.requestHumanBtn=document.createElement(`button`),this.requestHumanBtn.type=`button`,this.requestHumanBtn.className=`ttcb-request-human-btn hidden`,this.requestHumanBtn.id=`ttcb-request-human-btn`,this.requestHumanBtn.setAttribute(`aria-label`,`Request human agent`),this.requestHumanBtn.title=`Request human agent`,this.requestHumanBtn.innerHTML=rn(),this.requestHumanBtn.addEventListener(`click`,()=>this.callbacks.onRequestHuman()),this.newSessionBtn=document.createElement(`button`),this.newSessionBtn.className=`ttcb-new-session-btn hidden`,this.newSessionBtn.setAttribute(`aria-label`,`New conversation`),this.newSessionBtn.title=`New conversation`,this.newSessionBtn.innerHTML=Gt(),this.newSessionBtn.addEventListener(`click`,()=>this.callbacks.onReset());let f=document.createElement(`button`);return f.className=`ttcb-close-btn`,f.setAttribute(`aria-label`,`Close chat`),f.innerHTML=qt(),f.addEventListener(`click`,()=>this.close()),d.appendChild(this.requestHumanBtn),d.appendChild(this.newSessionBtn),d.appendChild(f),t.appendChild(n),t.appendChild(i),t.appendChild(d),t}buildAttachControls(){let e=document.createElement(`div`);e.className=`ttcb-attach`,this.attachBtn=document.createElement(`button`),this.attachBtn.type=`button`,this.attachBtn.className=`ttcb-attach-btn`,this.attachBtn.setAttribute(`aria-label`,`Add attachment`),this.attachBtn.setAttribute(`aria-haspopup`,`menu`),this.attachBtn.setAttribute(`aria-expanded`,`false`),this.attachBtn.title=`Add attachment`,this.attachBtn.innerHTML=an(),this.attachBtn.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this.toggleAttachMenu()}),this.attachMenu=document.createElement(`div`),this.attachMenu.className=`ttcb-attach-menu`,this.attachMenu.setAttribute(`role`,`menu`),this.attachFileInput=this.createFileInput(hn,`Choose files`),this.attachPhotoInput=this.createFileInput(gn,`Choose photos`);let t=[{label:`Attachment`,icon:on(),input:this.attachFileInput},{label:`Photo`,icon:sn(),input:this.attachPhotoInput}];for(let e of t){let t=document.createElement(`button`);t.type=`button`,t.className=`ttcb-attach-item`,t.setAttribute(`role`,`menuitem`),t.innerHTML=`${e.icon}<span>${e.label}</span>`,t.addEventListener(`click`,()=>{this.closeAttachMenu(),e.input.click()}),this.attachMenu.appendChild(t)}return e.appendChild(this.attachBtn),e.appendChild(this.attachMenu),e.appendChild(this.attachFileInput),e.appendChild(this.attachPhotoInput),e}createFileInput(e,t){let n=document.createElement(`input`);return n.type=`file`,n.multiple=!0,n.accept=e,n.className=`ttcb-file-input`,n.tabIndex=-1,n.setAttribute(`aria-label`,t),n.addEventListener(`change`,()=>{this.addPendingFiles(Array.from(n.files??[])),n.value=``}),n}toggleAttachMenu(){this.attachMenuOpen?this.closeAttachMenu():this.openAttachMenu()}openAttachMenu(){if(this.attachBtn.disabled)return;this.attachMenuOpen=!0,this.attachMenu.classList.add(`open`),this.attachBtn.setAttribute(`aria-expanded`,`true`);let e=this.attachMenu.querySelector(`.ttcb-attach-item`);queueMicrotask(()=>e?.focus())}closeAttachMenu(){this.attachMenuOpen&&(this.attachMenuOpen=!1,this.attachMenu.classList.remove(`open`),this.attachBtn.setAttribute(`aria-expanded`,`false`))}addPendingFiles(e){if(e.length===0)return;let t=d([...this.pendingFiles.map(e=>e.file),...e]);if(t)this.showComposeError(t);else{this.showComposeError(``);for(let t of e){let e=t.type.startsWith(`image/`)?p(t):``;this.pendingFiles.push({file:t,previewUrl:e})}this.renderPendingTray(),this.input.focus()}}removePendingFile(e){let[t]=this.pendingFiles.splice(e,1);t&&m(t.previewUrl),this.renderPendingTray(),this.input.focus()}clearPendingFiles(){for(let e of this.pendingFiles)m(e.previewUrl);this.pendingFiles=[],this.renderPendingTray()}renderPendingTray(){this.pendingTray.innerHTML=``,this.pendingTray.classList.toggle(`visible`,this.pendingFiles.length>0),this.pendingFiles.forEach((e,t)=>{let n=document.createElement(`div`);if(n.className=`ttcb-pending-item`,n.setAttribute(`role`,`listitem`),e.previewUrl){let t=document.createElement(`img`);t.className=`ttcb-pending-thumb`,t.src=e.previewUrl,t.alt=``,n.appendChild(t)}else{let e=document.createElement(`span`);e.className=`ttcb-pending-icon`,e.setAttribute(`aria-hidden`,`true`),e.innerHTML=dn(),n.appendChild(e)}let r=document.createElement(`span`);r.className=`ttcb-pending-name`,r.textContent=e.file.name||`attachment`,r.title=e.file.name,n.appendChild(r);let i=document.createElement(`button`);i.type=`button`,i.className=`ttcb-pending-remove`,i.setAttribute(`aria-label`,`Remove ${e.file.name||`attachment`}`),i.innerHTML=qt(),i.addEventListener(`click`,()=>this.removePendingFile(t)),n.appendChild(i),this.pendingTray.appendChild(n)})}buildVoiceBar(){this.voiceBar=document.createElement(`div`),this.voiceBar.className=`ttcb-voice-bar`,this.voiceBar.setAttribute(`role`,`group`),this.voiceBar.setAttribute(`aria-label`,`Recording voice message`);let e=document.createElement(`span`);e.className=`ttcb-voice-dot`,e.setAttribute(`aria-hidden`,`true`),this.voiceTime=document.createElement(`span`),this.voiceTime.className=`ttcb-voice-time`,this.voiceTime.setAttribute(`role`,`timer`),this.voiceTime.textContent=`0:00`;let t=document.createElement(`div`);return t.className=`ttcb-voice-meter`,t.setAttribute(`aria-hidden`,`true`),this.voiceLevel=document.createElement(`span`),this.voiceLevel.className=`ttcb-voice-level`,t.appendChild(this.voiceLevel),this.voiceCancelBtn=this.createVoiceButton(`Cancel recording`,un(),()=>this.cancelVoice()),this.voiceStopBtn=this.createVoiceButton(`Stop recording`,ln(),()=>void this.stopVoice()),this.voiceStopBtn.classList.add(`primary`),this.voiceBar.appendChild(e),this.voiceBar.appendChild(this.voiceTime),this.voiceBar.appendChild(t),this.voiceBar.appendChild(this.voiceCancelBtn),this.voiceBar.appendChild(this.voiceStopBtn),this.voiceBar}buildVoicePreview(){return this.voicePreview=document.createElement(`div`),this.voicePreview.className=`ttcb-voice-preview`,this.voicePreview.setAttribute(`role`,`group`),this.voicePreview.setAttribute(`aria-label`,`Voice message preview`),this.voiceAudio=document.createElement(`audio`),this.voiceAudio.className=`ttcb-voice-audio`,this.voiceAudio.controls=!0,this.voiceAudio.preload=`metadata`,this.voiceAudio.setAttribute(`aria-label`,`Recorded voice message`),this.voicePreviewTime=document.createElement(`span`),this.voicePreviewTime.className=`ttcb-voice-time`,this.voiceDiscardBtn=this.createVoiceButton(`Discard voice message`,un(),()=>this.cancelVoice()),this.voiceSendBtn=this.createVoiceButton(`Send voice message`,Jt(),()=>this.sendVoice()),this.voiceSendBtn.classList.add(`primary`),this.voicePreview.appendChild(this.voiceAudio),this.voicePreview.appendChild(this.voicePreviewTime),this.voicePreview.appendChild(this.voiceDiscardBtn),this.voicePreview.appendChild(this.voiceSendBtn),this.voicePreview}createVoiceButton(e,t,n){let r=document.createElement(`button`);return r.type=`button`,r.className=`ttcb-voice-btn`,r.setAttribute(`aria-label`,e),r.title=e,r.innerHTML=t,r.addEventListener(`click`,n),r}async startVoice(){if(!this.micBtn.disabled){if(this.closeAttachMenu(),this.showComposeError(``),!Y.isSupported())this.showComposeError(`Voice messages are not supported in this browser.`);else{this.recorder?.destroy(),this.recorder=new Y(e=>this.renderVoice(e));try{await this.recorder.start()}catch(e){this.showComposeError(e instanceof Error?e.message:`Could not start recording.`),this.recorder.destroy(),this.recorder=null,this.renderVoice({state:`idle`,elapsedSeconds:0,level:0,result:null})}}}}async stopVoice(){await this.recorder?.stop()}cancelVoice(){this.recorder?.cancel(),this.recorder?.destroy(),this.recorder=null,this.renderVoice({state:`idle`,elapsedSeconds:0,level:0,result:null}),this.input.focus()}sendVoice(){let e=this.recorder?.getSnapshot().result;e&&(this.cancelVoice(),this.callbacks.onSendVoice(e))}renderVoice(e){if(this.destroyed)return;let{state:t}=e;this.composeForm.classList.toggle(`hidden`,t!==`idle`),this.voiceBar.classList.toggle(`visible`,t===`recording`),this.voicePreview.classList.toggle(`visible`,t===`preview`),t===`recording`?(this.voiceTime.textContent=_(e.elapsedSeconds),this.voiceLevel.style.width=`${Math.max(4,Math.round(e.level*100))}%`):(m(this.voicePreviewUrl),this.voicePreviewUrl=``,this.voiceAudio.removeAttribute(`src`),t===`preview`&&e.result&&(this.voicePreviewUrl=p(new File([e.result.blob],`voice-preview`,{type:e.result.blob.type})),this.voicePreviewUrl&&(this.voiceAudio.src=this.voicePreviewUrl),this.voicePreviewTime.textContent=_(e.result.durationSeconds),queueMicrotask(()=>this.voiceSendBtn.focus())))}showComposeError(e){this.composeError.textContent=e,this.composeError.classList.toggle(`visible`,!!e)}setPanelMode(e){this.panel.classList.remove(`ttcb-mode-form`,`ttcb-mode-chat`,`ttcb-mode-compact`),this.panel.classList.add(`ttcb-mode-${e}`),e!==`chat`&&(this.requestHumanBtn.classList.add(`hidden`),this.newSessionBtn.classList.add(`hidden`),this.hideModeBanner())}buildIdentifyForm(e){let t=document.createElement(`form`);t.className=`ttcb-identify-form`,t.addEventListener(`submit`,e=>{e.preventDefault(),this.handleIdentifySubmit()}),this.nameInput=this.createIconField(t,{id:`name`,label:`Name`,required:!0,hint:`Required`,placeholder:`Your name`,type:`text`,autocomplete:`name`,icon:Xt()}),this.createPhoneField(t),this.emailInput=this.createIconField(t,{id:`email`,label:`Email (optional)`,required:!1,hint:`For chat transcript`,placeholder:`Email (optional)`,type:`email`,autocomplete:`email`,icon:Zt()}),this.identifyError=document.createElement(`p`),this.identifyError.className=`ttcb-identify-error`,t.appendChild(this.identifyError),this.identifySubmit=document.createElement(`button`),this.identifySubmit.type=`submit`,this.identifySubmit.className=`ttcb-identify-submit`,this.identifySubmit.innerHTML=`<span>Start Chatting</span>${$t()}`,t.appendChild(this.identifySubmit),e.appendChild(t);let n=document.createElement(`div`);n.className=`ttcb-trust`,n.innerHTML=`${en()}<span>Encrypted connection • No spam, ever</span>`,e.appendChild(n)}createIconField(e,t){let n=document.createElement(`div`);n.className=`ttcb-field`;let r=document.createElement(`div`);r.className=`ttcb-field-label-row`;let i=document.createElement(`label`);i.className=`ttcb-label`,i.htmlFor=`ttcb-${t.id}`,t.required?i.innerHTML=`${t.label.replace(` (optional)`,``)} <span class="ttcb-req">*</span>`:i.textContent=t.label;let a=document.createElement(`span`);a.className=`ttcb-field-hint`,a.textContent=t.hint,r.appendChild(i),r.appendChild(a);let o=document.createElement(`div`);o.className=`ttcb-input-wrap`;let s=document.createElement(`span`);s.className=`ttcb-input-icon`,s.setAttribute(`aria-hidden`,`true`),s.innerHTML=t.icon;let c=document.createElement(`input`);return c.id=`ttcb-${t.id}`,c.name=t.id,c.type=t.type,c.className=`ttcb-identify-input`,c.placeholder=t.placeholder,c.required=t.required,c.autocomplete=t.autocomplete,o.appendChild(s),o.appendChild(c),n.appendChild(r),n.appendChild(o),e.appendChild(n),c}createPhoneField(e){let t=document.createElement(`div`);t.className=`ttcb-field`;let n=document.createElement(`div`);n.className=`ttcb-field-label-row`;let r=document.createElement(`label`);r.className=`ttcb-label`,r.htmlFor=`ttcb-tel`,r.innerHTML=`Phone <span class="ttcb-req">*</span>`;let i=document.createElement(`span`);i.className=`ttcb-field-hint`,i.textContent=`SMS / WhatsApp sync`,n.appendChild(r),n.appendChild(i);let a=document.createElement(`div`);a.className=`ttcb-phone-row`,a.id=`ttcb-phone-row`,this.dialBtn=document.createElement(`button`),this.dialBtn.type=`button`,this.dialBtn.className=`ttcb-dial-btn`,this.dialBtn.setAttribute(`aria-label`,`Select country code`),this.dialBtn.setAttribute(`aria-haspopup`,`listbox`),this.dialBtn.setAttribute(`aria-expanded`,`false`),this.dialFlag=document.createElement(`span`),this.dialFlag.className=`ttcb-dial-flag`,this.dialCode=document.createElement(`span`),this.dialCode.className=`ttcb-dial-code`,this.syncDialButton(),this.dialBtn.appendChild(this.dialFlag),this.dialBtn.appendChild(this.dialCode);let o=document.createElement(`span`);o.setAttribute(`aria-hidden`,`true`),o.innerHTML=Qt(),this.dialBtn.appendChild(o),this.dialBtn.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this.toggleCountryPopover()}),this.phoneInput=document.createElement(`input`),this.phoneInput.id=`ttcb-tel`,this.phoneInput.name=`tel`,this.phoneInput.type=`tel`,this.phoneInput.className=`ttcb-phone-national`,this.phoneInput.placeholder=`1712-345678`,this.phoneInput.required=!0,this.phoneInput.autocomplete=`tel-national`,this.phoneInput.setAttribute(`inputmode`,`tel`),a.appendChild(this.dialBtn),a.appendChild(this.phoneInput),this.countryPopover=document.createElement(`div`),this.countryPopover.className=`ttcb-country-popover`,this.countryPopover.setAttribute(`role`,`listbox`),this.countrySearch=document.createElement(`input`),this.countrySearch.type=`search`,this.countrySearch.className=`ttcb-country-search`,this.countrySearch.placeholder=`Search country…`,this.countrySearch.setAttribute(`aria-label`,`Search countries`),this.countrySearch.addEventListener(`input`,()=>this.renderCountryList()),this.countryList=document.createElement(`div`),this.countryList.className=`ttcb-country-list`,this.countryPopover.appendChild(this.countrySearch),this.countryPopover.appendChild(this.countryList),this.renderCountryList(),t.appendChild(n),t.appendChild(a),t.appendChild(this.countryPopover),e.appendChild(t)}syncDialButton(){this.dialFlag.textContent=this.selectedCountry.flag,this.dialCode.textContent=`+${this.selectedCountry.dial}`}toggleCountryPopover(){this.countryOpen?this.closeCountryPopover():this.openCountryPopover()}openCountryPopover(){this.countryOpen=!0,this.countryPopover.classList.add(`open`),this.dialBtn.setAttribute(`aria-expanded`,`true`),this.countrySearch.value=``,this.renderCountryList(),queueMicrotask(()=>this.countrySearch.focus())}closeCountryPopover(){this.countryOpen=!1,this.countryPopover.classList.remove(`open`),this.dialBtn.setAttribute(`aria-expanded`,`false`)}renderCountryList(){let e=this.countrySearch.value.trim().toLowerCase(),t=X.filter(t=>!e||t.name.toLowerCase().includes(e)||t.dial.includes(e)||t.iso.toLowerCase().includes(e)||`+${t.dial}`.includes(e));this.countryList.innerHTML=``;for(let e of t){let t=document.createElement(`button`);t.type=`button`,t.className=`ttcb-country-item`,t.setAttribute(`role`,`option`),t.setAttribute(`aria-selected`,e.iso===this.selectedCountry.iso?`true`:`false`),t.innerHTML=`
764
+ </svg>`}function fn(e){let t=f(e.url)?e.url:``,n=e.type.toLowerCase();if(t&&n.startsWith(`image/`)){let n=document.createElement(`a`);n.className=`ttcb-attachment ttcb-attachment-image`,n.href=t,n.target=`_blank`,n.rel=`noopener noreferrer`,n.setAttribute(`aria-label`,`Open ${e.fileName}`);let r=document.createElement(`img`);return r.src=t,r.alt=e.fileName,r.loading=`lazy`,n.appendChild(r),n}if(t&&n.startsWith(`video/`)){let n=document.createElement(`video`);return n.className=`ttcb-attachment ttcb-attachment-video`,n.controls=!0,n.preload=`metadata`,n.src=t,n.setAttribute(`aria-label`,e.fileName),n}if(t&&n.startsWith(`audio/`)){let n=document.createElement(`div`);n.className=`ttcb-attachment ttcb-attachment-voice`;let r=document.createElement(`audio`);if(r.className=`ttcb-attachment-audio`,r.controls=!0,r.preload=`metadata`,r.src=t,r.setAttribute(`aria-label`,e.fileName),n.appendChild(r),typeof e.durationSeconds==`number`&&e.durationSeconds>0){let t=document.createElement(`span`);t.className=`ttcb-attachment-duration`,t.textContent=_(e.durationSeconds),n.appendChild(t)}return n}let r=document.createElement(t?`a`:`div`);r.className=`ttcb-attachment ttcb-attachment-file`,r instanceof HTMLAnchorElement&&(r.href=t,r.target=`_blank`,r.rel=`noopener noreferrer`);let i=document.createElement(`span`);i.className=`ttcb-attachment-icon`,i.setAttribute(`aria-hidden`,`true`),i.innerHTML=dn();let a=document.createElement(`span`);a.className=`ttcb-attachment-meta`;let o=document.createElement(`span`);o.className=`ttcb-attachment-name`,o.textContent=e.fileName,a.appendChild(o);let s=te(e.size);if(s){let e=document.createElement(`span`);e.className=`ttcb-attachment-size`,e.textContent=s,a.appendChild(e)}return r.appendChild(i),r.appendChild(a),r}function pn(e){let{type:t,content:n}=e,r=e.attachments??[],i=document.createElement(`div`);i.className=`ttcb-msg ${t}`,e.pending&&i.classList.add(`ttcb-pending`);let a=document.createElement(`div`);a.className=`ttcb-msg-avatar`,a.innerHTML=t===`human`?Yt():t===`agent`?Xt():Z();let o=document.createElement(`div`);if(o.className=`ttcb-msg-body`,t===`agent`){let e=document.createElement(`span`);e.className=`ttcb-msg-label`,e.textContent=`Agent`,o.appendChild(e)}if(r.length>0){let e=document.createElement(`div`);e.className=`ttcb-attachments`;for(let t of r)e.appendChild(fn(t));o.appendChild(e)}if(r.length===0||!re(n,r)){let e=document.createElement(`div`);e.className=`ttcb-bubble`,t===`human`?e.textContent=n:e.innerHTML=Wt(n),o.appendChild(e)}if(e.pending){let e=document.createElement(`span`);e.className=`ttcb-msg-status`,e.textContent=`Uploading…`,o.appendChild(e)}return i.appendChild(a),i.appendChild(o),i}function mn(){let e=document.createElement(`div`);e.className=`ttcb-msg ai`,e.id=`ttcb-typing`;let t=document.createElement(`div`);t.className=`ttcb-msg-avatar`,t.innerHTML=Z();let n=document.createElement(`div`);return n.className=`ttcb-typing`,n.innerHTML=`<span></span><span></span><span></span>`,e.appendChild(t),e.appendChild(n),e}var hn=`image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mpeg,audio/wav,audio/x-m4a,audio/aac,audio/opus,application/pdf,text/csv`,gn=`image/jpeg,image/png,image/gif`,_n=class{constructor(e,t){this.stopViewportSync=null,this.pendingFiles=[],this.attachMenuOpen=!1,this.recorder=null,this.voicePreviewUrl=``,this.selectedCountry=zt,this.countryOpen=!1,this.isOpen=!1,this.destroyed=!1,this.position=e.position??`bottom-right`,this.callbacks=t,this.autoOpen=e.autoOpen===!0,this.mount(e)}mount(e){this.host=document.createElement(`div`),this.host.id=`onedeskpro-chatbot-host`,this.host.style.display=`none`,this.shadow=this.host.attachShadow({mode:`closed`});let t=document.createElement(`style`);t.textContent=Ht(e.primaryColor??`#2563EB`,e.theme??`auto`),this.shadow.appendChild(t),this.fab=document.createElement(`button`),this.fab.className=`ttcb-fab ${this.position}`,this.fab.setAttribute(`aria-label`,`Open chat`),this.fab.innerHTML=Kt(),this.fab.addEventListener(`click`,()=>this.toggle()),this.shadow.appendChild(this.fab),this.panel=document.createElement(`div`),this.panel.className=`ttcb-panel ${this.position} hidden ttcb-mode-compact`,this.panel.tabIndex=-1,this.panel.setAttribute(`role`,`dialog`),this.panel.setAttribute(`aria-modal`,`true`),this.panel.setAttribute(`aria-label`,e.chatbotName??`AI Assistant`),this.panel.appendChild(this.buildHeader(e)),this.identifyContainer=document.createElement(`div`),this.identifyContainer.className=`ttcb-identify`,this.buildIdentifyForm(this.identifyContainer),this.panel.appendChild(this.identifyContainer),this.messagesContainer=document.createElement(`div`),this.messagesContainer.className=`ttcb-messages`,this.messagesContainer.setAttribute(`aria-live`,`polite`),this.messagesContainer.setAttribute(`aria-label`,`Chat messages`),this.panel.appendChild(this.messagesContainer),this.modeBanner=document.createElement(`div`),this.modeBanner.className=`ttcb-mode-banner`,this.modeBanner.setAttribute(`role`,`status`),this.panel.appendChild(this.modeBanner),this.footer=document.createElement(`div`),this.footer.className=`ttcb-footer`,this.pendingTray=document.createElement(`div`),this.pendingTray.className=`ttcb-pending-tray`,this.pendingTray.setAttribute(`role`,`list`),this.pendingTray.setAttribute(`aria-label`,`Files to send`),this.footer.appendChild(this.pendingTray),this.composeError=document.createElement(`p`),this.composeError.className=`ttcb-compose-error`,this.composeError.setAttribute(`role`,`alert`),this.footer.appendChild(this.composeError),this.footer.appendChild(this.buildVoiceBar()),this.footer.appendChild(this.buildVoicePreview());let n=document.createElement(`form`);n.className=`ttcb-form`,n.addEventListener(`submit`,e=>{e.preventDefault(),this.handleSend()}),this.composeForm=n,n.appendChild(this.buildAttachControls()),this.input=document.createElement(`input`),this.input.type=`text`,this.input.className=`ttcb-input`,this.input.placeholder=e.placeholder??`Type your message…`,this.input.setAttribute(`aria-label`,`Message input`),this.input.setAttribute(`autocomplete`,`off`),this.sendBtn=document.createElement(`button`),this.sendBtn.type=`submit`,this.sendBtn.className=`ttcb-send-btn`,this.sendBtn.innerHTML=Jt(),this.sendBtn.setAttribute(`aria-label`,`Send message`),this.micBtn=document.createElement(`button`),this.micBtn.type=`button`,this.micBtn.className=`ttcb-mic-btn`,this.micBtn.setAttribute(`aria-label`,`Record voice message`),this.micBtn.title=`Record voice message`,this.micBtn.innerHTML=cn(),this.micBtn.addEventListener(`click`,()=>void this.startVoice()),n.appendChild(this.input),n.appendChild(this.micBtn),n.appendChild(this.sendBtn),this.footer.appendChild(n),this.panel.appendChild(this.footer),this.shadow.appendChild(this.panel),this.shadow.addEventListener(`click`,e=>{let t=e.target;this.attachMenuOpen&&!(t&&(this.attachBtn.contains(t)||this.attachMenu.contains(t)))&&this.closeAttachMenu(),this.countryOpen&&(t&&(this.dialBtn.contains(t)||this.countryPopover.contains(t))||this.closeCountryPopover())}),this.panel.addEventListener(`keydown`,e=>{e.key===`Escape`&&this.attachMenuOpen&&(e.stopPropagation(),this.closeAttachMenu(),this.attachBtn.focus())}),this.attachToDocument(),this.showInitialLoading()}reveal(){this.host.style.removeProperty(`display`),this.autoOpen&&!this.isOpen&&this.open()}buildHeader(e){let t=document.createElement(`div`);t.className=`ttcb-header`;let n=document.createElement(`div`);n.className=`ttcb-avatar-wrap`;let r=document.createElement(`div`);r.className=`ttcb-avatar`,r.innerHTML=Z(),n.appendChild(r);let i=document.createElement(`div`);i.className=`ttcb-header-main`;let a=document.createElement(`div`);a.className=`ttcb-header-title-row`,this.headerTitle=document.createElement(`span`),this.headerTitle.className=`ttcb-header-title`,this.headerTitle.textContent=e.chatbotName??`AI Assistant`;let o=document.createElement(`span`);o.className=`ttcb-verified`,o.setAttribute(`aria-label`,`Verified`),o.innerHTML=tn(),a.appendChild(this.headerTitle),a.appendChild(o);let s=document.createElement(`div`);s.className=`ttcb-header-meta`;let c=document.createElement(`span`);c.className=`ttcb-meta-online`,c.textContent=`Online`;let l=document.createElement(`span`);l.className=`ttcb-meta-sep`,l.setAttribute(`aria-hidden`,`true`);let u=document.createElement(`span`);u.className=`ttcb-meta-replies`,u.innerHTML=`${nn()}<span>Replies instantly</span>`,s.appendChild(c),s.appendChild(l),s.appendChild(u),i.appendChild(a),i.appendChild(s);let d=document.createElement(`div`);d.className=`ttcb-header-actions`,this.requestHumanBtn=document.createElement(`button`),this.requestHumanBtn.type=`button`,this.requestHumanBtn.className=`ttcb-request-human-btn hidden`,this.requestHumanBtn.id=`ttcb-request-human-btn`,this.requestHumanBtn.setAttribute(`aria-label`,`Request human agent`),this.requestHumanBtn.title=`Request human agent`,this.requestHumanBtn.innerHTML=rn(),this.requestHumanBtn.addEventListener(`click`,()=>this.callbacks.onRequestHuman()),this.newSessionBtn=document.createElement(`button`),this.newSessionBtn.className=`ttcb-new-session-btn hidden`,this.newSessionBtn.setAttribute(`aria-label`,`New conversation`),this.newSessionBtn.title=`New conversation`,this.newSessionBtn.innerHTML=Gt(),this.newSessionBtn.addEventListener(`click`,()=>this.callbacks.onReset());let f=document.createElement(`button`);return f.className=`ttcb-close-btn`,f.setAttribute(`aria-label`,`Close chat`),f.innerHTML=qt(),f.addEventListener(`click`,()=>this.close()),d.appendChild(this.requestHumanBtn),d.appendChild(this.newSessionBtn),d.appendChild(f),t.appendChild(n),t.appendChild(i),t.appendChild(d),t}buildAttachControls(){let e=document.createElement(`div`);e.className=`ttcb-attach`,this.attachBtn=document.createElement(`button`),this.attachBtn.type=`button`,this.attachBtn.className=`ttcb-attach-btn`,this.attachBtn.setAttribute(`aria-label`,`Add attachment`),this.attachBtn.setAttribute(`aria-haspopup`,`menu`),this.attachBtn.setAttribute(`aria-expanded`,`false`),this.attachBtn.title=`Add attachment`,this.attachBtn.innerHTML=an(),this.attachBtn.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this.toggleAttachMenu()}),this.attachMenu=document.createElement(`div`),this.attachMenu.className=`ttcb-attach-menu`,this.attachMenu.setAttribute(`role`,`menu`),this.attachFileInput=this.createFileInput(hn,`Choose files`),this.attachPhotoInput=this.createFileInput(gn,`Choose photos`);let t=[{label:`Attachment`,icon:on(),input:this.attachFileInput},{label:`Photo`,icon:sn(),input:this.attachPhotoInput}];for(let e of t){let t=document.createElement(`button`);t.type=`button`,t.className=`ttcb-attach-item`,t.setAttribute(`role`,`menuitem`),t.innerHTML=`${e.icon}<span>${e.label}</span>`,t.addEventListener(`click`,()=>{this.closeAttachMenu(),e.input.click()}),this.attachMenu.appendChild(t)}return e.appendChild(this.attachBtn),e.appendChild(this.attachMenu),e.appendChild(this.attachFileInput),e.appendChild(this.attachPhotoInput),e}createFileInput(e,t){let n=document.createElement(`input`);return n.type=`file`,n.multiple=!0,n.accept=e,n.className=`ttcb-file-input`,n.tabIndex=-1,n.setAttribute(`aria-label`,t),n.addEventListener(`change`,()=>{this.addPendingFiles(Array.from(n.files??[])),n.value=``}),n}toggleAttachMenu(){this.attachMenuOpen?this.closeAttachMenu():this.openAttachMenu()}openAttachMenu(){if(this.attachBtn.disabled)return;this.attachMenuOpen=!0,this.attachMenu.classList.add(`open`),this.attachBtn.setAttribute(`aria-expanded`,`true`);let e=this.attachMenu.querySelector(`.ttcb-attach-item`);queueMicrotask(()=>e?.focus())}closeAttachMenu(){this.attachMenuOpen&&(this.attachMenuOpen=!1,this.attachMenu.classList.remove(`open`),this.attachBtn.setAttribute(`aria-expanded`,`false`))}addPendingFiles(e){if(e.length===0)return;let t=d([...this.pendingFiles.map(e=>e.file),...e]);if(t)this.showComposeError(t);else{this.showComposeError(``);for(let t of e){let e=t.type.startsWith(`image/`)?p(t):``;this.pendingFiles.push({file:t,previewUrl:e})}this.renderPendingTray(),this.input.focus()}}removePendingFile(e){let[t]=this.pendingFiles.splice(e,1);t&&m(t.previewUrl),this.renderPendingTray(),this.input.focus()}clearPendingFiles(){for(let e of this.pendingFiles)m(e.previewUrl);this.pendingFiles=[],this.renderPendingTray()}renderPendingTray(){this.pendingTray.innerHTML=``,this.pendingTray.classList.toggle(`visible`,this.pendingFiles.length>0),this.pendingFiles.forEach((e,t)=>{let n=document.createElement(`div`);if(n.className=`ttcb-pending-item`,n.setAttribute(`role`,`listitem`),e.previewUrl){let t=document.createElement(`img`);t.className=`ttcb-pending-thumb`,t.src=e.previewUrl,t.alt=``,n.appendChild(t)}else{let e=document.createElement(`span`);e.className=`ttcb-pending-icon`,e.setAttribute(`aria-hidden`,`true`),e.innerHTML=dn(),n.appendChild(e)}let r=document.createElement(`span`);r.className=`ttcb-pending-name`,r.textContent=e.file.name||`attachment`,r.title=e.file.name,n.appendChild(r);let i=document.createElement(`button`);i.type=`button`,i.className=`ttcb-pending-remove`,i.setAttribute(`aria-label`,`Remove ${e.file.name||`attachment`}`),i.innerHTML=qt(),i.addEventListener(`click`,()=>this.removePendingFile(t)),n.appendChild(i),this.pendingTray.appendChild(n)})}buildVoiceBar(){this.voiceBar=document.createElement(`div`),this.voiceBar.className=`ttcb-voice-bar`,this.voiceBar.setAttribute(`role`,`group`),this.voiceBar.setAttribute(`aria-label`,`Recording voice message`);let e=document.createElement(`span`);e.className=`ttcb-voice-dot`,e.setAttribute(`aria-hidden`,`true`),this.voiceTime=document.createElement(`span`),this.voiceTime.className=`ttcb-voice-time`,this.voiceTime.setAttribute(`role`,`timer`),this.voiceTime.textContent=`0:00`;let t=document.createElement(`div`);return t.className=`ttcb-voice-meter`,t.setAttribute(`aria-hidden`,`true`),this.voiceLevel=document.createElement(`span`),this.voiceLevel.className=`ttcb-voice-level`,t.appendChild(this.voiceLevel),this.voiceCancelBtn=this.createVoiceButton(`Cancel recording`,un(),()=>this.cancelVoice()),this.voiceStopBtn=this.createVoiceButton(`Stop recording`,ln(),()=>void this.stopVoice()),this.voiceStopBtn.classList.add(`primary`),this.voiceBar.appendChild(e),this.voiceBar.appendChild(this.voiceTime),this.voiceBar.appendChild(t),this.voiceBar.appendChild(this.voiceCancelBtn),this.voiceBar.appendChild(this.voiceStopBtn),this.voiceBar}buildVoicePreview(){return this.voicePreview=document.createElement(`div`),this.voicePreview.className=`ttcb-voice-preview`,this.voicePreview.setAttribute(`role`,`group`),this.voicePreview.setAttribute(`aria-label`,`Voice message preview`),this.voiceAudio=document.createElement(`audio`),this.voiceAudio.className=`ttcb-voice-audio`,this.voiceAudio.controls=!0,this.voiceAudio.preload=`metadata`,this.voiceAudio.setAttribute(`aria-label`,`Recorded voice message`),this.voicePreviewTime=document.createElement(`span`),this.voicePreviewTime.className=`ttcb-voice-time`,this.voiceDiscardBtn=this.createVoiceButton(`Discard voice message`,un(),()=>this.cancelVoice()),this.voiceSendBtn=this.createVoiceButton(`Send voice message`,Jt(),()=>this.sendVoice()),this.voiceSendBtn.classList.add(`primary`),this.voicePreview.appendChild(this.voiceAudio),this.voicePreview.appendChild(this.voicePreviewTime),this.voicePreview.appendChild(this.voiceDiscardBtn),this.voicePreview.appendChild(this.voiceSendBtn),this.voicePreview}createVoiceButton(e,t,n){let r=document.createElement(`button`);return r.type=`button`,r.className=`ttcb-voice-btn`,r.setAttribute(`aria-label`,e),r.title=e,r.innerHTML=t,r.addEventListener(`click`,n),r}async startVoice(){if(!this.micBtn.disabled){if(this.closeAttachMenu(),this.showComposeError(``),!Y.isSupported())this.showComposeError(`Voice messages are not supported in this browser.`);else{this.recorder?.destroy(),this.recorder=new Y(e=>this.renderVoice(e));try{await this.recorder.start()}catch(e){this.showComposeError(e instanceof Error?e.message:`Could not start recording.`),this.recorder.destroy(),this.recorder=null,this.renderVoice({state:`idle`,elapsedSeconds:0,level:0,result:null})}}}}async stopVoice(){await this.recorder?.stop()}cancelVoice(){this.recorder?.cancel(),this.recorder?.destroy(),this.recorder=null,this.renderVoice({state:`idle`,elapsedSeconds:0,level:0,result:null}),this.input.focus()}sendVoice(){let e=this.recorder?.getSnapshot().result;e&&(this.cancelVoice(),this.callbacks.onSendVoice(e))}renderVoice(e){if(this.destroyed)return;let{state:t}=e;this.composeForm.classList.toggle(`hidden`,t!==`idle`),this.voiceBar.classList.toggle(`visible`,t===`recording`),this.voicePreview.classList.toggle(`visible`,t===`preview`),t===`recording`?(this.voiceTime.textContent=_(e.elapsedSeconds),this.voiceLevel.style.width=`${Math.max(4,Math.round(e.level*100))}%`):(m(this.voicePreviewUrl),this.voicePreviewUrl=``,this.voiceAudio.removeAttribute(`src`),t===`preview`&&e.result&&(this.voicePreviewUrl=p(new File([e.result.blob],`voice-preview`,{type:e.result.blob.type})),this.voicePreviewUrl&&(this.voiceAudio.src=this.voicePreviewUrl),this.voicePreviewTime.textContent=_(e.result.durationSeconds),queueMicrotask(()=>this.voiceSendBtn.focus())))}showComposeError(e){this.composeError.textContent=e,this.composeError.classList.toggle(`visible`,!!e)}setPanelMode(e){this.panel.classList.remove(`ttcb-mode-form`,`ttcb-mode-chat`,`ttcb-mode-compact`),this.panel.classList.add(`ttcb-mode-${e}`),e!==`chat`&&(this.requestHumanBtn.classList.add(`hidden`),this.newSessionBtn.classList.add(`hidden`),this.hideModeBanner())}buildIdentifyForm(e){let t=document.createElement(`form`);t.className=`ttcb-identify-form`,t.addEventListener(`submit`,e=>{e.preventDefault(),this.handleIdentifySubmit()}),this.nameInput=this.createIconField(t,{id:`name`,label:`Name`,required:!0,hint:`Required`,placeholder:`Your name`,type:`text`,autocomplete:`name`,icon:Xt()}),this.createPhoneField(t),this.emailInput=this.createIconField(t,{id:`email`,label:`Email (optional)`,required:!1,hint:`For chat transcript`,placeholder:`Email (optional)`,type:`email`,autocomplete:`email`,icon:Zt()}),this.identifyError=document.createElement(`p`),this.identifyError.className=`ttcb-identify-error`,t.appendChild(this.identifyError),this.identifySubmit=document.createElement(`button`),this.identifySubmit.type=`submit`,this.identifySubmit.className=`ttcb-identify-submit`,this.identifySubmit.innerHTML=`<span>Start Chatting</span>${$t()}`,t.appendChild(this.identifySubmit),e.appendChild(t);let n=document.createElement(`div`);n.className=`ttcb-trust`,n.innerHTML=`${en()}<span>Encrypted connection • No spam, ever</span>`,e.appendChild(n)}createIconField(e,t){let n=document.createElement(`div`);n.className=`ttcb-field`;let r=document.createElement(`div`);r.className=`ttcb-field-label-row`;let i=document.createElement(`label`);i.className=`ttcb-label`,i.htmlFor=`ttcb-${t.id}`,t.required?i.innerHTML=`${t.label.replace(` (optional)`,``)} <span class="ttcb-req">*</span>`:i.textContent=t.label;let a=document.createElement(`span`);a.className=`ttcb-field-hint`,a.textContent=t.hint,r.appendChild(i),r.appendChild(a);let o=document.createElement(`div`);o.className=`ttcb-input-wrap`;let s=document.createElement(`span`);s.className=`ttcb-input-icon`,s.setAttribute(`aria-hidden`,`true`),s.innerHTML=t.icon;let c=document.createElement(`input`);return c.id=`ttcb-${t.id}`,c.name=t.id,c.type=t.type,c.className=`ttcb-identify-input`,c.placeholder=t.placeholder,c.required=t.required,c.autocomplete=t.autocomplete,o.appendChild(s),o.appendChild(c),n.appendChild(r),n.appendChild(o),e.appendChild(n),c}createPhoneField(e){let t=document.createElement(`div`);t.className=`ttcb-field`;let n=document.createElement(`div`);n.className=`ttcb-field-label-row`;let r=document.createElement(`label`);r.className=`ttcb-label`,r.htmlFor=`ttcb-tel`,r.innerHTML=`Phone <span class="ttcb-req">*</span>`;let i=document.createElement(`span`);i.className=`ttcb-field-hint`,i.textContent=`SMS / WhatsApp sync`,n.appendChild(r),n.appendChild(i);let a=document.createElement(`div`);a.className=`ttcb-phone-row`,a.id=`ttcb-phone-row`,this.dialBtn=document.createElement(`button`),this.dialBtn.type=`button`,this.dialBtn.className=`ttcb-dial-btn`,this.dialBtn.setAttribute(`aria-label`,`Select country code`),this.dialBtn.setAttribute(`aria-haspopup`,`listbox`),this.dialBtn.setAttribute(`aria-expanded`,`false`),this.dialFlag=document.createElement(`span`),this.dialFlag.className=`ttcb-dial-flag`,this.dialCode=document.createElement(`span`),this.dialCode.className=`ttcb-dial-code`,this.syncDialButton(),this.dialBtn.appendChild(this.dialFlag),this.dialBtn.appendChild(this.dialCode);let o=document.createElement(`span`);o.setAttribute(`aria-hidden`,`true`),o.innerHTML=Qt(),this.dialBtn.appendChild(o),this.dialBtn.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this.toggleCountryPopover()}),this.phoneInput=document.createElement(`input`),this.phoneInput.id=`ttcb-tel`,this.phoneInput.name=`tel`,this.phoneInput.type=`tel`,this.phoneInput.className=`ttcb-phone-national`,this.phoneInput.placeholder=`1712-345678`,this.phoneInput.required=!0,this.phoneInput.autocomplete=`tel-national`,this.phoneInput.setAttribute(`inputmode`,`tel`),a.appendChild(this.dialBtn),a.appendChild(this.phoneInput),this.countryPopover=document.createElement(`div`),this.countryPopover.className=`ttcb-country-popover`,this.countryPopover.setAttribute(`role`,`listbox`),this.countrySearch=document.createElement(`input`),this.countrySearch.type=`search`,this.countrySearch.className=`ttcb-country-search`,this.countrySearch.placeholder=`Search country…`,this.countrySearch.setAttribute(`aria-label`,`Search countries`),this.countrySearch.addEventListener(`input`,()=>this.renderCountryList()),this.countryList=document.createElement(`div`),this.countryList.className=`ttcb-country-list`,this.countryPopover.appendChild(this.countrySearch),this.countryPopover.appendChild(this.countryList),this.renderCountryList(),t.appendChild(n),t.appendChild(a),t.appendChild(this.countryPopover),e.appendChild(t)}syncDialButton(){this.dialFlag.textContent=this.selectedCountry.flag,this.dialCode.textContent=`+${this.selectedCountry.dial}`}toggleCountryPopover(){this.countryOpen?this.closeCountryPopover():this.openCountryPopover()}openCountryPopover(){this.countryOpen=!0,this.countryPopover.classList.add(`open`),this.dialBtn.setAttribute(`aria-expanded`,`true`),this.countrySearch.value=``,this.renderCountryList(),queueMicrotask(()=>this.countrySearch.focus())}closeCountryPopover(){this.countryOpen=!1,this.countryPopover.classList.remove(`open`),this.dialBtn.setAttribute(`aria-expanded`,`false`)}renderCountryList(){let e=this.countrySearch.value.trim().toLowerCase(),t=X.filter(t=>!e||t.name.toLowerCase().includes(e)||t.dial.includes(e)||t.iso.toLowerCase().includes(e)||`+${t.dial}`.includes(e));this.countryList.innerHTML=``;for(let e of t){let t=document.createElement(`button`);t.type=`button`,t.className=`ttcb-country-item`,t.setAttribute(`role`,`option`),t.setAttribute(`aria-selected`,e.iso===this.selectedCountry.iso?`true`:`false`),t.innerHTML=`
765
765
  <span class="ttcb-dial-flag">${e.flag}</span>
766
766
  <span class="ttcb-country-item-name">${e.name}</span>
767
767
  <span class="ttcb-country-item-dial">+${e.dial}</span>
@@ -1,4 +1,4 @@
1
- var OnedeskProChatbot=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},r=3e4,i=12e4;function a(e){return typeof e==`object`&&!!e&&typeof e.message==`string`}function o(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.type==`string`&&typeof t.url==`string`&&typeof t.fileName==`string`&&typeof t.size==`number`}function s(e){return e instanceof Error&&`apiError`in e&&`status`in e&&typeof e.status==`number`&&a(e.apiError)}var c=class{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,``),this.apiKey=e.apiKey,this.timeoutMs=e.timeoutMs??3e4,this.uploadTimeoutMs=e.uploadTimeoutMs??i}fail(e,t,n,r){let i={statusCode:t,message:e,code:n,timestamp:new Date().toISOString(),path:r};throw Object.assign(Error(e),{apiError:i,status:t})}async request(e,t,n,r,i,o=this.timeoutMs){let s=new URL(`${this.baseUrl}${t}`);if(r)for(let[e,t]of Object.entries(r))s.searchParams.set(e,t);let c=typeof FormData<`u`&&n instanceof FormData,l={...c?{}:{"Content-Type":`application/json`},"X-API-Key":this.apiKey,...i},u=new AbortController,d=setTimeout(()=>u.abort(),o),f;try{f=await fetch(s.toString(),{method:e,headers:l,signal:u.signal,...n===void 0?{}:{body:c?n:JSON.stringify(n)}})}catch(e){u.signal.aborted&&this.fail(`Request timed out after ${o}ms.`,0,`TIMEOUT`,t),this.fail(e instanceof Error?e.message:`Network request failed.`,0,`NETWORK_ERROR`,t)}finally{clearTimeout(d)}let p=await f.text(),m=null;if(p)try{m=JSON.parse(p)}catch{m=null}if(!f.ok){if(a(m))throw Object.assign(Error(m.message),{apiError:m,status:f.status});this.fail(`Request failed with status ${f.status} ${f.statusText}`.trim(),f.status,`HTTP_ERROR`,t)}return m===null&&this.fail(`The server returned an empty or malformed response.`,f.status,`BAD_RESPONSE`,t),m.data}async identify(e){return this.request(`POST`,`/sdk/identify`,e)}async verifyVisitor(e){return this.request(`GET`,`/sdk/visitor`,void 0,void 0,{"X-Visitor-Token":e})}async sendMessage(e){return this.request(`POST`,`/sdk/chat`,e)}async uploadAttachment(e,t){let n=new FormData;n.append(`file`,e,e.name);let r=await this.request(`POST`,`/sdk/upload`,n,void 0,{"X-Visitor-Token":t},this.uploadTimeoutMs);return o(r)||this.fail(`The server returned an unexpected upload response.`,200,`BAD_RESPONSE`,`/sdk/upload`),r}async fetchConfig(){return this.request(`GET`,`/sdk/config`)}async requestHuman(e){return this.request(`POST`,`/sdk/human-request`,{visitorToken:e})}async fetchTicketStatus(e){return this.request(`GET`,`/sdk/ticket-status`,void 0,void 0,{"X-Visitor-Token":e})}},l=`https://api.onedeskpro.com`,u=10485760,d=10;function f(e){if(e.length>10)return`You can send up to 10 files at a time.`;let t=e.find(e=>e.size>u);if(t){let e=Math.round(u/1048576);return`"${t.name||`This file`}" is larger than ${e} MB.`}return null}function p(e){return/^(https?:\/\/|blob:)/i.test(e)}function m(e){return typeof URL>`u`||typeof URL.createObjectURL!=`function`?``:URL.createObjectURL(e)}function h(e){e.startsWith(`blob:`)&&typeof URL<`u`&&typeof URL.revokeObjectURL==`function`&&URL.revokeObjectURL(e)}function ee(e){return{type:e.type||`application/octet-stream`,url:m(e),fileName:e.name||`attachment`,size:e.size}}function te(e){return!Number.isFinite(e)||e<0?``:e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(+(e<10240))} KB`:`${(e/1048576).toFixed(1)} MB`}function ne(e){if(!e||typeof e!=`object`)return[];let t=e,n=t.attachments;if(!Array.isArray(n)&&t.message&&typeof t.message==`object`&&(n=t.message.attachments),!Array.isArray(n))return[];let r=[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=e;typeof t.url==`string`&&/^https?:\/\//i.test(t.url)&&r.push({type:typeof t.type==`string`&&t.type?t.type:`application/octet-stream`,url:t.url,fileName:typeof t.fileName==`string`&&t.fileName?t.fileName:`attachment`,size:typeof t.size==`number`&&t.size>=0?t.size:0,...typeof t.durationSeconds==`number`?{durationSeconds:t.durationSeconds}:{}})}return r}function re(e,t){let n=e.trim();return n?t.length===0?!1:t.some(e=>e.fileName===n)||/^\d+ files?$/.test(n)?!0:[`Image`,`Video`,`Audio`,`Attachment`].includes(n):!0}var g=16e3;function _(e){return(e??``).split(`;`)[0].trim().toLowerCase()||`audio/webm`}function ie(e){return e.includes(`mpeg`)||e.includes(`mp3`)?`mp3`:e.includes(`wav`)?`wav`:e.includes(`mp4`)||e.includes(`m4a`)?`m4a`:e.includes(`ogg`)?`ogg`:`webm`}function v(e){if(!Number.isFinite(e)||e<0)return`0:00`;let t=Math.floor(e),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,`0`)}`}function ae(){if(typeof window>`u`)return null;let e=window;return e.AudioContext??e.webkitAudioContext??null}function oe(){if(typeof window>`u`)return null;let e=window;return e.OfflineAudioContext??e.webkitOfflineAudioContext??null}async function se(e){let t=ae();if(!t)return null;let n=new t;try{let t=await e.arrayBuffer();return await n.decodeAudioData(t.slice(0))}catch{return null}finally{await n.close().catch(()=>void 0)}}async function ce(e){let t=oe();if(t)try{let n=new t(1,Math.max(1,Math.ceil(e.duration*g)),g),r=n.createBufferSource();return r.buffer=e,r.connect(n.destination),r.start(0),{samples:(await n.startRendering()).getChannelData(0),sampleRate:g}}catch{}return{samples:e.getChannelData(0),sampleRate:e.sampleRate}}function le(e,t){let n=e.length*2,r=new ArrayBuffer(44+n),i=new DataView(r),a=(e,t)=>{for(let n=0;n<t.length;n++)i.setUint8(e+n,t.charCodeAt(n))};a(0,`RIFF`),i.setUint32(4,36+n,!0),a(8,`WAVE`),a(12,`fmt `),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,1,!0),i.setUint32(24,t,!0),i.setUint32(28,t*2,!0),i.setUint16(32,2,!0),i.setUint16(34,16,!0),a(36,`data`),i.setUint32(40,n,!0);let o=44;for(let t=0;t<e.length;t++){let n=Math.max(-1,Math.min(1,e[t]??0));i.setInt16(o,Math.round(n<0?n*32768:n*32767),!0),o+=2}return new Blob([r],{type:`audio/wav`})}function ue(e,t=48){if(e.length===0)return[];let n=Math.max(1,Math.floor(e.length/t)),r=[],i=0;for(let a=0;a<t;a++){let t=a*n,o=Math.min(t+n,e.length),s=0;for(let n=t;n<o;n++){let t=e[n]??0;s+=t*t}let c=o>t?Math.sqrt(s/(o-t)):0;r.push(c),c>i&&(i=c)}return r.map(e=>i>0?Math.max(8,Math.min(100,Math.round(e/i*100))):8)}async function de(e){let t=Date.now(),n=Math.max(1,Math.round(e.durationSeconds||1)),r=_(e.mimeType??e.blob.type),i=await se(e.blob);if(!i)return{file:new File([e.blob],`voice-message-${t}.${ie(r)}`,{type:r}),durationSeconds:n};let{samples:a,sampleRate:o}=await ce(i);return{file:new File([le(a,o)],`voice-message-${t}.wav`,{type:`audio/wav`}),durationSeconds:Math.max(1,Math.round(i.duration||n)),waveform:ue(a)}}var fe=class{constructor(){this._listeners={}}on(e,t){return this._listeners[e]||(this._listeners[e]=[]),this._listeners[e].push(t),()=>this.off(e,t)}off(e,t){let n=this._listeners[e];n&&(this._listeners[e]=n.filter(e=>e!==t))}emit(e,...t){let n=this._listeners[e];if(n)for(let e of n)e(...t)}removeAllListeners(){for(let e of Object.keys(this._listeners))delete this._listeners[e]}},y=Object.create(null);y.open=`0`,y.close=`1`,y.ping=`2`,y.pong=`3`,y.message=`4`,y.upgrade=`5`,y.noop=`6`;var b=Object.create(null);Object.keys(y).forEach(e=>{b[y[e]]=e});var x={type:`error`,data:`parser error`},pe=typeof Blob==`function`||typeof Blob<`u`&&Object.prototype.toString.call(Blob)===`[object BlobConstructor]`,me=typeof ArrayBuffer==`function`,he=e=>typeof ArrayBuffer.isView==`function`?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,ge=({type:e,data:t},n,r)=>pe&&t instanceof Blob?n?r(t):_e(t,r):me&&(t instanceof ArrayBuffer||he(t))?n?r(t):_e(new Blob([t]),r):r(y[e]+(t||``)),_e=(e,t)=>{let n=new FileReader;return n.onload=function(){let e=n.result.split(`,`)[1];t(`b`+(e||``))},n.readAsDataURL(e)};function ve(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var ye;function be(e,t){if(pe&&e.data instanceof Blob)return e.data.arrayBuffer().then(ve).then(t);if(me&&(e.data instanceof ArrayBuffer||he(e.data)))return t(ve(e.data));ge(e,!1,e=>{ye||=new TextEncoder,t(ye.encode(e))})}var xe=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,S=typeof Uint8Array>`u`?[]:new Uint8Array(256);for(let e=0;e<64;e++)S[xe.charCodeAt(e)]=e;var Se=e=>{let t=e.length*.75,n=e.length,r,i=0,a,o,s,c;e[e.length-1]===`=`&&(t--,e[e.length-2]===`=`&&t--);let l=new ArrayBuffer(t),u=new Uint8Array(l);for(r=0;r<n;r+=4)a=S[e.charCodeAt(r)],o=S[e.charCodeAt(r+1)],s=S[e.charCodeAt(r+2)],c=S[e.charCodeAt(r+3)],u[i++]=a<<2|o>>4,u[i++]=(o&15)<<4|s>>2,u[i++]=(s&3)<<6|c&63;return l},Ce=typeof ArrayBuffer==`function`,C=(e,t)=>{if(typeof e!=`string`)return{type:`message`,data:Te(e,t)};let n=e.charAt(0);return n===`b`?{type:`message`,data:we(e.substring(1),t)}:b[n]?e.length>1?{type:b[n],data:e.substring(1)}:{type:b[n]}:x},we=(e,t)=>Ce?Te(Se(e),t):{base64:!0,data:e},Te=(e,t)=>{switch(t){case`blob`:return e instanceof Blob?e:new Blob([e]);default:return e instanceof ArrayBuffer?e:e.buffer}},Ee=``,De=(e,t)=>{let n=e.length,r=Array(n),i=0;e.forEach((e,a)=>{ge(e,!1,e=>{r[a]=e,++i===n&&t(r.join(Ee))})})},Oe=(e,t)=>{let n=e.split(Ee),r=[];for(let e=0;e<n.length;e++){let i=C(n[e],t);if(r.push(i),i.type===`error`)break}return r};function ke(){return new TransformStream({transform(e,t){be(e,n=>{let r=n.length,i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);let e=new DataView(i.buffer);e.setUint8(0,126),e.setUint16(1,r)}else{i=new Uint8Array(9);let e=new DataView(i.buffer);e.setUint8(0,127),e.setBigUint64(1,BigInt(r))}e.data&&typeof e.data!=`string`&&(i[0]|=128),t.enqueue(i),t.enqueue(n)})}})}var Ae;function w(e){return e.reduce((e,t)=>e+t.length,0)}function T(e,t){if(e[0].length===t)return e.shift();let n=new Uint8Array(t),r=0;for(let i=0;i<t;i++)n[i]=e[0][r++],r===e[0].length&&(e.shift(),r=0);return e.length&&r<e[0].length&&(e[0]=e[0].slice(r)),n}function je(e,t){Ae||=new TextDecoder;let n=[],r=0,i=-1,a=!1;return new TransformStream({transform(o,s){for(n.push(o);;){if(r===0){if(w(n)<1)break;let e=T(n,1);a=(e[0]&128)==128,i=e[0]&127,r=i<126?3:i===126?1:2}else if(r===1){if(w(n)<2)break;let e=T(n,2);i=new DataView(e.buffer,e.byteOffset,e.length).getUint16(0),r=3}else if(r===2){if(w(n)<8)break;let e=T(n,8),t=new DataView(e.buffer,e.byteOffset,e.length),a=t.getUint32(0);if(a>2**21-1){s.enqueue(x);break}i=a*2**32+t.getUint32(4),r=3}else{if(w(n)<i)break;let e=T(n,i);s.enqueue(C(a?e:Ae.decode(e),t)),r=0}if(i===0||i>e){s.enqueue(x);break}}}})}function E(e){if(e)return Me(e)}function Me(e){for(var t in E.prototype)e[t]=E.prototype[t];return e}E.prototype.on=E.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks[`$`+e]=this._callbacks[`$`+e]||[]).push(t),this},E.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},E.prototype.off=E.prototype.removeListener=E.prototype.removeAllListeners=E.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks[`$`+e];if(!n)return this;if(arguments.length==1)return delete this._callbacks[`$`+e],this;for(var r,i=0;i<n.length;i++)if(r=n[i],r===t||r.fn===t){n.splice(i,1);break}return n.length===0&&delete this._callbacks[`$`+e],this},E.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=Array(arguments.length-1),n=this._callbacks[`$`+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(n){n=n.slice(0);for(var r=0,i=n.length;r<i;++r)n[r].apply(this,t)}return this},E.prototype.emitReserved=E.prototype.emit,E.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks[`$`+e]||[]},E.prototype.hasListeners=function(e){return!!this.listeners(e).length};var D=typeof Promise==`function`&&typeof Promise.resolve==`function`?e=>Promise.resolve().then(e):(e,t)=>t(e,0),O=typeof self<`u`?self:typeof window<`u`?window:Function(`return this`)(),Ne=`arraybuffer`;function Pe(e,...t){return t.reduce((t,n)=>(e.hasOwnProperty(n)&&(t[n]=e[n]),t),{})}var Fe=O.setTimeout,Ie=O.clearTimeout;function k(e,t){t.useNativeTimers?(e.setTimeoutFn=Fe.bind(O),e.clearTimeoutFn=Ie.bind(O)):(e.setTimeoutFn=O.setTimeout.bind(O),e.clearTimeoutFn=O.clearTimeout.bind(O))}var Le=1.33;function Re(e){return typeof e==`string`?ze(e):Math.ceil((e.byteLength||e.size)*Le)}function ze(e){let t=0,n=0;for(let r=0,i=e.length;r<i;r++)t=e.charCodeAt(r),t<128?n+=1:t<2048?n+=2:t<55296||t>=57344?n+=3:(r++,n+=4);return n}function Be(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function Ve(e){let t=``;for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+=`&`),t+=encodeURIComponent(n)+`=`+encodeURIComponent(e[n]));return t}function He(e){let t={},n=e.split(`&`);for(let e=0,r=n.length;e<r;e++){let r=n[e].split(`=`);t[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return t}var Ue=class extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type=`TransportError`}},A=class extends E{constructor(e){super(),this.writable=!1,k(this,e),this.opts=e,this.query=e.query,this.socket=e.socket,this.supportsBinary=!e.forceBase64}onError(e,t,n){return super.emitReserved(`error`,new Ue(e,t,n)),this}open(){return this.readyState=`opening`,this.doOpen(),this}close(){return(this.readyState===`opening`||this.readyState===`open`)&&(this.doClose(),this.onClose()),this}send(e){this.readyState===`open`&&this.write(e)}onOpen(){this.readyState=`open`,this.writable=!0,super.emitReserved(`open`)}onData(e){let t=C(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved(`packet`,e)}onClose(e){this.readyState=`closed`,super.emitReserved(`close`,e)}pause(e){}createUri(e,t={}){return e+`://`+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){let e=this.opts.hostname;return e.indexOf(`:`)===-1?e:`[`+e+`]`}_port(){return this.opts.port&&(this.opts.secure&&Number(this.opts.port)!==443||!this.opts.secure&&Number(this.opts.port)!==80)?`:`+this.opts.port:``}_query(e){let t=Ve(e);return t.length?`?`+t:``}},We=class extends A{constructor(){super(...arguments),this._polling=!1}get name(){return`polling`}doOpen(){this._poll()}pause(e){this.readyState=`pausing`;let t=()=>{this.readyState=`paused`,e()};if(this._polling||!this.writable){let e=0;this._polling&&(e++,this.once(`pollComplete`,function(){--e||t()})),this.writable||(e++,this.once(`drain`,function(){--e||t()}))}else t()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved(`poll`)}onData(e){Oe(e,this.socket.binaryType).forEach(e=>{if(this.readyState===`opening`&&e.type===`open`&&this.onOpen(),e.type===`close`)return this.onClose({description:`transport closed by the server`}),!1;this.onPacket(e)}),this.readyState!==`closed`&&(this._polling=!1,this.emitReserved(`pollComplete`),this.readyState===`open`&&this._poll())}doClose(){let e=()=>{this.write([{type:`close`}])};this.readyState===`open`?e():this.once(`open`,e)}write(e){this.writable=!1,De(e,e=>{this.doWrite(e,()=>{this.writable=!0,this.emitReserved(`drain`)})})}uri(){let e=this.opts.secure?`https`:`http`,t=this.query||{};return!1!==this.opts.timestampRequests&&(t[this.opts.timestampParam]=Be()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}},Ge=!1;try{Ge=typeof XMLHttpRequest<`u`&&`withCredentials`in new XMLHttpRequest}catch{}var Ke=Ge;function qe(){}var Je=class extends We{constructor(e){if(super(e),typeof location<`u`){let t=location.protocol===`https:`,n=location.port;n||=t?`443`:`80`,this.xd=typeof location<`u`&&e.hostname!==location.hostname||n!==e.port}}doWrite(e,t){let n=this.request({method:`POST`,data:e});n.on(`success`,t),n.on(`error`,(e,t)=>{this.onError(`xhr post error`,e,t)})}doPoll(){let e=this.request();e.on(`data`,this.onData.bind(this)),e.on(`error`,(e,t)=>{this.onError(`xhr poll error`,e,t)}),this.pollXhr=e}},j=class e extends E{constructor(e,t,n){super(),this.createRequest=e,k(this,n),this._opts=n,this._method=n.method||`GET`,this._uri=t,this._data=n.data===void 0?null:n.data,this._create()}_create(){var t;let n=Pe(this._opts,`agent`,`pfx`,`key`,`passphrase`,`cert`,`ca`,`ciphers`,`rejectUnauthorized`,`autoUnref`);n.xdomain=!!this._opts.xd;let r=this._xhr=this.createRequest(n);try{r.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let e in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(e)&&r.setRequestHeader(e,this._opts.extraHeaders[e])}}catch{}if(this._method===`POST`)try{r.setRequestHeader(`Content-type`,`text/plain;charset=UTF-8`)}catch{}try{r.setRequestHeader(`Accept`,`*/*`)}catch{}(t=this._opts.cookieJar)==null||t.addCookies(r),`withCredentials`in r&&(r.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(r.timeout=this._opts.requestTimeout),r.onreadystatechange=()=>{var e;r.readyState===3&&((e=this._opts.cookieJar)==null||e.parseCookies(r.getResponseHeader(`set-cookie`))),r.readyState===4&&(r.status===200||r.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof r.status==`number`?r.status:0)},0))},r.send(this._data)}catch(e){this.setTimeoutFn(()=>{this._onError(e)},0);return}typeof document<`u`&&(this._index=e.requestsCount++,e.requests[this._index]=this)}_onError(e){this.emitReserved(`error`,e,this._xhr),this._cleanup(!0)}_cleanup(t){if(this._xhr!==void 0&&this._xhr!==null){if(this._xhr.onreadystatechange=qe,t)try{this._xhr.abort()}catch{}typeof document<`u`&&delete e.requests[this._index],this._xhr=null}}_onLoad(){let e=this._xhr.responseText;e!==null&&(this.emitReserved(`data`,e),this.emitReserved(`success`),this._cleanup())}abort(){this._cleanup()}};if(j.requestsCount=0,j.requests={},typeof document<`u`){if(typeof attachEvent==`function`)attachEvent(`onunload`,Ye);else if(typeof addEventListener==`function`){let e=`onpagehide`in O?`pagehide`:`unload`;addEventListener(e,Ye,!1)}}function Ye(){for(let e in j.requests)j.requests.hasOwnProperty(e)&&j.requests[e].abort()}var Xe=(function(){let e=Qe({xdomain:!1});return e&&e.responseType!==null})(),Ze=class extends Je{constructor(e){super(e);let t=e&&e.forceBase64;this.supportsBinary=Xe&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new j(Qe,this.uri(),e)}};function Qe(e){let t=e.xdomain;try{if(typeof XMLHttpRequest<`u`&&(!t||Ke))return new XMLHttpRequest}catch{}if(!t)try{return new O[[`Active`,`Object`].join(`X`)](`Microsoft.XMLHTTP`)}catch{}}var $e=typeof navigator<`u`&&typeof navigator.product==`string`&&navigator.product.toLowerCase()===`reactnative`,et=class extends A{get name(){return`websocket`}doOpen(){let e=this.uri(),t=this.opts.protocols,n=$e?{}:Pe(this.opts,`agent`,`perMessageDeflate`,`pfx`,`key`,`passphrase`,`cert`,`ca`,`ciphers`,`rejectUnauthorized`,`localAddress`,`protocolVersion`,`origin`,`maxPayload`,`family`,`checkServerIdentity`);this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(e,t,n)}catch(e){return this.emitReserved(`error`,e)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=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<e.length;t++){let n=e[t],r=t===e.length-1;ge(n,this.supportsBinary,e=>{try{this.doWrite(n,e)}catch{}r&&D(()=>{this.writable=!0,this.emitReserved(`drain`)},this.setTimeoutFn)})}}doClose(){this.ws!==void 0&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){let e=this.opts.secure?`wss`:`ws`,t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=Be()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}},M=O.WebSocket||O.MozWebSocket,tt={websocket:class extends et{createSocket(e,t,n){return $e?new M(e,t,n):t?new M(e,t):new M(e)}doWrite(e,t){this.ws.send(t)}},webtransport:class extends A{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=>{let t=je(2**53-1,this.socket.binaryType),n=e.readable.pipeThrough(t).getReader(),r=ke();r.readable.pipeTo(e.writable),this._writer=r.writable.getWriter();let i=()=>{n.read().then(({done:e,value:t})=>{e||(this.onPacket(t),i())}).catch(e=>{})};i();let a={type:`open`};this.query.sid&&(a.data=`{"sid":"${this.query.sid}"}`),this._writer.write(a).then(()=>this.onOpen())})})}write(e){this.writable=!1;for(let t=0;t<e.length;t++){let n=e[t],r=t===e.length-1;this._writer.write(n).then(()=>{r&&D(()=>{this.writable=!0,this.emitReserved(`drain`)},this.setTimeoutFn)})}}doClose(){var e;(e=this._transport)==null||e.close()}},polling:Ze},nt=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,rt=[`source`,`protocol`,`authority`,`userInfo`,`user`,`password`,`host`,`port`,`relative`,`path`,`directory`,`file`,`query`,`anchor`];function N(e){if(e.length>8e3)throw`URI too long`;let t=e,n=e.indexOf(`[`),r=e.indexOf(`]`);n!=-1&&r!=-1&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,`;`)+e.substring(r,e.length));let i=nt.exec(e||``),a={},o=14;for(;o--;)a[rt[o]]=i[o]||``;return n!=-1&&r!=-1&&(a.source=t,a.host=a.host.substring(1,a.host.length-1).replace(/;/g,`:`),a.authority=a.authority.replace(`[`,``).replace(`]`,``).replace(/;/g,`:`),a.ipv6uri=!0),a.pathNames=it(a,a.path),a.queryKey=at(a,a.query),a}function it(e,t){let n=t.replace(/\/{2,9}/g,`/`).split(`/`);return(t.slice(0,1)==`/`||t.length===0)&&n.splice(0,1),t.slice(-1)==`/`&&n.splice(n.length-1,1),n}function at(e,t){let n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(e,t,r){t&&(n[t]=r)}),n}var P=typeof addEventListener==`function`&&typeof removeEventListener==`function`,F=[];P&&addEventListener(`offline`,()=>{F.forEach(e=>e())},!1);var I=class e extends E{constructor(e,t){if(super(),this.binaryType=Ne,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,e&&typeof e==`object`&&(t=e,e=null),e){let n=N(e);t.hostname=n.host,t.secure=n.protocol===`https`||n.protocol===`wss`,t.port=n.port,n.query&&(t.query=n.query)}else t.host&&(t.hostname=N(t.host).host);k(this,t),this.secure=t.secure==null?typeof location<`u`&&location.protocol===`https:`:t.secure,t.hostname&&!t.port&&(t.port=this.secure?`443`:`80`),this.hostname=t.hostname||(typeof location<`u`?location.hostname:`localhost`),this.port=t.port||(typeof location<`u`&&location.port?location.port:this.secure?`443`:`80`),this.transports=[],this._transportsByName={},t.transports.forEach(e=>{let t=e.prototype.name;this.transports.push(t),this._transportsByName[t]=e}),this.opts=Object.assign({path:`/engine.io`,agent:!1,withCredentials:!1,upgrade:!0,timestampParam:`t`,rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,``)+(this.opts.addTrailingSlash?`/`:``),typeof this.opts.query==`string`&&(this.opts.query=He(this.opts.query)),P&&(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`})},F.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(e){let t=Object.assign({},this.opts.query);t.EIO=4,t.transport=e,this.id&&(t.sid=this.id);let n=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](n)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved(`error`,`No transports available`)},0);return}let t=this.opts.rememberUpgrade&&e.priorWebsocketSuccess&&this.transports.indexOf(`websocket`)!==-1?`websocket`:this.transports[0];this.readyState=`opening`;let n=this.createTransport(t);n.open(),this.setTransport(n)}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`,e=>this._onClose(`transport close`,e))}onOpen(){this.readyState=`open`,e.priorWebsocketSuccess=this.transport.name===`websocket`,this.emitReserved(`open`),this.flush()}_onPacket(e){if(this.readyState===`opening`||this.readyState===`open`||this.readyState===`closing`)switch(this.emitReserved(`packet`,e),this.emitReserved(`heartbeat`),e.type){case`open`:this.onHandshake(JSON.parse(e.data));break;case`ping`:this._sendPacket(`pong`),this.emitReserved(`ping`),this.emitReserved(`pong`),this._resetPingTimeout();break;case`error`:let t=Error(`server error`);t.code=e.data,this._onError(t);break;case`message`:this.emitReserved(`data`,e.data),this.emitReserved(`message`,e.data)}}onHandshake(e){this.emitReserved(`handshake`,e),this.id=e.sid,this.transport.query.sid=e.sid,this._pingInterval=e.pingInterval,this._pingTimeout=e.pingTimeout,this._maxPayload=e.maxPayload,this.onOpen(),this.readyState!==`closed`&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let e=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+e,this._pingTimeoutTimer=this.setTimeoutFn(()=>{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){let 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 e=1;for(let t=0;t<this.writeBuffer.length;t++){let n=this.writeBuffer[t].data;if(n&&(e+=Re(n)),t>0&&e>this._maxPayload)return this.writeBuffer.slice(0,t);e+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;let e=Date.now()>this._pingTimeoutTime;return e&&(this._pingTimeoutTime=0,D(()=>{this._onClose(`ping timeout`)},this.setTimeoutFn)),e}write(e,t,n){return this._sendPacket(`message`,e,t,n),this}send(e,t,n){return this._sendPacket(`message`,e,t,n),this}_sendPacket(e,t,n,r){if(typeof t==`function`&&(r=t,t=void 0),typeof n==`function`&&(r=n,n=null),this.readyState===`closing`||this.readyState===`closed`)return;n||={},n.compress=!1!==n.compress;let i={type:e,data:t,options:n};this.emitReserved(`packetCreate`,i),this.writeBuffer.push(i),r&&this.once(`flush`,r),this.flush()}close(){let e=()=>{this._onClose(`forced close`),this.transport.close()},t=()=>{this.off(`upgrade`,t),this.off(`upgradeError`,t),e()},n=()=>{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?n():e()}):this.upgrading?n():e()),this}_onError(t){if(e.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState===`opening`)return this.transports.shift(),this._open();this.emitReserved(`error`,t),this._onClose(`transport error`,t)}_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(),P&&(this._beforeunloadEventListener&&removeEventListener(`beforeunload`,this._beforeunloadEventListener,!1),this._offlineEventListener)){let e=F.indexOf(this._offlineEventListener);e!==-1&&F.splice(e,1)}this.readyState=`closed`,this.id=null,this.emitReserved(`close`,e,t),this.writeBuffer=[],this._prevBufferLen=0}}};I.protocol=4;var ot=class extends I{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState===`open`&&this.opts.upgrade)for(let e=0;e<this._upgrades.length;e++)this._probe(this._upgrades[e])}_probe(e){let t=this.createTransport(e),n=!1;I.priorWebsocketSuccess=!1;let r=()=>{n||(t.send([{type:`ping`,data:`probe`}]),t.once(`packet`,e=>{if(!n){if(e.type===`pong`&&e.data===`probe`){if(this.upgrading=!0,this.emitReserved(`upgrading`,t),!t)return;I.priorWebsocketSuccess=t.name===`websocket`,this.transport.pause(()=>{n||this.readyState!==`closed`&&(l(),this.setTransport(t),t.send([{type:`upgrade`}]),this.emitReserved(`upgrade`,t),t=null,this.upgrading=!1,this.flush())})}else{let e=Error(`probe error`);e.transport=t.name,this.emitReserved(`upgradeError`,e)}}}))};function i(){n||(n=!0,l(),t.close(),t=null)}let a=e=>{let n=Error(`probe error: `+e);n.transport=t.name,i(),this.emitReserved(`upgradeError`,n)};function o(){a(`transport closed`)}function s(){a(`socket closed`)}function c(e){t&&e.name!==t.name&&i()}let l=()=>{t.removeListener(`open`,r),t.removeListener(`error`,a),t.removeListener(`close`,o),this.off(`close`,s),this.off(`upgrading`,c)};t.once(`open`,r),t.once(`error`,a),t.once(`close`,o),this.once(`close`,s),this.once(`upgrading`,c),this._upgrades.indexOf(`webtransport`)!==-1&&e!==`webtransport`?this.setTimeoutFn(()=>{n||t.open()},200):t.open()}onHandshake(e){this._upgrades=this._filterUpgrades(e.upgrades),super.onHandshake(e)}_filterUpgrades(e){let t=[];for(let n=0;n<e.length;n++)~this.transports.indexOf(e[n])&&t.push(e[n]);return t}},st=class extends ot{constructor(e,t={}){let n=typeof e==`object`,r=n?{...e}:{...t};(!r.transports||r.transports&&typeof r.transports[0]==`string`)&&(r.transports=(r.transports||[`polling`,`websocket`,`webtransport`]).map(e=>tt[e]).filter(e=>!!e)),super(n?r:e,r)}};st.protocol;function ct(e,t=``,n){let r=e;n||=typeof location<`u`&&location,e??=n.protocol+`//`+n.host,typeof e==`string`&&(e.charAt(0)===`/`&&(e=e.charAt(1)===`/`?n.protocol+e:n.host+e),/^(https?|wss?):\/\//.test(e)||(e=n===void 0?`https://`+e:n.protocol+`//`+e),r=N(e)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port=`80`:/^(http|ws)s$/.test(r.protocol)&&(r.port=`443`)),r.path=r.path||`/`;let i=r.host.indexOf(`:`)===-1?r.host:`[`+r.host+`]`;return r.id=r.protocol+`://`+i+`:`+r.port+t,r.href=r.protocol+`://`+i+(n&&n.port===r.port?``:`:`+r.port),r}var lt=typeof ArrayBuffer==`function`,ut=e=>typeof ArrayBuffer.isView==`function`?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,dt=Object.prototype.toString,ft=typeof Blob==`function`||typeof Blob<`u`&&dt.call(Blob)===`[object BlobConstructor]`,pt=typeof File==`function`||typeof File<`u`&&dt.call(File)===`[object FileConstructor]`;function L(e){return lt&&(e instanceof ArrayBuffer||ut(e))||ft&&e instanceof Blob||pt&&e instanceof File}function R(e,t){if(!e||typeof e!=`object`)return!1;if(Array.isArray(e)){for(let t=0,n=e.length;t<n;t++)if(R(e[t]))return!0;return!1}if(L(e))return!0;if(e.toJSON&&typeof e.toJSON==`function`&&arguments.length===1)return R(e.toJSON(),!0);for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t)&&R(e[t]))return!0;return!1}function mt(e){let t=[],n=e.data,r=e;return r.data=z(n,t),r.attachments=t.length,{packet:r,buffers:t}}function z(e,t,n){if(!e)return e;if(L(e)){let n={_placeholder:!0,num:t.length};return t.push(e),n}if(Array.isArray(e)){let n=Array(e.length);for(let r=0;r<e.length;r++)n[r]=z(e[r],t);return n}if(typeof e==`object`&&!(e instanceof Date)){if(e.toJSON&&typeof e.toJSON==`function`&&!n)return z(e.toJSON(),t,!0);let r={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=z(e[n],t));return r}return e}function ht(e,t){return e.data=B(e.data,t),delete e.attachments,e}function B(e,t){if(!e)return e;if(e&&e._placeholder===!0){if(typeof e.num==`number`&&e.num>=0&&e.num<t.length)return t[e.num];throw Error(`illegal attachments`)}if(Array.isArray(e))for(let n=0;n<e.length;n++)e[n]=B(e[n],t);else if(typeof e==`object`)for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(e[n]=B(e[n],t));return e}var gt=n({Decoder:()=>yt,Encoder:()=>vt,PacketType:()=>V,isPacketValid:()=>Tt,protocol:()=>5}),_t=[`connect`,`connect_error`,`disconnect`,`disconnecting`,`newListener`,`removeListener`],V;(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`})(V||={});var vt=class{constructor(e){this.replacer=e}encode(e){return(e.type===V.EVENT||e.type===V.ACK)&&R(e)?this.encodeAsBinary({type:e.type===V.EVENT?V.BINARY_EVENT:V.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let t=``+e.type;return(e.type===V.BINARY_EVENT||e.type===V.BINARY_ACK)&&(t+=e.attachments+`-`),e.nsp&&e.nsp!==`/`&&(t+=e.nsp+`,`),e.id!=null&&(t+=e.id),e.data!=null&&(t+=JSON.stringify(e.data,this.replacer)),t}encodeAsBinary(e){let t=mt(e),n=this.encodeAsString(t.packet),r=t.buffers;return r.unshift(n),r}},yt=class e extends E{constructor(e){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},typeof e==`function`?{reviver:e}:e)}add(e){let t;if(typeof e==`string`){if(this.reconstructor)throw Error(`got plaintext data when reconstructing a packet`);t=this.decodeString(e);let n=t.type===V.BINARY_EVENT;n||t.type===V.BINARY_ACK?(t.type=n?V.EVENT:V.ACK,this.reconstructor=new bt(t)):super.emitReserved(`decoded`,t)}else if(L(e)||e.base64){if(this.reconstructor)t=this.reconstructor.takeBinaryData(e),t&&(this.reconstructor=null,super.emitReserved(`decoded`,t));else throw Error(`got binary data when not reconstructing a packet`)}else throw Error(`Unknown type: `+e)}decodeString(t){let n=0,r={type:Number(t.charAt(0))};if(V[r.type]===void 0)throw Error(`unknown packet type `+r.type);if(r.type===V.BINARY_EVENT||r.type===V.BINARY_ACK){let e=n+1;for(;t.charAt(++n)!==`-`&&n!=t.length;);let i=t.substring(e,n);if(i!=Number(i)||t.charAt(n)!==`-`)throw Error(`Illegal attachments`);let a=Number(i);if(!St(a)||a<1)throw Error(`Illegal attachments`);if(a>this.opts.maxAttachments)throw Error(`too many attachments`);r.attachments=a}if(t.charAt(n+1)===`/`){let e=n+1;for(;++n&&t.charAt(n)!==`,`&&n!==t.length;);r.nsp=t.substring(e,n)}else r.nsp=`/`;let i=t.charAt(n+1);if(i!==``&&Number(i)==i){let e=n+1;for(;++n;){let e=t.charAt(n);if(e==null||Number(e)!=e){--n;break}if(n===t.length)break}r.id=Number(t.substring(e,n+1))}if(t.charAt(++n)){let i=this.tryParse(t.substr(n));if(e.isPayloadValid(r.type,i))r.data=i;else throw Error(`invalid payload`)}return r}tryParse(e){try{return JSON.parse(e,this.opts.reviver)}catch{return!1}}static isPayloadValid(e,t){switch(e){case V.CONNECT:return H(t);case V.DISCONNECT:return t===void 0;case V.CONNECT_ERROR:return typeof t==`string`||H(t);case V.EVENT:case V.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]==`number`||typeof t[0]==`string`&&_t.indexOf(t[0])===-1);case V.ACK:case V.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&=(this.reconstructor.finishedReconstruction(),null)}},bt=class{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){let e=ht(this.reconPack,this.buffers);return this.finishedReconstruction(),e}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};function xt(e){return typeof e==`string`}var St=Number.isInteger||function(e){return typeof e==`number`&&isFinite(e)&&Math.floor(e)===e};function Ct(e){return e===void 0||St(e)}function H(e){return Object.prototype.toString.call(e)===`[object Object]`}function wt(e,t){switch(e){case V.CONNECT:return t===void 0||H(t);case V.DISCONNECT:return t===void 0;case V.EVENT:return Array.isArray(t)&&(typeof t[0]==`number`||typeof t[0]==`string`&&_t.indexOf(t[0])===-1);case V.ACK:return Array.isArray(t);case V.CONNECT_ERROR:return typeof t==`string`||H(t);default:return!1}}function Tt(e){return xt(e.nsp)&&Ct(e.id)&&wt(e.type,e.data)}function U(e,t,n){return e.on(t,n),function(){e.off(t,n)}}var Et=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),Dt=class extends E{constructor(e,t,n){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,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;let e=this.io;this.subs=[U(e,`open`,this.onopen.bind(this)),U(e,`packet`,this.onpacket.bind(this)),U(e,`error`,this.onerror.bind(this)),U(e,`close`,this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(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){if(Et.hasOwnProperty(e))throw 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;let n={type:V.EVENT,data:t};if(n.options={},n.options.compress=this.flags.compress!==!1,typeof t[t.length-1]==`function`){let e=this.ids++,r=t.pop();this._registerAckCallback(e,r),n.id=e}let r=this.io.engine?.transport?.writable,i=this.connected&&!this.io.engine?._hasPingExpired();return this.flags.volatile&&!r||(i?(this.notifyOutgoingListeners(n),this.packet(n)):this.sendBuffer.push(n)),this.flags={},this}_registerAckCallback(e,t){let n=this.flags.timeout??this._opts.ackTimeout;if(n===void 0){this.acks[e]=t;return}let r=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let t=0;t<this.sendBuffer.length;t++)this.sendBuffer[t].id===e&&this.sendBuffer.splice(t,1);t.call(this,Error(`operation has timed out`))},n),i=(...e)=>{this.io.clearTimeoutFn(r),t.apply(this,e)};i.withError=!0,this.acks[e]=i}emitWithAck(e,...t){return new Promise((n,r)=>{let i=(e,t)=>e?r(e):n(t);i.withError=!0,t.push(i),this.emit(e,...t)})}_addToQueue(e){let t;typeof e[e.length-1]==`function`&&(t=e.pop());let n={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((e,...r)=>(this._queue[0],e===null?(this._queue.shift(),t&&t(null,...r)):n.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(e)),n.pending=!1,this._drainQueue())),this._queue.push(n),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||this._queue.length===0)return;let 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:V.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(t=>String(t.id)===e)){let t=this.acks[e];delete this.acks[e],t.withError&&t.call(this,Error(`socket has been disconnected`))}})}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case V.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved(`connect_error`,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 V.EVENT:case V.BINARY_EVENT:this.onevent(e);break;case V.ACK:case V.BINARY_ACK:this.onack(e);break;case V.DISCONNECT:this.ondisconnect();break;case V.CONNECT_ERROR:this.destroy();let t=Error(e.data.message);t.data=e.data.data,this.emitReserved(`connect_error`,t)}}onevent(e){let 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){let t=this._anyListeners.slice();for(let n of t)n.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){let t=this,n=!1;return function(...r){n||(n=!0,t.packet({type:V.ACK,id:e,data:r}))}}onack(e){let 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()),void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:V.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){let t=this._anyListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){let t=this._anyOutgoingListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){let t=this._anyOutgoingListeners.slice();for(let n of t)n.apply(this,e.data)}}};function W(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}W.prototype.duration=function(){var e=this.ms*this.factor**+this.attempts++;if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=Math.floor(t*10)&1?e+n:e-n}return Math.min(e,this.max)|0},W.prototype.reset=function(){this.attempts=0},W.prototype.setMin=function(e){this.ms=e},W.prototype.setMax=function(e){this.max=e},W.prototype.setJitter=function(e){this.jitter=e};var G=class extends E{constructor(e,t){super(),this.nsps={},this.subs=[],e&&typeof e==`object`&&(t=e,e=void 0),t||={},t.path=t.path||`/socket.io`,this.opts=t,k(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(t.randomizationFactor??.5),this.backoff=new W({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(t.timeout==null?2e4:t.timeout),this._readyState=`closed`,this.uri=e;let n=t.parser||gt;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.setMin(e),this)}randomizationFactor(e){var t;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(t=this.backoff)==null||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(t=this.backoff)==null||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 st(this.uri,this.opts);let t=this.engine,n=this;this._readyState=`opening`,this.skipReconnect=!1;let r=U(t,`open`,function(){n.onopen(),e&&e()}),i=t=>{this.cleanup(),this._readyState=`closed`,this.emitReserved(`error`,t),e?e(t):this.maybeReconnectOnOpen()},a=U(t,`error`,i);if(!1!==this._timeout){let e=this._timeout,n=this.setTimeoutFn(()=>{r(),i(Error(`timeout`)),t.close()},e);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}return this.subs.push(r),this.subs.push(a),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState=`open`,this.emitReserved(`open`);let e=this.engine;this.subs.push(U(e,`ping`,this.onping.bind(this)),U(e,`data`,this.ondata.bind(this)),U(e,`error`,this.onerror.bind(this)),U(e,`close`,this.onclose.bind(this)),U(this.decoder,`decoded`,this.ondecoded.bind(this)))}onping(){this.emitReserved(`ping`)}ondata(e){try{this.decoder.add(e)}catch(e){this.onclose(`parse error`,e)}}ondecoded(e){D(()=>{this.emitReserved(`packet`,e)},this.setTimeoutFn)}onerror(e){this.emitReserved(`error`,e)}socket(e,t){let n=this.nsps[e];return n?this._autoConnect&&!n.active&&n.connect():(n=new Dt(this,e,t),this.nsps[e]=n),n}_destroy(e){let t=Object.keys(this.nsps);for(let e of t)if(this.nsps[e].active)return;this._close()}_packet(e){let t=this.encoder.encode(e);for(let n=0;n<t.length;n++)this.engine.write(t[n],e.options)}cleanup(){this.subs.forEach(e=>e()),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 n;this.cleanup(),(n=this.engine)==null||n.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;let e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved(`reconnect_failed`),this._reconnecting=!1;else{let t=this.backoff.duration();this._reconnecting=!0;let n=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved(`reconnect_attempt`,e.backoff.attempts),!e.skipReconnect&&e.open(t=>{t?(e._reconnecting=!1,e.reconnect(),this.emitReserved(`reconnect_error`,t)):e.onreconnect()}))},t);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}}onreconnect(){let e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved(`reconnect`,e)}},K={};function q(e,t){typeof e==`object`&&(t=e,e=void 0),t||={};let n=ct(e,t.path||`/socket.io`),r=n.source,i=n.id,a=n.path,o=K[i]&&a in K[i].nsps,s=t.forceNew||t[`force new connection`]||!1===t.multiplex||o,c;return s?c=new G(r,t):(K[i]||(K[i]=new G(r,t)),c=K[i]),n.query&&!t.query&&(t.query=n.queryKey),c.socket(n.path,t)}Object.assign(q,{Manager:G,Socket:Dt,io:q,connect:q});function Ot(e){let t=e.replace(/\/$/,``);try{return`${new URL(t).origin}/sdk`}catch{return`${t}/sdk`}}var kt=class{constructor(){this.socket=null}get connected(){return this.socket?.connected??!1}connect(e){this.disconnect();let t=Ot(e.baseUrl);this.socket=q(t,{auth:{apiKey:e.apiKey,visitorToken:e.visitorToken},transports:[`websocket`,`polling`],autoConnect:!0,reconnection:!0});let n=!1;this.socket.on(`connect`,()=>{n?e.onReconnect?.():n=!0}),this.socket.on(`ticket:status`,t=>{e.onTicketStatus?.(t)}),this.socket.on(`message:receive`,t=>{e.onMessageReceive?.(t)}),this.socket.on(`connect_error`,t=>{e.onConnectError?.(t)})}disconnect(){this.socket&&=(this.socket.removeAllListeners(),this.socket.disconnect(),null)}},J=`onedeskpro_visitor_token`;function At(e){try{return typeof window<`u`?window.localStorage.getItem(e):null}catch{return null}}function jt(e,t){try{typeof window<`u`&&window.localStorage.setItem(e,t)}catch{}}function Mt(e){try{typeof window<`u`&&window.localStorage.removeItem(e)}catch{}}var Nt=class{constructor(){this.token=null,this.storageKey=J}setScope(e){this.storageKey=e?.trim()?`${J}:${e.trim()}`:J,this.token=At(this.storageKey)}get(){return this.token??At(this.storageKey)}set(e){this.token=e,jt(this.storageKey,e)}clear(){this.token=null,Mt(this.storageKey)}},Pt=300,Ft=250,It=100,Lt=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg;codecs=opus`];function Rt(){return typeof MediaRecorder>`u`||typeof MediaRecorder.isTypeSupported!=`function`?`audio/webm`:Lt.find(e=>MediaRecorder.isTypeSupported(e))??`audio/webm`}function zt(e){let t=e instanceof DOMException?e.name:``;return t===`NotAllowedError`||t===`PermissionDeniedError`||t===`SecurityError`?`Microphone access was denied.`:t===`NotFoundError`||t===`DevicesNotFoundError`?`No microphone was found.`:`Could not start recording.`}var Y=class e{constructor(e,t=300){this.onChange=e,this.maxDurationSeconds=t,this.recorder=null,this.stream=null,this.chunks=[],this.mimeType=`audio/webm`,this.startedAt=0,this.tickTimer=null,this.levelTimer=null,this.maxTimer=null,this.audioContext=null,this.analyser=null,this.snapshot={state:`idle`,elapsedSeconds:0,level:0,result:null}}static isSupported(){return typeof navigator<`u`&&typeof navigator.mediaDevices?.getUserMedia==`function`&&typeof MediaRecorder<`u`}getSnapshot(){return{...this.snapshot}}async start(){if(!e.isSupported())throw Error(`Voice messages are not supported in this browser.`);this.release(),this.chunks=[];let t;try{t=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){throw Error(zt(e))}try{this.mimeType=Rt();let e=new MediaRecorder(t,{mimeType:this.mimeType});e.ondataavailable=e=>{e.data.size>0&&this.chunks.push(e.data)},this.stream=t,this.recorder=e,this.startedAt=Date.now(),e.start(200)}catch(e){throw t.getTracks().forEach(e=>e.stop()),this.stream=null,this.recorder=null,Error(zt(e))}this.startLevelMeter(t),this.tickTimer=setInterval(()=>{this.update({elapsedSeconds:Math.floor(this.elapsedMs()/1e3)})},Ft),this.maxTimer=setTimeout(()=>void this.stop(),this.maxDurationSeconds*1e3),this.update({state:`recording`,elapsedSeconds:0,level:0,result:null})}async stop(){let e=this.recorder;if(!e||e.state===`inactive`)return this.release(),null;let t=Math.max(1,Math.round(this.elapsedMs()/1e3));this.clearTimers();let n=await new Promise(t=>{e.onstop=()=>{let e=this.chunks;this.chunks=[],t(new Blob(e,{type:_(this.mimeType)}))};try{e.stop()}catch{t(new Blob(this.chunks,{type:_(this.mimeType)}))}});this.releaseMedia();let r={blob:n,mimeType:_(this.mimeType),durationSeconds:t};return this.update({state:`preview`,elapsedSeconds:t,level:0,result:r}),r}cancel(){this.release(),this.update({state:`idle`,elapsedSeconds:0,level:0,result:null})}destroy(){this.release(),this.snapshot={state:`idle`,elapsedSeconds:0,level:0,result:null}}update(e){this.snapshot={...this.snapshot,...e},this.onChange({...this.snapshot})}elapsedMs(){return this.startedAt>0?Date.now()-this.startedAt:0}startLevelMeter(e){let t=typeof window>`u`?null:window,n=t?.AudioContext??t?.webkitAudioContext;if(n)try{let t=new n,r=t.createAnalyser();r.fftSize=256,t.createMediaStreamSource(e).connect(r),t.resume().catch(()=>void 0),this.audioContext=t,this.analyser=r;let i=new Uint8Array(r.frequencyBinCount);this.levelTimer=setInterval(()=>{r.getByteTimeDomainData(i);let e=0;for(let t=0;t<i.length;t++){let n=((i[t]??128)-128)/128;e+=n*n}this.update({level:Math.min(1,Math.sqrt(e/i.length)*3.2)})},It)}catch{}}clearTimers(){this.tickTimer&&clearInterval(this.tickTimer),this.levelTimer&&clearInterval(this.levelTimer),this.maxTimer&&clearTimeout(this.maxTimer),this.tickTimer=null,this.levelTimer=null,this.maxTimer=null}releaseMedia(){this.stream?.getTracks().forEach(e=>e.stop()),this.stream=null,this.recorder=null,this.analyser=null,this.audioContext&&=(this.audioContext.close().catch(()=>void 0),null),this.startedAt=0}release(){if(this.clearTimers(),this.recorder&&this.recorder.state!==`inactive`){this.recorder.onstop=null;try{this.recorder.stop()}catch{}}this.chunks=[],this.releaseMedia()}},X=[{iso:`BD`,name:`Bangladesh`,dial:`880`,flag:`🇧🇩`},{iso:`US`,name:`United States`,dial:`1`,flag:`🇺🇸`},{iso:`GB`,name:`United Kingdom`,dial:`44`,flag:`🇬🇧`},{iso:`IN`,name:`India`,dial:`91`,flag:`🇮🇳`},{iso:`PK`,name:`Pakistan`,dial:`92`,flag:`🇵🇰`},{iso:`AE`,name:`United Arab Emirates`,dial:`971`,flag:`🇦🇪`},{iso:`SA`,name:`Saudi Arabia`,dial:`966`,flag:`🇸🇦`},{iso:`CA`,name:`Canada`,dial:`1`,flag:`🇨🇦`},{iso:`AU`,name:`Australia`,dial:`61`,flag:`🇦🇺`},{iso:`DE`,name:`Germany`,dial:`49`,flag:`🇩🇪`},{iso:`FR`,name:`France`,dial:`33`,flag:`🇫🇷`},{iso:`IT`,name:`Italy`,dial:`39`,flag:`🇮🇹`},{iso:`ES`,name:`Spain`,dial:`34`,flag:`🇪🇸`},{iso:`NL`,name:`Netherlands`,dial:`31`,flag:`🇳🇱`},{iso:`SE`,name:`Sweden`,dial:`46`,flag:`🇸🇪`},{iso:`NO`,name:`Norway`,dial:`47`,flag:`🇳🇴`},{iso:`DK`,name:`Denmark`,dial:`45`,flag:`🇩🇰`},{iso:`FI`,name:`Finland`,dial:`358`,flag:`🇫🇮`},{iso:`IE`,name:`Ireland`,dial:`353`,flag:`🇮🇪`},{iso:`CH`,name:`Switzerland`,dial:`41`,flag:`🇨🇭`},{iso:`AT`,name:`Austria`,dial:`43`,flag:`🇦🇹`},{iso:`BE`,name:`Belgium`,dial:`32`,flag:`🇧🇪`},{iso:`PT`,name:`Portugal`,dial:`351`,flag:`🇵🇹`},{iso:`PL`,name:`Poland`,dial:`48`,flag:`🇵🇱`},{iso:`CZ`,name:`Czechia`,dial:`420`,flag:`🇨🇿`},{iso:`RO`,name:`Romania`,dial:`40`,flag:`🇷🇴`},{iso:`HU`,name:`Hungary`,dial:`36`,flag:`🇭🇺`},{iso:`GR`,name:`Greece`,dial:`30`,flag:`🇬🇷`},{iso:`TR`,name:`Turkey`,dial:`90`,flag:`🇹🇷`},{iso:`RU`,name:`Russia`,dial:`7`,flag:`🇷🇺`},{iso:`UA`,name:`Ukraine`,dial:`380`,flag:`🇺🇦`},{iso:`CN`,name:`China`,dial:`86`,flag:`🇨🇳`},{iso:`JP`,name:`Japan`,dial:`81`,flag:`🇯🇵`},{iso:`KR`,name:`South Korea`,dial:`82`,flag:`🇰🇷`},{iso:`SG`,name:`Singapore`,dial:`65`,flag:`🇸🇬`},{iso:`MY`,name:`Malaysia`,dial:`60`,flag:`🇲🇾`},{iso:`ID`,name:`Indonesia`,dial:`62`,flag:`🇮🇩`},{iso:`TH`,name:`Thailand`,dial:`66`,flag:`🇹🇭`},{iso:`VN`,name:`Vietnam`,dial:`84`,flag:`🇻🇳`},{iso:`PH`,name:`Philippines`,dial:`63`,flag:`🇵🇭`},{iso:`HK`,name:`Hong Kong`,dial:`852`,flag:`🇭🇰`},{iso:`TW`,name:`Taiwan`,dial:`886`,flag:`🇹🇼`},{iso:`NZ`,name:`New Zealand`,dial:`64`,flag:`🇳🇿`},{iso:`ZA`,name:`South Africa`,dial:`27`,flag:`🇿🇦`},{iso:`NG`,name:`Nigeria`,dial:`234`,flag:`🇳🇬`},{iso:`KE`,name:`Kenya`,dial:`254`,flag:`🇰🇪`},{iso:`EG`,name:`Egypt`,dial:`20`,flag:`🇪🇬`},{iso:`MA`,name:`Morocco`,dial:`212`,flag:`🇲🇦`},{iso:`BR`,name:`Brazil`,dial:`55`,flag:`🇧🇷`},{iso:`MX`,name:`Mexico`,dial:`52`,flag:`🇲🇽`},{iso:`AR`,name:`Argentina`,dial:`54`,flag:`🇦🇷`},{iso:`CL`,name:`Chile`,dial:`56`,flag:`🇨🇱`},{iso:`CO`,name:`Colombia`,dial:`57`,flag:`🇨🇴`},{iso:`PE`,name:`Peru`,dial:`51`,flag:`🇵🇪`},{iso:`IL`,name:`Israel`,dial:`972`,flag:`🇮🇱`},{iso:`QA`,name:`Qatar`,dial:`974`,flag:`🇶🇦`},{iso:`KW`,name:`Kuwait`,dial:`965`,flag:`🇰🇼`},{iso:`BH`,name:`Bahrain`,dial:`973`,flag:`🇧🇭`},{iso:`OM`,name:`Oman`,dial:`968`,flag:`🇴🇲`},{iso:`LK`,name:`Sri Lanka`,dial:`94`,flag:`🇱🇰`},{iso:`NP`,name:`Nepal`,dial:`977`,flag:`🇳🇵`}],Bt=X.find(e=>e.iso===`BD`)??X[0];function Vt(e,t){let n=t.trim();if(n.startsWith(`+`)){let e=n.replace(/\D/g,``);return e?`+${e}`:``}let r=n.replace(/\D/g,``);return!r||(r=r.replace(/^0+/,``),!r)?``:`+${e}${r}`}var Ht=`(max-width: 640px), (max-height: 500px) and (pointer: coarse)`;function Ut(e,t){let n=`
1
+ var OnedeskProChatbot=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},r=3e4,i=12e4;function a(e){return typeof e==`object`&&!!e&&typeof e.message==`string`}function o(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.type==`string`&&typeof t.url==`string`&&typeof t.fileName==`string`&&typeof t.size==`number`}function s(e){return e instanceof Error&&`apiError`in e&&`status`in e&&typeof e.status==`number`&&a(e.apiError)}var c=class{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,``),this.apiKey=e.apiKey,this.timeoutMs=e.timeoutMs??3e4,this.uploadTimeoutMs=e.uploadTimeoutMs??i}fail(e,t,n,r){let i={statusCode:t,message:e,code:n,timestamp:new Date().toISOString(),path:r};throw Object.assign(Error(e),{apiError:i,status:t})}async request(e,t,n,r,i,o=this.timeoutMs){let s=new URL(`${this.baseUrl}${t}`);if(r)for(let[e,t]of Object.entries(r))s.searchParams.set(e,t);let c=typeof FormData<`u`&&n instanceof FormData,l={...c?{}:{"Content-Type":`application/json`},"X-API-Key":this.apiKey,...i},u=new AbortController,d=setTimeout(()=>u.abort(),o),f;try{f=await fetch(s.toString(),{method:e,headers:l,signal:u.signal,...n===void 0?{}:{body:c?n:JSON.stringify(n)}})}catch(e){u.signal.aborted&&this.fail(`Request timed out after ${o}ms.`,0,`TIMEOUT`,t),this.fail(e instanceof Error?e.message:`Network request failed.`,0,`NETWORK_ERROR`,t)}finally{clearTimeout(d)}let p=await f.text(),m=null;if(p)try{m=JSON.parse(p)}catch{m=null}if(!f.ok){if(a(m))throw Object.assign(Error(m.message),{apiError:m,status:f.status});this.fail(`Request failed with status ${f.status} ${f.statusText}`.trim(),f.status,`HTTP_ERROR`,t)}return m===null&&this.fail(`The server returned an empty or malformed response.`,f.status,`BAD_RESPONSE`,t),m.data}async identify(e){return this.request(`POST`,`/sdk/identify`,e)}async verifyVisitor(e){return this.request(`GET`,`/sdk/visitor`,void 0,void 0,{"X-Visitor-Token":e})}async sendMessage(e){return this.request(`POST`,`/sdk/chat`,e)}async uploadAttachment(e,t){let n=new FormData;n.append(`file`,e,e.name);let r=await this.request(`POST`,`/sdk/upload`,n,void 0,{"X-Visitor-Token":t},this.uploadTimeoutMs);return o(r)||this.fail(`The server returned an unexpected upload response.`,200,`BAD_RESPONSE`,`/sdk/upload`),r}async fetchConfig(){return this.request(`GET`,`/sdk/config`)}async requestHuman(e){return this.request(`POST`,`/sdk/human-request`,{visitorToken:e})}async fetchTicketStatus(e){return this.request(`GET`,`/sdk/ticket-status`,void 0,void 0,{"X-Visitor-Token":e})}},l=`https://api.onedeskpro.com`,u=10485760,d=10;function f(e){if(e.length>10)return`You can send up to 10 files at a time.`;let t=e.find(e=>e.size>u);if(t){let e=Math.round(u/1048576);return`"${t.name||`This file`}" is larger than ${e} MB.`}return null}function p(e){return/^(https?:\/\/|blob:)/i.test(e)}function m(e){return typeof URL>`u`||typeof URL.createObjectURL!=`function`?``:URL.createObjectURL(e)}function h(e){e.startsWith(`blob:`)&&typeof URL<`u`&&typeof URL.revokeObjectURL==`function`&&URL.revokeObjectURL(e)}function ee(e){return{type:e.type||`application/octet-stream`,url:m(e),fileName:e.name||`attachment`,size:e.size}}function te(e){return!Number.isFinite(e)||e<0?``:e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(+(e<10240))} KB`:`${(e/1048576).toFixed(1)} MB`}function ne(e){if(!e||typeof e!=`object`)return[];let t=e,n=t.attachments;if(!Array.isArray(n)&&t.message&&typeof t.message==`object`&&(n=t.message.attachments),!Array.isArray(n))return[];let r=[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=e;typeof t.url==`string`&&/^https?:\/\//i.test(t.url)&&r.push({type:typeof t.type==`string`&&t.type?t.type:`application/octet-stream`,url:t.url,fileName:typeof t.fileName==`string`&&t.fileName?t.fileName:`attachment`,size:typeof t.size==`number`&&t.size>=0?t.size:0,...typeof t.durationSeconds==`number`?{durationSeconds:t.durationSeconds}:{}})}return r}function re(e,t){let n=e.trim();return n?t.length===0?!1:t.some(e=>e.fileName===n)||/^\d+ files?$/.test(n)?!0:[`Image`,`Video`,`Audio`,`Attachment`].includes(n):!0}var g=16e3;function _(e){return(e??``).split(`;`)[0].trim().toLowerCase()||`audio/webm`}function ie(e){return e.includes(`mpeg`)||e.includes(`mp3`)?`mp3`:e.includes(`wav`)?`wav`:e.includes(`mp4`)||e.includes(`m4a`)?`m4a`:e.includes(`ogg`)?`ogg`:`webm`}function v(e){if(!Number.isFinite(e)||e<0)return`0:00`;let t=Math.floor(e),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,`0`)}`}function ae(){if(typeof window>`u`)return null;let e=window;return e.AudioContext??e.webkitAudioContext??null}function oe(){if(typeof window>`u`)return null;let e=window;return e.OfflineAudioContext??e.webkitOfflineAudioContext??null}async function se(e){let t=ae();if(!t)return null;let n=new t;try{let t=await e.arrayBuffer();return await n.decodeAudioData(t.slice(0))}catch{return null}finally{await n.close().catch(()=>void 0)}}async function ce(e){let t=oe();if(t)try{let n=new t(1,Math.max(1,Math.ceil(e.duration*g)),g),r=n.createBufferSource();return r.buffer=e,r.connect(n.destination),r.start(0),{samples:(await n.startRendering()).getChannelData(0),sampleRate:g}}catch{}return{samples:e.getChannelData(0),sampleRate:e.sampleRate}}function le(e,t){let n=e.length*2,r=new ArrayBuffer(44+n),i=new DataView(r),a=(e,t)=>{for(let n=0;n<t.length;n++)i.setUint8(e+n,t.charCodeAt(n))};a(0,`RIFF`),i.setUint32(4,36+n,!0),a(8,`WAVE`),a(12,`fmt `),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,1,!0),i.setUint32(24,t,!0),i.setUint32(28,t*2,!0),i.setUint16(32,2,!0),i.setUint16(34,16,!0),a(36,`data`),i.setUint32(40,n,!0);let o=44;for(let t=0;t<e.length;t++){let n=Math.max(-1,Math.min(1,e[t]??0));i.setInt16(o,Math.round(n<0?n*32768:n*32767),!0),o+=2}return new Blob([r],{type:`audio/wav`})}function ue(e,t=48){if(e.length===0)return[];let n=Math.max(1,Math.floor(e.length/t)),r=[],i=0;for(let a=0;a<t;a++){let t=a*n,o=Math.min(t+n,e.length),s=0;for(let n=t;n<o;n++){let t=e[n]??0;s+=t*t}let c=o>t?Math.sqrt(s/(o-t)):0;r.push(c),c>i&&(i=c)}return r.map(e=>i>0?Math.max(8,Math.min(100,Math.round(e/i*100))):8)}async function de(e){let t=Date.now(),n=Math.max(1,Math.round(e.durationSeconds||1)),r=_(e.mimeType??e.blob.type),i=await se(e.blob);if(!i)return{file:new File([e.blob],`voice-message-${t}.${ie(r)}`,{type:r}),durationSeconds:n};let{samples:a,sampleRate:o}=await ce(i);return{file:new File([le(a,o)],`voice-message-${t}.wav`,{type:`audio/wav`}),durationSeconds:Math.max(1,Math.round(i.duration||n)),waveform:ue(a)}}var fe=class{constructor(){this._listeners={}}on(e,t){return this._listeners[e]||(this._listeners[e]=[]),this._listeners[e].push(t),()=>this.off(e,t)}off(e,t){let n=this._listeners[e];n&&(this._listeners[e]=n.filter(e=>e!==t))}emit(e,...t){let n=this._listeners[e];if(n)for(let e of n)e(...t)}removeAllListeners(){for(let e of Object.keys(this._listeners))delete this._listeners[e]}},y=Object.create(null);y.open=`0`,y.close=`1`,y.ping=`2`,y.pong=`3`,y.message=`4`,y.upgrade=`5`,y.noop=`6`;var b=Object.create(null);Object.keys(y).forEach(e=>{b[y[e]]=e});var x={type:`error`,data:`parser error`},pe=typeof Blob==`function`||typeof Blob<`u`&&Object.prototype.toString.call(Blob)===`[object BlobConstructor]`,me=typeof ArrayBuffer==`function`,he=e=>typeof ArrayBuffer.isView==`function`?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,ge=({type:e,data:t},n,r)=>pe&&t instanceof Blob?n?r(t):_e(t,r):me&&(t instanceof ArrayBuffer||he(t))?n?r(t):_e(new Blob([t]),r):r(y[e]+(t||``)),_e=(e,t)=>{let n=new FileReader;return n.onload=function(){let e=n.result.split(`,`)[1];t(`b`+(e||``))},n.readAsDataURL(e)};function ve(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var ye;function be(e,t){if(pe&&e.data instanceof Blob)return e.data.arrayBuffer().then(ve).then(t);if(me&&(e.data instanceof ArrayBuffer||he(e.data)))return t(ve(e.data));ge(e,!1,e=>{ye||=new TextEncoder,t(ye.encode(e))})}var xe=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,S=typeof Uint8Array>`u`?[]:new Uint8Array(256);for(let e=0;e<64;e++)S[xe.charCodeAt(e)]=e;var Se=e=>{let t=e.length*.75,n=e.length,r,i=0,a,o,s,c;e[e.length-1]===`=`&&(t--,e[e.length-2]===`=`&&t--);let l=new ArrayBuffer(t),u=new Uint8Array(l);for(r=0;r<n;r+=4)a=S[e.charCodeAt(r)],o=S[e.charCodeAt(r+1)],s=S[e.charCodeAt(r+2)],c=S[e.charCodeAt(r+3)],u[i++]=a<<2|o>>4,u[i++]=(o&15)<<4|s>>2,u[i++]=(s&3)<<6|c&63;return l},Ce=typeof ArrayBuffer==`function`,C=(e,t)=>{if(typeof e!=`string`)return{type:`message`,data:Te(e,t)};let n=e.charAt(0);return n===`b`?{type:`message`,data:we(e.substring(1),t)}:b[n]?e.length>1?{type:b[n],data:e.substring(1)}:{type:b[n]}:x},we=(e,t)=>Ce?Te(Se(e),t):{base64:!0,data:e},Te=(e,t)=>{switch(t){case`blob`:return e instanceof Blob?e:new Blob([e]);default:return e instanceof ArrayBuffer?e:e.buffer}},Ee=``,De=(e,t)=>{let n=e.length,r=Array(n),i=0;e.forEach((e,a)=>{ge(e,!1,e=>{r[a]=e,++i===n&&t(r.join(Ee))})})},Oe=(e,t)=>{let n=e.split(Ee),r=[];for(let e=0;e<n.length;e++){let i=C(n[e],t);if(r.push(i),i.type===`error`)break}return r};function ke(){return new TransformStream({transform(e,t){be(e,n=>{let r=n.length,i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);let e=new DataView(i.buffer);e.setUint8(0,126),e.setUint16(1,r)}else{i=new Uint8Array(9);let e=new DataView(i.buffer);e.setUint8(0,127),e.setBigUint64(1,BigInt(r))}e.data&&typeof e.data!=`string`&&(i[0]|=128),t.enqueue(i),t.enqueue(n)})}})}var Ae;function w(e){return e.reduce((e,t)=>e+t.length,0)}function T(e,t){if(e[0].length===t)return e.shift();let n=new Uint8Array(t),r=0;for(let i=0;i<t;i++)n[i]=e[0][r++],r===e[0].length&&(e.shift(),r=0);return e.length&&r<e[0].length&&(e[0]=e[0].slice(r)),n}function je(e,t){Ae||=new TextDecoder;let n=[],r=0,i=-1,a=!1;return new TransformStream({transform(o,s){for(n.push(o);;){if(r===0){if(w(n)<1)break;let e=T(n,1);a=(e[0]&128)==128,i=e[0]&127,r=i<126?3:i===126?1:2}else if(r===1){if(w(n)<2)break;let e=T(n,2);i=new DataView(e.buffer,e.byteOffset,e.length).getUint16(0),r=3}else if(r===2){if(w(n)<8)break;let e=T(n,8),t=new DataView(e.buffer,e.byteOffset,e.length),a=t.getUint32(0);if(a>2**21-1){s.enqueue(x);break}i=a*2**32+t.getUint32(4),r=3}else{if(w(n)<i)break;let e=T(n,i);s.enqueue(C(a?e:Ae.decode(e),t)),r=0}if(i===0||i>e){s.enqueue(x);break}}}})}function E(e){if(e)return Me(e)}function Me(e){for(var t in E.prototype)e[t]=E.prototype[t];return e}E.prototype.on=E.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks[`$`+e]=this._callbacks[`$`+e]||[]).push(t),this},E.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},E.prototype.off=E.prototype.removeListener=E.prototype.removeAllListeners=E.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks[`$`+e];if(!n)return this;if(arguments.length==1)return delete this._callbacks[`$`+e],this;for(var r,i=0;i<n.length;i++)if(r=n[i],r===t||r.fn===t){n.splice(i,1);break}return n.length===0&&delete this._callbacks[`$`+e],this},E.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=Array(arguments.length-1),n=this._callbacks[`$`+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(n){n=n.slice(0);for(var r=0,i=n.length;r<i;++r)n[r].apply(this,t)}return this},E.prototype.emitReserved=E.prototype.emit,E.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks[`$`+e]||[]},E.prototype.hasListeners=function(e){return!!this.listeners(e).length};var D=typeof Promise==`function`&&typeof Promise.resolve==`function`?e=>Promise.resolve().then(e):(e,t)=>t(e,0),O=typeof self<`u`?self:typeof window<`u`?window:Function(`return this`)(),Ne=`arraybuffer`;function Pe(e,...t){return t.reduce((t,n)=>(e.hasOwnProperty(n)&&(t[n]=e[n]),t),{})}var Fe=O.setTimeout,Ie=O.clearTimeout;function k(e,t){t.useNativeTimers?(e.setTimeoutFn=Fe.bind(O),e.clearTimeoutFn=Ie.bind(O)):(e.setTimeoutFn=O.setTimeout.bind(O),e.clearTimeoutFn=O.clearTimeout.bind(O))}var Le=1.33;function Re(e){return typeof e==`string`?ze(e):Math.ceil((e.byteLength||e.size)*Le)}function ze(e){let t=0,n=0;for(let r=0,i=e.length;r<i;r++)t=e.charCodeAt(r),t<128?n+=1:t<2048?n+=2:t<55296||t>=57344?n+=3:(r++,n+=4);return n}function Be(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function Ve(e){let t=``;for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+=`&`),t+=encodeURIComponent(n)+`=`+encodeURIComponent(e[n]));return t}function He(e){let t={},n=e.split(`&`);for(let e=0,r=n.length;e<r;e++){let r=n[e].split(`=`);t[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return t}var Ue=class extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type=`TransportError`}},A=class extends E{constructor(e){super(),this.writable=!1,k(this,e),this.opts=e,this.query=e.query,this.socket=e.socket,this.supportsBinary=!e.forceBase64}onError(e,t,n){return super.emitReserved(`error`,new Ue(e,t,n)),this}open(){return this.readyState=`opening`,this.doOpen(),this}close(){return(this.readyState===`opening`||this.readyState===`open`)&&(this.doClose(),this.onClose()),this}send(e){this.readyState===`open`&&this.write(e)}onOpen(){this.readyState=`open`,this.writable=!0,super.emitReserved(`open`)}onData(e){let t=C(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved(`packet`,e)}onClose(e){this.readyState=`closed`,super.emitReserved(`close`,e)}pause(e){}createUri(e,t={}){return e+`://`+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){let e=this.opts.hostname;return e.indexOf(`:`)===-1?e:`[`+e+`]`}_port(){return this.opts.port&&(this.opts.secure&&Number(this.opts.port)!==443||!this.opts.secure&&Number(this.opts.port)!==80)?`:`+this.opts.port:``}_query(e){let t=Ve(e);return t.length?`?`+t:``}},We=class extends A{constructor(){super(...arguments),this._polling=!1}get name(){return`polling`}doOpen(){this._poll()}pause(e){this.readyState=`pausing`;let t=()=>{this.readyState=`paused`,e()};if(this._polling||!this.writable){let e=0;this._polling&&(e++,this.once(`pollComplete`,function(){--e||t()})),this.writable||(e++,this.once(`drain`,function(){--e||t()}))}else t()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved(`poll`)}onData(e){Oe(e,this.socket.binaryType).forEach(e=>{if(this.readyState===`opening`&&e.type===`open`&&this.onOpen(),e.type===`close`)return this.onClose({description:`transport closed by the server`}),!1;this.onPacket(e)}),this.readyState!==`closed`&&(this._polling=!1,this.emitReserved(`pollComplete`),this.readyState===`open`&&this._poll())}doClose(){let e=()=>{this.write([{type:`close`}])};this.readyState===`open`?e():this.once(`open`,e)}write(e){this.writable=!1,De(e,e=>{this.doWrite(e,()=>{this.writable=!0,this.emitReserved(`drain`)})})}uri(){let e=this.opts.secure?`https`:`http`,t=this.query||{};return!1!==this.opts.timestampRequests&&(t[this.opts.timestampParam]=Be()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}},Ge=!1;try{Ge=typeof XMLHttpRequest<`u`&&`withCredentials`in new XMLHttpRequest}catch{}var Ke=Ge;function qe(){}var Je=class extends We{constructor(e){if(super(e),typeof location<`u`){let t=location.protocol===`https:`,n=location.port;n||=t?`443`:`80`,this.xd=typeof location<`u`&&e.hostname!==location.hostname||n!==e.port}}doWrite(e,t){let n=this.request({method:`POST`,data:e});n.on(`success`,t),n.on(`error`,(e,t)=>{this.onError(`xhr post error`,e,t)})}doPoll(){let e=this.request();e.on(`data`,this.onData.bind(this)),e.on(`error`,(e,t)=>{this.onError(`xhr poll error`,e,t)}),this.pollXhr=e}},j=class e extends E{constructor(e,t,n){super(),this.createRequest=e,k(this,n),this._opts=n,this._method=n.method||`GET`,this._uri=t,this._data=n.data===void 0?null:n.data,this._create()}_create(){var t;let n=Pe(this._opts,`agent`,`pfx`,`key`,`passphrase`,`cert`,`ca`,`ciphers`,`rejectUnauthorized`,`autoUnref`);n.xdomain=!!this._opts.xd;let r=this._xhr=this.createRequest(n);try{r.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let e in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(e)&&r.setRequestHeader(e,this._opts.extraHeaders[e])}}catch{}if(this._method===`POST`)try{r.setRequestHeader(`Content-type`,`text/plain;charset=UTF-8`)}catch{}try{r.setRequestHeader(`Accept`,`*/*`)}catch{}(t=this._opts.cookieJar)==null||t.addCookies(r),`withCredentials`in r&&(r.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(r.timeout=this._opts.requestTimeout),r.onreadystatechange=()=>{var e;r.readyState===3&&((e=this._opts.cookieJar)==null||e.parseCookies(r.getResponseHeader(`set-cookie`))),r.readyState===4&&(r.status===200||r.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof r.status==`number`?r.status:0)},0))},r.send(this._data)}catch(e){this.setTimeoutFn(()=>{this._onError(e)},0);return}typeof document<`u`&&(this._index=e.requestsCount++,e.requests[this._index]=this)}_onError(e){this.emitReserved(`error`,e,this._xhr),this._cleanup(!0)}_cleanup(t){if(this._xhr!==void 0&&this._xhr!==null){if(this._xhr.onreadystatechange=qe,t)try{this._xhr.abort()}catch{}typeof document<`u`&&delete e.requests[this._index],this._xhr=null}}_onLoad(){let e=this._xhr.responseText;e!==null&&(this.emitReserved(`data`,e),this.emitReserved(`success`),this._cleanup())}abort(){this._cleanup()}};if(j.requestsCount=0,j.requests={},typeof document<`u`){if(typeof attachEvent==`function`)attachEvent(`onunload`,Ye);else if(typeof addEventListener==`function`){let e=`onpagehide`in O?`pagehide`:`unload`;addEventListener(e,Ye,!1)}}function Ye(){for(let e in j.requests)j.requests.hasOwnProperty(e)&&j.requests[e].abort()}var Xe=(function(){let e=Qe({xdomain:!1});return e&&e.responseType!==null})(),Ze=class extends Je{constructor(e){super(e);let t=e&&e.forceBase64;this.supportsBinary=Xe&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new j(Qe,this.uri(),e)}};function Qe(e){let t=e.xdomain;try{if(typeof XMLHttpRequest<`u`&&(!t||Ke))return new XMLHttpRequest}catch{}if(!t)try{return new O.ActiveXObject(`Microsoft.XMLHTTP`)}catch{}}var $e=typeof navigator<`u`&&typeof navigator.product==`string`&&navigator.product.toLowerCase()===`reactnative`,et=class extends A{get name(){return`websocket`}doOpen(){let e=this.uri(),t=this.opts.protocols,n=$e?{}:Pe(this.opts,`agent`,`perMessageDeflate`,`pfx`,`key`,`passphrase`,`cert`,`ca`,`ciphers`,`rejectUnauthorized`,`localAddress`,`protocolVersion`,`origin`,`maxPayload`,`family`,`checkServerIdentity`);this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(e,t,n)}catch(e){return this.emitReserved(`error`,e)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=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<e.length;t++){let n=e[t],r=t===e.length-1;ge(n,this.supportsBinary,e=>{try{this.doWrite(n,e)}catch{}r&&D(()=>{this.writable=!0,this.emitReserved(`drain`)},this.setTimeoutFn)})}}doClose(){this.ws!==void 0&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){let e=this.opts.secure?`wss`:`ws`,t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=Be()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}},M=O.WebSocket||O.MozWebSocket,tt={websocket:class extends et{createSocket(e,t,n){return $e?new M(e,t,n):t?new M(e,t):new M(e)}doWrite(e,t){this.ws.send(t)}},webtransport:class extends A{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=>{let t=je(2**53-1,this.socket.binaryType),n=e.readable.pipeThrough(t).getReader(),r=ke();r.readable.pipeTo(e.writable),this._writer=r.writable.getWriter();let i=()=>{n.read().then(({done:e,value:t})=>{e||(this.onPacket(t),i())}).catch(e=>{})};i();let a={type:`open`};this.query.sid&&(a.data=`{"sid":"${this.query.sid}"}`),this._writer.write(a).then(()=>this.onOpen())})})}write(e){this.writable=!1;for(let t=0;t<e.length;t++){let n=e[t],r=t===e.length-1;this._writer.write(n).then(()=>{r&&D(()=>{this.writable=!0,this.emitReserved(`drain`)},this.setTimeoutFn)})}}doClose(){var e;(e=this._transport)==null||e.close()}},polling:Ze},nt=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,rt=[`source`,`protocol`,`authority`,`userInfo`,`user`,`password`,`host`,`port`,`relative`,`path`,`directory`,`file`,`query`,`anchor`];function N(e){if(e.length>8e3)throw`URI too long`;let t=e,n=e.indexOf(`[`),r=e.indexOf(`]`);n!=-1&&r!=-1&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,`;`)+e.substring(r,e.length));let i=nt.exec(e||``),a={},o=14;for(;o--;)a[rt[o]]=i[o]||``;return n!=-1&&r!=-1&&(a.source=t,a.host=a.host.substring(1,a.host.length-1).replace(/;/g,`:`),a.authority=a.authority.replace(`[`,``).replace(`]`,``).replace(/;/g,`:`),a.ipv6uri=!0),a.pathNames=it(a,a.path),a.queryKey=at(a,a.query),a}function it(e,t){let n=t.replace(/\/{2,9}/g,`/`).split(`/`);return(t.slice(0,1)==`/`||t.length===0)&&n.splice(0,1),t.slice(-1)==`/`&&n.splice(n.length-1,1),n}function at(e,t){let n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(e,t,r){t&&(n[t]=r)}),n}var P=typeof addEventListener==`function`&&typeof removeEventListener==`function`,F=[];P&&addEventListener(`offline`,()=>{F.forEach(e=>e())},!1);var I=class e extends E{constructor(e,t){if(super(),this.binaryType=Ne,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,e&&typeof e==`object`&&(t=e,e=null),e){let n=N(e);t.hostname=n.host,t.secure=n.protocol===`https`||n.protocol===`wss`,t.port=n.port,n.query&&(t.query=n.query)}else t.host&&(t.hostname=N(t.host).host);k(this,t),this.secure=t.secure==null?typeof location<`u`&&location.protocol===`https:`:t.secure,t.hostname&&!t.port&&(t.port=this.secure?`443`:`80`),this.hostname=t.hostname||(typeof location<`u`?location.hostname:`localhost`),this.port=t.port||(typeof location<`u`&&location.port?location.port:this.secure?`443`:`80`),this.transports=[],this._transportsByName={},t.transports.forEach(e=>{let t=e.prototype.name;this.transports.push(t),this._transportsByName[t]=e}),this.opts=Object.assign({path:`/engine.io`,agent:!1,withCredentials:!1,upgrade:!0,timestampParam:`t`,rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,``)+(this.opts.addTrailingSlash?`/`:``),typeof this.opts.query==`string`&&(this.opts.query=He(this.opts.query)),P&&(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`})},F.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(e){let t=Object.assign({},this.opts.query);t.EIO=4,t.transport=e,this.id&&(t.sid=this.id);let n=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](n)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved(`error`,`No transports available`)},0);return}let t=this.opts.rememberUpgrade&&e.priorWebsocketSuccess&&this.transports.indexOf(`websocket`)!==-1?`websocket`:this.transports[0];this.readyState=`opening`;let n=this.createTransport(t);n.open(),this.setTransport(n)}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`,e=>this._onClose(`transport close`,e))}onOpen(){this.readyState=`open`,e.priorWebsocketSuccess=this.transport.name===`websocket`,this.emitReserved(`open`),this.flush()}_onPacket(e){if(this.readyState===`opening`||this.readyState===`open`||this.readyState===`closing`)switch(this.emitReserved(`packet`,e),this.emitReserved(`heartbeat`),e.type){case`open`:this.onHandshake(JSON.parse(e.data));break;case`ping`:this._sendPacket(`pong`),this.emitReserved(`ping`),this.emitReserved(`pong`),this._resetPingTimeout();break;case`error`:let t=Error(`server error`);t.code=e.data,this._onError(t);break;case`message`:this.emitReserved(`data`,e.data),this.emitReserved(`message`,e.data)}}onHandshake(e){this.emitReserved(`handshake`,e),this.id=e.sid,this.transport.query.sid=e.sid,this._pingInterval=e.pingInterval,this._pingTimeout=e.pingTimeout,this._maxPayload=e.maxPayload,this.onOpen(),this.readyState!==`closed`&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let e=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+e,this._pingTimeoutTimer=this.setTimeoutFn(()=>{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){let 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 e=1;for(let t=0;t<this.writeBuffer.length;t++){let n=this.writeBuffer[t].data;if(n&&(e+=Re(n)),t>0&&e>this._maxPayload)return this.writeBuffer.slice(0,t);e+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;let e=Date.now()>this._pingTimeoutTime;return e&&(this._pingTimeoutTime=0,D(()=>{this._onClose(`ping timeout`)},this.setTimeoutFn)),e}write(e,t,n){return this._sendPacket(`message`,e,t,n),this}send(e,t,n){return this._sendPacket(`message`,e,t,n),this}_sendPacket(e,t,n,r){if(typeof t==`function`&&(r=t,t=void 0),typeof n==`function`&&(r=n,n=null),this.readyState===`closing`||this.readyState===`closed`)return;n||={},n.compress=!1!==n.compress;let i={type:e,data:t,options:n};this.emitReserved(`packetCreate`,i),this.writeBuffer.push(i),r&&this.once(`flush`,r),this.flush()}close(){let e=()=>{this._onClose(`forced close`),this.transport.close()},t=()=>{this.off(`upgrade`,t),this.off(`upgradeError`,t),e()},n=()=>{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?n():e()}):this.upgrading?n():e()),this}_onError(t){if(e.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState===`opening`)return this.transports.shift(),this._open();this.emitReserved(`error`,t),this._onClose(`transport error`,t)}_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(),P&&(this._beforeunloadEventListener&&removeEventListener(`beforeunload`,this._beforeunloadEventListener,!1),this._offlineEventListener)){let e=F.indexOf(this._offlineEventListener);e!==-1&&F.splice(e,1)}this.readyState=`closed`,this.id=null,this.emitReserved(`close`,e,t),this.writeBuffer=[],this._prevBufferLen=0}}};I.protocol=4;var ot=class extends I{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState===`open`&&this.opts.upgrade)for(let e=0;e<this._upgrades.length;e++)this._probe(this._upgrades[e])}_probe(e){let t=this.createTransport(e),n=!1;I.priorWebsocketSuccess=!1;let r=()=>{n||(t.send([{type:`ping`,data:`probe`}]),t.once(`packet`,e=>{if(!n){if(e.type===`pong`&&e.data===`probe`){if(this.upgrading=!0,this.emitReserved(`upgrading`,t),!t)return;I.priorWebsocketSuccess=t.name===`websocket`,this.transport.pause(()=>{n||this.readyState!==`closed`&&(l(),this.setTransport(t),t.send([{type:`upgrade`}]),this.emitReserved(`upgrade`,t),t=null,this.upgrading=!1,this.flush())})}else{let e=Error(`probe error`);e.transport=t.name,this.emitReserved(`upgradeError`,e)}}}))};function i(){n||(n=!0,l(),t.close(),t=null)}let a=e=>{let n=Error(`probe error: `+e);n.transport=t.name,i(),this.emitReserved(`upgradeError`,n)};function o(){a(`transport closed`)}function s(){a(`socket closed`)}function c(e){t&&e.name!==t.name&&i()}let l=()=>{t.removeListener(`open`,r),t.removeListener(`error`,a),t.removeListener(`close`,o),this.off(`close`,s),this.off(`upgrading`,c)};t.once(`open`,r),t.once(`error`,a),t.once(`close`,o),this.once(`close`,s),this.once(`upgrading`,c),this._upgrades.indexOf(`webtransport`)!==-1&&e!==`webtransport`?this.setTimeoutFn(()=>{n||t.open()},200):t.open()}onHandshake(e){this._upgrades=this._filterUpgrades(e.upgrades),super.onHandshake(e)}_filterUpgrades(e){let t=[];for(let n=0;n<e.length;n++)~this.transports.indexOf(e[n])&&t.push(e[n]);return t}},st=class extends ot{constructor(e,t={}){let n=typeof e==`object`,r=n?{...e}:{...t};(!r.transports||r.transports&&typeof r.transports[0]==`string`)&&(r.transports=(r.transports||[`polling`,`websocket`,`webtransport`]).map(e=>tt[e]).filter(e=>!!e)),super(n?r:e,r)}};st.protocol;function ct(e,t=``,n){let r=e;n||=typeof location<`u`&&location,e??=n.protocol+`//`+n.host,typeof e==`string`&&(e.charAt(0)===`/`&&(e=e.charAt(1)===`/`?n.protocol+e:n.host+e),/^(https?|wss?):\/\//.test(e)||(e=n===void 0?`https://`+e:n.protocol+`//`+e),r=N(e)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port=`80`:/^(http|ws)s$/.test(r.protocol)&&(r.port=`443`)),r.path=r.path||`/`;let i=r.host.indexOf(`:`)===-1?r.host:`[`+r.host+`]`;return r.id=r.protocol+`://`+i+`:`+r.port+t,r.href=r.protocol+`://`+i+(n&&n.port===r.port?``:`:`+r.port),r}var lt=typeof ArrayBuffer==`function`,ut=e=>typeof ArrayBuffer.isView==`function`?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,dt=Object.prototype.toString,ft=typeof Blob==`function`||typeof Blob<`u`&&dt.call(Blob)===`[object BlobConstructor]`,pt=typeof File==`function`||typeof File<`u`&&dt.call(File)===`[object FileConstructor]`;function L(e){return lt&&(e instanceof ArrayBuffer||ut(e))||ft&&e instanceof Blob||pt&&e instanceof File}function R(e,t){if(!e||typeof e!=`object`)return!1;if(Array.isArray(e)){for(let t=0,n=e.length;t<n;t++)if(R(e[t]))return!0;return!1}if(L(e))return!0;if(e.toJSON&&typeof e.toJSON==`function`&&arguments.length===1)return R(e.toJSON(),!0);for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t)&&R(e[t]))return!0;return!1}function mt(e){let t=[],n=e.data,r=e;return r.data=z(n,t),r.attachments=t.length,{packet:r,buffers:t}}function z(e,t,n){if(!e)return e;if(L(e)){let n={_placeholder:!0,num:t.length};return t.push(e),n}if(Array.isArray(e)){let n=Array(e.length);for(let r=0;r<e.length;r++)n[r]=z(e[r],t);return n}if(typeof e==`object`&&!(e instanceof Date)){if(e.toJSON&&typeof e.toJSON==`function`&&!n)return z(e.toJSON(),t,!0);let r={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=z(e[n],t));return r}return e}function ht(e,t){return e.data=B(e.data,t),delete e.attachments,e}function B(e,t){if(!e)return e;if(e&&e._placeholder===!0){if(typeof e.num==`number`&&e.num>=0&&e.num<t.length)return t[e.num];throw Error(`illegal attachments`)}if(Array.isArray(e))for(let n=0;n<e.length;n++)e[n]=B(e[n],t);else if(typeof e==`object`)for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(e[n]=B(e[n],t));return e}var gt=n({Decoder:()=>yt,Encoder:()=>vt,PacketType:()=>V,isPacketValid:()=>Tt,protocol:()=>5}),_t=[`connect`,`connect_error`,`disconnect`,`disconnecting`,`newListener`,`removeListener`],V;(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`})(V||={});var vt=class{constructor(e){this.replacer=e}encode(e){return(e.type===V.EVENT||e.type===V.ACK)&&R(e)?this.encodeAsBinary({type:e.type===V.EVENT?V.BINARY_EVENT:V.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let t=``+e.type;return(e.type===V.BINARY_EVENT||e.type===V.BINARY_ACK)&&(t+=e.attachments+`-`),e.nsp&&e.nsp!==`/`&&(t+=e.nsp+`,`),e.id!=null&&(t+=e.id),e.data!=null&&(t+=JSON.stringify(e.data,this.replacer)),t}encodeAsBinary(e){let t=mt(e),n=this.encodeAsString(t.packet),r=t.buffers;return r.unshift(n),r}},yt=class e extends E{constructor(e){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},typeof e==`function`?{reviver:e}:e)}add(e){let t;if(typeof e==`string`){if(this.reconstructor)throw Error(`got plaintext data when reconstructing a packet`);t=this.decodeString(e);let n=t.type===V.BINARY_EVENT;n||t.type===V.BINARY_ACK?(t.type=n?V.EVENT:V.ACK,this.reconstructor=new bt(t)):super.emitReserved(`decoded`,t)}else if(L(e)||e.base64){if(this.reconstructor)t=this.reconstructor.takeBinaryData(e),t&&(this.reconstructor=null,super.emitReserved(`decoded`,t));else throw Error(`got binary data when not reconstructing a packet`)}else throw Error(`Unknown type: `+e)}decodeString(t){let n=0,r={type:Number(t.charAt(0))};if(V[r.type]===void 0)throw Error(`unknown packet type `+r.type);if(r.type===V.BINARY_EVENT||r.type===V.BINARY_ACK){let e=n+1;for(;t.charAt(++n)!==`-`&&n!=t.length;);let i=t.substring(e,n);if(i!=Number(i)||t.charAt(n)!==`-`)throw Error(`Illegal attachments`);let a=Number(i);if(!St(a)||a<1)throw Error(`Illegal attachments`);if(a>this.opts.maxAttachments)throw Error(`too many attachments`);r.attachments=a}if(t.charAt(n+1)===`/`){let e=n+1;for(;++n&&t.charAt(n)!==`,`&&n!==t.length;);r.nsp=t.substring(e,n)}else r.nsp=`/`;let i=t.charAt(n+1);if(i!==``&&Number(i)==i){let e=n+1;for(;++n;){let e=t.charAt(n);if(e==null||Number(e)!=e){--n;break}if(n===t.length)break}r.id=Number(t.substring(e,n+1))}if(t.charAt(++n)){let i=this.tryParse(t.substr(n));if(e.isPayloadValid(r.type,i))r.data=i;else throw Error(`invalid payload`)}return r}tryParse(e){try{return JSON.parse(e,this.opts.reviver)}catch{return!1}}static isPayloadValid(e,t){switch(e){case V.CONNECT:return H(t);case V.DISCONNECT:return t===void 0;case V.CONNECT_ERROR:return typeof t==`string`||H(t);case V.EVENT:case V.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]==`number`||typeof t[0]==`string`&&_t.indexOf(t[0])===-1);case V.ACK:case V.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&=(this.reconstructor.finishedReconstruction(),null)}},bt=class{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){let e=ht(this.reconPack,this.buffers);return this.finishedReconstruction(),e}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};function xt(e){return typeof e==`string`}var St=Number.isInteger||function(e){return typeof e==`number`&&isFinite(e)&&Math.floor(e)===e};function Ct(e){return e===void 0||St(e)}function H(e){return Object.prototype.toString.call(e)===`[object Object]`}function wt(e,t){switch(e){case V.CONNECT:return t===void 0||H(t);case V.DISCONNECT:return t===void 0;case V.EVENT:return Array.isArray(t)&&(typeof t[0]==`number`||typeof t[0]==`string`&&_t.indexOf(t[0])===-1);case V.ACK:return Array.isArray(t);case V.CONNECT_ERROR:return typeof t==`string`||H(t);default:return!1}}function Tt(e){return xt(e.nsp)&&Ct(e.id)&&wt(e.type,e.data)}function U(e,t,n){return e.on(t,n),function(){e.off(t,n)}}var Et=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),Dt=class extends E{constructor(e,t,n){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,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;let e=this.io;this.subs=[U(e,`open`,this.onopen.bind(this)),U(e,`packet`,this.onpacket.bind(this)),U(e,`error`,this.onerror.bind(this)),U(e,`close`,this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(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){if(Et.hasOwnProperty(e))throw 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;let n={type:V.EVENT,data:t};if(n.options={},n.options.compress=this.flags.compress!==!1,typeof t[t.length-1]==`function`){let e=this.ids++,r=t.pop();this._registerAckCallback(e,r),n.id=e}let r=this.io.engine?.transport?.writable,i=this.connected&&!this.io.engine?._hasPingExpired();return this.flags.volatile&&!r||(i?(this.notifyOutgoingListeners(n),this.packet(n)):this.sendBuffer.push(n)),this.flags={},this}_registerAckCallback(e,t){let n=this.flags.timeout??this._opts.ackTimeout;if(n===void 0){this.acks[e]=t;return}let r=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let t=0;t<this.sendBuffer.length;t++)this.sendBuffer[t].id===e&&this.sendBuffer.splice(t,1);t.call(this,Error(`operation has timed out`))},n),i=(...e)=>{this.io.clearTimeoutFn(r),t.apply(this,e)};i.withError=!0,this.acks[e]=i}emitWithAck(e,...t){return new Promise((n,r)=>{let i=(e,t)=>e?r(e):n(t);i.withError=!0,t.push(i),this.emit(e,...t)})}_addToQueue(e){let t;typeof e[e.length-1]==`function`&&(t=e.pop());let n={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((e,...r)=>(this._queue[0],e===null?(this._queue.shift(),t&&t(null,...r)):n.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(e)),n.pending=!1,this._drainQueue())),this._queue.push(n),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||this._queue.length===0)return;let 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:V.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(t=>String(t.id)===e)){let t=this.acks[e];delete this.acks[e],t.withError&&t.call(this,Error(`socket has been disconnected`))}})}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case V.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved(`connect_error`,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 V.EVENT:case V.BINARY_EVENT:this.onevent(e);break;case V.ACK:case V.BINARY_ACK:this.onack(e);break;case V.DISCONNECT:this.ondisconnect();break;case V.CONNECT_ERROR:this.destroy();let t=Error(e.data.message);t.data=e.data.data,this.emitReserved(`connect_error`,t)}}onevent(e){let 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){let t=this._anyListeners.slice();for(let n of t)n.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){let t=this,n=!1;return function(...r){n||(n=!0,t.packet({type:V.ACK,id:e,data:r}))}}onack(e){let 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()),void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:V.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){let t=this._anyListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){let t=this._anyOutgoingListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){let t=this._anyOutgoingListeners.slice();for(let n of t)n.apply(this,e.data)}}};function W(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}W.prototype.duration=function(){var e=this.ms*this.factor**+this.attempts++;if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=Math.floor(t*10)&1?e+n:e-n}return Math.min(e,this.max)|0},W.prototype.reset=function(){this.attempts=0},W.prototype.setMin=function(e){this.ms=e},W.prototype.setMax=function(e){this.max=e},W.prototype.setJitter=function(e){this.jitter=e};var G=class extends E{constructor(e,t){super(),this.nsps={},this.subs=[],e&&typeof e==`object`&&(t=e,e=void 0),t||={},t.path=t.path||`/socket.io`,this.opts=t,k(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(t.randomizationFactor??.5),this.backoff=new W({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(t.timeout==null?2e4:t.timeout),this._readyState=`closed`,this.uri=e;let n=t.parser||gt;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.setMin(e),this)}randomizationFactor(e){var t;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(t=this.backoff)==null||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(t=this.backoff)==null||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 st(this.uri,this.opts);let t=this.engine,n=this;this._readyState=`opening`,this.skipReconnect=!1;let r=U(t,`open`,function(){n.onopen(),e&&e()}),i=t=>{this.cleanup(),this._readyState=`closed`,this.emitReserved(`error`,t),e?e(t):this.maybeReconnectOnOpen()},a=U(t,`error`,i);if(!1!==this._timeout){let e=this._timeout,n=this.setTimeoutFn(()=>{r(),i(Error(`timeout`)),t.close()},e);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}return this.subs.push(r),this.subs.push(a),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState=`open`,this.emitReserved(`open`);let e=this.engine;this.subs.push(U(e,`ping`,this.onping.bind(this)),U(e,`data`,this.ondata.bind(this)),U(e,`error`,this.onerror.bind(this)),U(e,`close`,this.onclose.bind(this)),U(this.decoder,`decoded`,this.ondecoded.bind(this)))}onping(){this.emitReserved(`ping`)}ondata(e){try{this.decoder.add(e)}catch(e){this.onclose(`parse error`,e)}}ondecoded(e){D(()=>{this.emitReserved(`packet`,e)},this.setTimeoutFn)}onerror(e){this.emitReserved(`error`,e)}socket(e,t){let n=this.nsps[e];return n?this._autoConnect&&!n.active&&n.connect():(n=new Dt(this,e,t),this.nsps[e]=n),n}_destroy(e){let t=Object.keys(this.nsps);for(let e of t)if(this.nsps[e].active)return;this._close()}_packet(e){let t=this.encoder.encode(e);for(let n=0;n<t.length;n++)this.engine.write(t[n],e.options)}cleanup(){this.subs.forEach(e=>e()),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 n;this.cleanup(),(n=this.engine)==null||n.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;let e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved(`reconnect_failed`),this._reconnecting=!1;else{let t=this.backoff.duration();this._reconnecting=!0;let n=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved(`reconnect_attempt`,e.backoff.attempts),!e.skipReconnect&&e.open(t=>{t?(e._reconnecting=!1,e.reconnect(),this.emitReserved(`reconnect_error`,t)):e.onreconnect()}))},t);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}}onreconnect(){let e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved(`reconnect`,e)}},K={};function q(e,t){typeof e==`object`&&(t=e,e=void 0),t||={};let n=ct(e,t.path||`/socket.io`),r=n.source,i=n.id,a=n.path,o=K[i]&&a in K[i].nsps,s=t.forceNew||t[`force new connection`]||!1===t.multiplex||o,c;return s?c=new G(r,t):(K[i]||(K[i]=new G(r,t)),c=K[i]),n.query&&!t.query&&(t.query=n.queryKey),c.socket(n.path,t)}Object.assign(q,{Manager:G,Socket:Dt,io:q,connect:q});function Ot(e){let t=e.replace(/\/$/,``);try{return`${new URL(t).origin}/sdk`}catch{return`${t}/sdk`}}var kt=class{constructor(){this.socket=null}get connected(){return this.socket?.connected??!1}connect(e){this.disconnect();let t=Ot(e.baseUrl);this.socket=q(t,{auth:{apiKey:e.apiKey,visitorToken:e.visitorToken},transports:[`websocket`,`polling`],autoConnect:!0,reconnection:!0});let n=!1;this.socket.on(`connect`,()=>{n?e.onReconnect?.():n=!0}),this.socket.on(`ticket:status`,t=>{e.onTicketStatus?.(t)}),this.socket.on(`message:receive`,t=>{e.onMessageReceive?.(t)}),this.socket.on(`connect_error`,t=>{e.onConnectError?.(t)})}disconnect(){this.socket&&=(this.socket.removeAllListeners(),this.socket.disconnect(),null)}},J=`onedeskpro_visitor_token`;function At(e){try{return typeof window<`u`?window.localStorage.getItem(e):null}catch{return null}}function jt(e,t){try{typeof window<`u`&&window.localStorage.setItem(e,t)}catch{}}function Mt(e){try{typeof window<`u`&&window.localStorage.removeItem(e)}catch{}}var Nt=class{constructor(){this.token=null,this.storageKey=J}setScope(e){this.storageKey=e?.trim()?`${J}:${e.trim()}`:J,this.token=At(this.storageKey)}get(){return this.token??At(this.storageKey)}set(e){this.token=e,jt(this.storageKey,e)}clear(){this.token=null,Mt(this.storageKey)}},Pt=300,Ft=250,It=100,Lt=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg;codecs=opus`];function Rt(){return typeof MediaRecorder>`u`||typeof MediaRecorder.isTypeSupported!=`function`?`audio/webm`:Lt.find(e=>MediaRecorder.isTypeSupported(e))??`audio/webm`}function zt(e){let t=e instanceof DOMException?e.name:``;return t===`NotAllowedError`||t===`PermissionDeniedError`||t===`SecurityError`?`Microphone access was denied.`:t===`NotFoundError`||t===`DevicesNotFoundError`?`No microphone was found.`:`Could not start recording.`}var Y=class e{constructor(e,t=300){this.onChange=e,this.maxDurationSeconds=t,this.recorder=null,this.stream=null,this.chunks=[],this.mimeType=`audio/webm`,this.startedAt=0,this.tickTimer=null,this.levelTimer=null,this.maxTimer=null,this.audioContext=null,this.analyser=null,this.snapshot={state:`idle`,elapsedSeconds:0,level:0,result:null}}static isSupported(){return typeof navigator<`u`&&typeof navigator.mediaDevices?.getUserMedia==`function`&&typeof MediaRecorder<`u`}getSnapshot(){return{...this.snapshot}}async start(){if(!e.isSupported())throw Error(`Voice messages are not supported in this browser.`);this.release(),this.chunks=[];let t;try{t=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){throw Error(zt(e))}try{this.mimeType=Rt();let e=new MediaRecorder(t,{mimeType:this.mimeType});e.ondataavailable=e=>{e.data.size>0&&this.chunks.push(e.data)},this.stream=t,this.recorder=e,this.startedAt=Date.now(),e.start(200)}catch(e){throw t.getTracks().forEach(e=>e.stop()),this.stream=null,this.recorder=null,Error(zt(e))}this.startLevelMeter(t),this.tickTimer=setInterval(()=>{this.update({elapsedSeconds:Math.floor(this.elapsedMs()/1e3)})},Ft),this.maxTimer=setTimeout(()=>void this.stop(),this.maxDurationSeconds*1e3),this.update({state:`recording`,elapsedSeconds:0,level:0,result:null})}async stop(){let e=this.recorder;if(!e||e.state===`inactive`)return this.release(),null;let t=Math.max(1,Math.round(this.elapsedMs()/1e3));this.clearTimers();let n=await new Promise(t=>{e.onstop=()=>{let e=this.chunks;this.chunks=[],t(new Blob(e,{type:_(this.mimeType)}))};try{e.stop()}catch{t(new Blob(this.chunks,{type:_(this.mimeType)}))}});this.releaseMedia();let r={blob:n,mimeType:_(this.mimeType),durationSeconds:t};return this.update({state:`preview`,elapsedSeconds:t,level:0,result:r}),r}cancel(){this.release(),this.update({state:`idle`,elapsedSeconds:0,level:0,result:null})}destroy(){this.release(),this.snapshot={state:`idle`,elapsedSeconds:0,level:0,result:null}}update(e){this.snapshot={...this.snapshot,...e},this.onChange({...this.snapshot})}elapsedMs(){return this.startedAt>0?Date.now()-this.startedAt:0}startLevelMeter(e){let t=typeof window>`u`?null:window,n=t?.AudioContext??t?.webkitAudioContext;if(n)try{let t=new n,r=t.createAnalyser();r.fftSize=256,t.createMediaStreamSource(e).connect(r),t.resume().catch(()=>void 0),this.audioContext=t,this.analyser=r;let i=new Uint8Array(r.frequencyBinCount);this.levelTimer=setInterval(()=>{r.getByteTimeDomainData(i);let e=0;for(let t=0;t<i.length;t++){let n=((i[t]??128)-128)/128;e+=n*n}this.update({level:Math.min(1,Math.sqrt(e/i.length)*3.2)})},It)}catch{}}clearTimers(){this.tickTimer&&clearInterval(this.tickTimer),this.levelTimer&&clearInterval(this.levelTimer),this.maxTimer&&clearTimeout(this.maxTimer),this.tickTimer=null,this.levelTimer=null,this.maxTimer=null}releaseMedia(){this.stream?.getTracks().forEach(e=>e.stop()),this.stream=null,this.recorder=null,this.analyser=null,this.audioContext&&=(this.audioContext.close().catch(()=>void 0),null),this.startedAt=0}release(){if(this.clearTimers(),this.recorder&&this.recorder.state!==`inactive`){this.recorder.onstop=null;try{this.recorder.stop()}catch{}}this.chunks=[],this.releaseMedia()}},X=[{iso:`BD`,name:`Bangladesh`,dial:`880`,flag:`🇧🇩`},{iso:`US`,name:`United States`,dial:`1`,flag:`🇺🇸`},{iso:`GB`,name:`United Kingdom`,dial:`44`,flag:`🇬🇧`},{iso:`IN`,name:`India`,dial:`91`,flag:`🇮🇳`},{iso:`PK`,name:`Pakistan`,dial:`92`,flag:`🇵🇰`},{iso:`AE`,name:`United Arab Emirates`,dial:`971`,flag:`🇦🇪`},{iso:`SA`,name:`Saudi Arabia`,dial:`966`,flag:`🇸🇦`},{iso:`CA`,name:`Canada`,dial:`1`,flag:`🇨🇦`},{iso:`AU`,name:`Australia`,dial:`61`,flag:`🇦🇺`},{iso:`DE`,name:`Germany`,dial:`49`,flag:`🇩🇪`},{iso:`FR`,name:`France`,dial:`33`,flag:`🇫🇷`},{iso:`IT`,name:`Italy`,dial:`39`,flag:`🇮🇹`},{iso:`ES`,name:`Spain`,dial:`34`,flag:`🇪🇸`},{iso:`NL`,name:`Netherlands`,dial:`31`,flag:`🇳🇱`},{iso:`SE`,name:`Sweden`,dial:`46`,flag:`🇸🇪`},{iso:`NO`,name:`Norway`,dial:`47`,flag:`🇳🇴`},{iso:`DK`,name:`Denmark`,dial:`45`,flag:`🇩🇰`},{iso:`FI`,name:`Finland`,dial:`358`,flag:`🇫🇮`},{iso:`IE`,name:`Ireland`,dial:`353`,flag:`🇮🇪`},{iso:`CH`,name:`Switzerland`,dial:`41`,flag:`🇨🇭`},{iso:`AT`,name:`Austria`,dial:`43`,flag:`🇦🇹`},{iso:`BE`,name:`Belgium`,dial:`32`,flag:`🇧🇪`},{iso:`PT`,name:`Portugal`,dial:`351`,flag:`🇵🇹`},{iso:`PL`,name:`Poland`,dial:`48`,flag:`🇵🇱`},{iso:`CZ`,name:`Czechia`,dial:`420`,flag:`🇨🇿`},{iso:`RO`,name:`Romania`,dial:`40`,flag:`🇷🇴`},{iso:`HU`,name:`Hungary`,dial:`36`,flag:`🇭🇺`},{iso:`GR`,name:`Greece`,dial:`30`,flag:`🇬🇷`},{iso:`TR`,name:`Turkey`,dial:`90`,flag:`🇹🇷`},{iso:`RU`,name:`Russia`,dial:`7`,flag:`🇷🇺`},{iso:`UA`,name:`Ukraine`,dial:`380`,flag:`🇺🇦`},{iso:`CN`,name:`China`,dial:`86`,flag:`🇨🇳`},{iso:`JP`,name:`Japan`,dial:`81`,flag:`🇯🇵`},{iso:`KR`,name:`South Korea`,dial:`82`,flag:`🇰🇷`},{iso:`SG`,name:`Singapore`,dial:`65`,flag:`🇸🇬`},{iso:`MY`,name:`Malaysia`,dial:`60`,flag:`🇲🇾`},{iso:`ID`,name:`Indonesia`,dial:`62`,flag:`🇮🇩`},{iso:`TH`,name:`Thailand`,dial:`66`,flag:`🇹🇭`},{iso:`VN`,name:`Vietnam`,dial:`84`,flag:`🇻🇳`},{iso:`PH`,name:`Philippines`,dial:`63`,flag:`🇵🇭`},{iso:`HK`,name:`Hong Kong`,dial:`852`,flag:`🇭🇰`},{iso:`TW`,name:`Taiwan`,dial:`886`,flag:`🇹🇼`},{iso:`NZ`,name:`New Zealand`,dial:`64`,flag:`🇳🇿`},{iso:`ZA`,name:`South Africa`,dial:`27`,flag:`🇿🇦`},{iso:`NG`,name:`Nigeria`,dial:`234`,flag:`🇳🇬`},{iso:`KE`,name:`Kenya`,dial:`254`,flag:`🇰🇪`},{iso:`EG`,name:`Egypt`,dial:`20`,flag:`🇪🇬`},{iso:`MA`,name:`Morocco`,dial:`212`,flag:`🇲🇦`},{iso:`BR`,name:`Brazil`,dial:`55`,flag:`🇧🇷`},{iso:`MX`,name:`Mexico`,dial:`52`,flag:`🇲🇽`},{iso:`AR`,name:`Argentina`,dial:`54`,flag:`🇦🇷`},{iso:`CL`,name:`Chile`,dial:`56`,flag:`🇨🇱`},{iso:`CO`,name:`Colombia`,dial:`57`,flag:`🇨🇴`},{iso:`PE`,name:`Peru`,dial:`51`,flag:`🇵🇪`},{iso:`IL`,name:`Israel`,dial:`972`,flag:`🇮🇱`},{iso:`QA`,name:`Qatar`,dial:`974`,flag:`🇶🇦`},{iso:`KW`,name:`Kuwait`,dial:`965`,flag:`🇰🇼`},{iso:`BH`,name:`Bahrain`,dial:`973`,flag:`🇧🇭`},{iso:`OM`,name:`Oman`,dial:`968`,flag:`🇴🇲`},{iso:`LK`,name:`Sri Lanka`,dial:`94`,flag:`🇱🇰`},{iso:`NP`,name:`Nepal`,dial:`977`,flag:`🇳🇵`}],Bt=X.find(e=>e.iso===`BD`)??X[0];function Vt(e,t){let n=t.trim();if(n.startsWith(`+`)){let e=n.replace(/\D/g,``);return e?`+${e}`:``}let r=n.replace(/\D/g,``);return!r||(r=r.replace(/^0+/,``),!r)?``:`+${e}${r}`}var Ht=`(max-width: 640px), (max-height: 500px) and (pointer: coarse)`;function Ut(e,t){let n=`
2
2
  --ttcb-bg: #ffffff;
3
3
  --ttcb-bg-secondary: #f3f4f6;
4
4
  --ttcb-text: #111827;
@@ -761,7 +761,7 @@ var OnedeskProChatbot=(function(e){Object.defineProperty(e,Symbol.toStringTag,{v
761
761
  </svg>`}function fn(){return`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg">
762
762
  <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
763
763
  <polyline points="14 2 14 8 20 8"/>
764
- </svg>`}function pn(e){let t=p(e.url)?e.url:``,n=e.type.toLowerCase();if(t&&n.startsWith(`image/`)){let n=document.createElement(`a`);n.className=`ttcb-attachment ttcb-attachment-image`,n.href=t,n.target=`_blank`,n.rel=`noopener noreferrer`,n.setAttribute(`aria-label`,`Open ${e.fileName}`);let r=document.createElement(`img`);return r.src=t,r.alt=e.fileName,r.loading=`lazy`,n.appendChild(r),n}if(t&&n.startsWith(`video/`)){let n=document.createElement(`video`);return n.className=`ttcb-attachment ttcb-attachment-video`,n.controls=!0,n.preload=`metadata`,n.src=t,n.setAttribute(`aria-label`,e.fileName),n}if(t&&n.startsWith(`audio/`)){let n=document.createElement(`div`);n.className=`ttcb-attachment ttcb-attachment-voice`;let r=document.createElement(`audio`);if(r.className=`ttcb-attachment-audio`,r.controls=!0,r.preload=`metadata`,r.src=t,r.setAttribute(`aria-label`,e.fileName),n.appendChild(r),typeof e.durationSeconds==`number`&&e.durationSeconds>0){let t=document.createElement(`span`);t.className=`ttcb-attachment-duration`,t.textContent=v(e.durationSeconds),n.appendChild(t)}return n}let r=document.createElement(t?`a`:`div`);r.className=`ttcb-attachment ttcb-attachment-file`,r instanceof HTMLAnchorElement&&(r.href=t,r.target=`_blank`,r.rel=`noopener noreferrer`);let i=document.createElement(`span`);i.className=`ttcb-attachment-icon`,i.setAttribute(`aria-hidden`,`true`),i.innerHTML=fn();let a=document.createElement(`span`);a.className=`ttcb-attachment-meta`;let o=document.createElement(`span`);o.className=`ttcb-attachment-name`,o.textContent=e.fileName,a.appendChild(o);let s=te(e.size);if(s){let e=document.createElement(`span`);e.className=`ttcb-attachment-size`,e.textContent=s,a.appendChild(e)}return r.appendChild(i),r.appendChild(a),r}function mn(e){let{type:t,content:n}=e,r=e.attachments??[],i=document.createElement(`div`);i.className=`ttcb-msg ${t}`,e.pending&&i.classList.add(`ttcb-pending`);let a=document.createElement(`div`);a.className=`ttcb-msg-avatar`,a.innerHTML=t===`human`?Xt():t===`agent`?Zt():Z();let o=document.createElement(`div`);if(o.className=`ttcb-msg-body`,t===`agent`){let e=document.createElement(`span`);e.className=`ttcb-msg-label`,e.textContent=`Agent`,o.appendChild(e)}if(r.length>0){let e=document.createElement(`div`);e.className=`ttcb-attachments`;for(let t of r)e.appendChild(pn(t));o.appendChild(e)}if(r.length===0||!re(n,r)){let e=document.createElement(`div`);e.className=`ttcb-bubble`,t===`human`?e.textContent=n:e.innerHTML=Gt(n),o.appendChild(e)}if(e.pending){let e=document.createElement(`span`);e.className=`ttcb-msg-status`,e.textContent=`Uploading…`,o.appendChild(e)}return i.appendChild(a),i.appendChild(o),i}function hn(){let e=document.createElement(`div`);e.className=`ttcb-msg ai`,e.id=`ttcb-typing`;let t=document.createElement(`div`);t.className=`ttcb-msg-avatar`,t.innerHTML=Z();let n=document.createElement(`div`);return n.className=`ttcb-typing`,n.innerHTML=`<span></span><span></span><span></span>`,e.appendChild(t),e.appendChild(n),e}var gn=[`image/jpeg`,`image/png`,`image/gif`,`video/mp4`,`video/webm`,`audio/ogg`,`audio/mpeg`,`audio/wav`,`audio/x-m4a`,`audio/aac`,`audio/opus`,`application/pdf`,`text/csv`].join(`,`),_n=`image/jpeg,image/png,image/gif`,vn=class{constructor(e,t){this.stopViewportSync=null,this.pendingFiles=[],this.attachMenuOpen=!1,this.recorder=null,this.voicePreviewUrl=``,this.selectedCountry=Bt,this.countryOpen=!1,this.isOpen=!1,this.destroyed=!1,this.position=e.position??`bottom-right`,this.callbacks=t,this.autoOpen=e.autoOpen===!0,this.mount(e)}mount(e){this.host=document.createElement(`div`),this.host.id=`onedeskpro-chatbot-host`,this.host.style.display=`none`,this.shadow=this.host.attachShadow({mode:`closed`});let t=document.createElement(`style`);t.textContent=Ut(e.primaryColor??`#2563EB`,e.theme??`auto`),this.shadow.appendChild(t),this.fab=document.createElement(`button`),this.fab.className=`ttcb-fab ${this.position}`,this.fab.setAttribute(`aria-label`,`Open chat`),this.fab.innerHTML=qt(),this.fab.addEventListener(`click`,()=>this.toggle()),this.shadow.appendChild(this.fab),this.panel=document.createElement(`div`),this.panel.className=`ttcb-panel ${this.position} hidden ttcb-mode-compact`,this.panel.tabIndex=-1,this.panel.setAttribute(`role`,`dialog`),this.panel.setAttribute(`aria-modal`,`true`),this.panel.setAttribute(`aria-label`,e.chatbotName??`AI Assistant`),this.panel.appendChild(this.buildHeader(e)),this.identifyContainer=document.createElement(`div`),this.identifyContainer.className=`ttcb-identify`,this.buildIdentifyForm(this.identifyContainer),this.panel.appendChild(this.identifyContainer),this.messagesContainer=document.createElement(`div`),this.messagesContainer.className=`ttcb-messages`,this.messagesContainer.setAttribute(`aria-live`,`polite`),this.messagesContainer.setAttribute(`aria-label`,`Chat messages`),this.panel.appendChild(this.messagesContainer),this.modeBanner=document.createElement(`div`),this.modeBanner.className=`ttcb-mode-banner`,this.modeBanner.setAttribute(`role`,`status`),this.panel.appendChild(this.modeBanner),this.footer=document.createElement(`div`),this.footer.className=`ttcb-footer`,this.pendingTray=document.createElement(`div`),this.pendingTray.className=`ttcb-pending-tray`,this.pendingTray.setAttribute(`role`,`list`),this.pendingTray.setAttribute(`aria-label`,`Files to send`),this.footer.appendChild(this.pendingTray),this.composeError=document.createElement(`p`),this.composeError.className=`ttcb-compose-error`,this.composeError.setAttribute(`role`,`alert`),this.footer.appendChild(this.composeError),this.footer.appendChild(this.buildVoiceBar()),this.footer.appendChild(this.buildVoicePreview());let n=document.createElement(`form`);n.className=`ttcb-form`,n.addEventListener(`submit`,e=>{e.preventDefault(),this.handleSend()}),this.composeForm=n,n.appendChild(this.buildAttachControls()),this.input=document.createElement(`input`),this.input.type=`text`,this.input.className=`ttcb-input`,this.input.placeholder=e.placeholder??`Type your message…`,this.input.setAttribute(`aria-label`,`Message input`),this.input.setAttribute(`autocomplete`,`off`),this.sendBtn=document.createElement(`button`),this.sendBtn.type=`submit`,this.sendBtn.className=`ttcb-send-btn`,this.sendBtn.innerHTML=Yt(),this.sendBtn.setAttribute(`aria-label`,`Send message`),this.micBtn=document.createElement(`button`),this.micBtn.type=`button`,this.micBtn.className=`ttcb-mic-btn`,this.micBtn.setAttribute(`aria-label`,`Record voice message`),this.micBtn.title=`Record voice message`,this.micBtn.innerHTML=ln(),this.micBtn.addEventListener(`click`,()=>void this.startVoice()),n.appendChild(this.input),n.appendChild(this.micBtn),n.appendChild(this.sendBtn),this.footer.appendChild(n),this.panel.appendChild(this.footer),this.shadow.appendChild(this.panel),this.shadow.addEventListener(`click`,e=>{let t=e.target;this.attachMenuOpen&&!(t&&(this.attachBtn.contains(t)||this.attachMenu.contains(t)))&&this.closeAttachMenu(),this.countryOpen&&(t&&(this.dialBtn.contains(t)||this.countryPopover.contains(t))||this.closeCountryPopover())}),this.panel.addEventListener(`keydown`,e=>{e.key===`Escape`&&this.attachMenuOpen&&(e.stopPropagation(),this.closeAttachMenu(),this.attachBtn.focus())}),this.attachToDocument(),this.showInitialLoading()}reveal(){this.host.style.removeProperty(`display`),this.autoOpen&&!this.isOpen&&this.open()}buildHeader(e){let t=document.createElement(`div`);t.className=`ttcb-header`;let n=document.createElement(`div`);n.className=`ttcb-avatar-wrap`;let r=document.createElement(`div`);r.className=`ttcb-avatar`,r.innerHTML=Z(),n.appendChild(r);let i=document.createElement(`div`);i.className=`ttcb-header-main`;let a=document.createElement(`div`);a.className=`ttcb-header-title-row`,this.headerTitle=document.createElement(`span`),this.headerTitle.className=`ttcb-header-title`,this.headerTitle.textContent=e.chatbotName??`AI Assistant`;let o=document.createElement(`span`);o.className=`ttcb-verified`,o.setAttribute(`aria-label`,`Verified`),o.innerHTML=nn(),a.appendChild(this.headerTitle),a.appendChild(o);let s=document.createElement(`div`);s.className=`ttcb-header-meta`;let c=document.createElement(`span`);c.className=`ttcb-meta-online`,c.textContent=`Online`;let l=document.createElement(`span`);l.className=`ttcb-meta-sep`,l.setAttribute(`aria-hidden`,`true`);let u=document.createElement(`span`);u.className=`ttcb-meta-replies`,u.innerHTML=`${rn()}<span>Replies instantly</span>`,s.appendChild(c),s.appendChild(l),s.appendChild(u),i.appendChild(a),i.appendChild(s);let d=document.createElement(`div`);d.className=`ttcb-header-actions`,this.requestHumanBtn=document.createElement(`button`),this.requestHumanBtn.type=`button`,this.requestHumanBtn.className=`ttcb-request-human-btn hidden`,this.requestHumanBtn.id=`ttcb-request-human-btn`,this.requestHumanBtn.setAttribute(`aria-label`,`Request human agent`),this.requestHumanBtn.title=`Request human agent`,this.requestHumanBtn.innerHTML=an(),this.requestHumanBtn.addEventListener(`click`,()=>this.callbacks.onRequestHuman()),this.newSessionBtn=document.createElement(`button`),this.newSessionBtn.className=`ttcb-new-session-btn hidden`,this.newSessionBtn.setAttribute(`aria-label`,`New conversation`),this.newSessionBtn.title=`New conversation`,this.newSessionBtn.innerHTML=Kt(),this.newSessionBtn.addEventListener(`click`,()=>this.callbacks.onReset());let f=document.createElement(`button`);return f.className=`ttcb-close-btn`,f.setAttribute(`aria-label`,`Close chat`),f.innerHTML=Jt(),f.addEventListener(`click`,()=>this.close()),d.appendChild(this.requestHumanBtn),d.appendChild(this.newSessionBtn),d.appendChild(f),t.appendChild(n),t.appendChild(i),t.appendChild(d),t}buildAttachControls(){let e=document.createElement(`div`);e.className=`ttcb-attach`,this.attachBtn=document.createElement(`button`),this.attachBtn.type=`button`,this.attachBtn.className=`ttcb-attach-btn`,this.attachBtn.setAttribute(`aria-label`,`Add attachment`),this.attachBtn.setAttribute(`aria-haspopup`,`menu`),this.attachBtn.setAttribute(`aria-expanded`,`false`),this.attachBtn.title=`Add attachment`,this.attachBtn.innerHTML=on(),this.attachBtn.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this.toggleAttachMenu()}),this.attachMenu=document.createElement(`div`),this.attachMenu.className=`ttcb-attach-menu`,this.attachMenu.setAttribute(`role`,`menu`),this.attachFileInput=this.createFileInput(gn,`Choose files`),this.attachPhotoInput=this.createFileInput(_n,`Choose photos`);let t=[{label:`Attachment`,icon:sn(),input:this.attachFileInput},{label:`Photo`,icon:cn(),input:this.attachPhotoInput}];for(let e of t){let t=document.createElement(`button`);t.type=`button`,t.className=`ttcb-attach-item`,t.setAttribute(`role`,`menuitem`),t.innerHTML=`${e.icon}<span>${e.label}</span>`,t.addEventListener(`click`,()=>{this.closeAttachMenu(),e.input.click()}),this.attachMenu.appendChild(t)}return e.appendChild(this.attachBtn),e.appendChild(this.attachMenu),e.appendChild(this.attachFileInput),e.appendChild(this.attachPhotoInput),e}createFileInput(e,t){let n=document.createElement(`input`);return n.type=`file`,n.multiple=!0,n.accept=e,n.className=`ttcb-file-input`,n.tabIndex=-1,n.setAttribute(`aria-label`,t),n.addEventListener(`change`,()=>{this.addPendingFiles(Array.from(n.files??[])),n.value=``}),n}toggleAttachMenu(){this.attachMenuOpen?this.closeAttachMenu():this.openAttachMenu()}openAttachMenu(){if(this.attachBtn.disabled)return;this.attachMenuOpen=!0,this.attachMenu.classList.add(`open`),this.attachBtn.setAttribute(`aria-expanded`,`true`);let e=this.attachMenu.querySelector(`.ttcb-attach-item`);queueMicrotask(()=>e?.focus())}closeAttachMenu(){this.attachMenuOpen&&(this.attachMenuOpen=!1,this.attachMenu.classList.remove(`open`),this.attachBtn.setAttribute(`aria-expanded`,`false`))}addPendingFiles(e){if(e.length===0)return;let t=f([...this.pendingFiles.map(e=>e.file),...e]);if(t)this.showComposeError(t);else{this.showComposeError(``);for(let t of e){let e=t.type.startsWith(`image/`)?m(t):``;this.pendingFiles.push({file:t,previewUrl:e})}this.renderPendingTray(),this.input.focus()}}removePendingFile(e){let[t]=this.pendingFiles.splice(e,1);t&&h(t.previewUrl),this.renderPendingTray(),this.input.focus()}clearPendingFiles(){for(let e of this.pendingFiles)h(e.previewUrl);this.pendingFiles=[],this.renderPendingTray()}renderPendingTray(){this.pendingTray.innerHTML=``,this.pendingTray.classList.toggle(`visible`,this.pendingFiles.length>0),this.pendingFiles.forEach((e,t)=>{let n=document.createElement(`div`);if(n.className=`ttcb-pending-item`,n.setAttribute(`role`,`listitem`),e.previewUrl){let t=document.createElement(`img`);t.className=`ttcb-pending-thumb`,t.src=e.previewUrl,t.alt=``,n.appendChild(t)}else{let e=document.createElement(`span`);e.className=`ttcb-pending-icon`,e.setAttribute(`aria-hidden`,`true`),e.innerHTML=fn(),n.appendChild(e)}let r=document.createElement(`span`);r.className=`ttcb-pending-name`,r.textContent=e.file.name||`attachment`,r.title=e.file.name,n.appendChild(r);let i=document.createElement(`button`);i.type=`button`,i.className=`ttcb-pending-remove`,i.setAttribute(`aria-label`,`Remove ${e.file.name||`attachment`}`),i.innerHTML=Jt(),i.addEventListener(`click`,()=>this.removePendingFile(t)),n.appendChild(i),this.pendingTray.appendChild(n)})}buildVoiceBar(){this.voiceBar=document.createElement(`div`),this.voiceBar.className=`ttcb-voice-bar`,this.voiceBar.setAttribute(`role`,`group`),this.voiceBar.setAttribute(`aria-label`,`Recording voice message`);let e=document.createElement(`span`);e.className=`ttcb-voice-dot`,e.setAttribute(`aria-hidden`,`true`),this.voiceTime=document.createElement(`span`),this.voiceTime.className=`ttcb-voice-time`,this.voiceTime.setAttribute(`role`,`timer`),this.voiceTime.textContent=`0:00`;let t=document.createElement(`div`);return t.className=`ttcb-voice-meter`,t.setAttribute(`aria-hidden`,`true`),this.voiceLevel=document.createElement(`span`),this.voiceLevel.className=`ttcb-voice-level`,t.appendChild(this.voiceLevel),this.voiceCancelBtn=this.createVoiceButton(`Cancel recording`,dn(),()=>this.cancelVoice()),this.voiceStopBtn=this.createVoiceButton(`Stop recording`,un(),()=>void this.stopVoice()),this.voiceStopBtn.classList.add(`primary`),this.voiceBar.appendChild(e),this.voiceBar.appendChild(this.voiceTime),this.voiceBar.appendChild(t),this.voiceBar.appendChild(this.voiceCancelBtn),this.voiceBar.appendChild(this.voiceStopBtn),this.voiceBar}buildVoicePreview(){return this.voicePreview=document.createElement(`div`),this.voicePreview.className=`ttcb-voice-preview`,this.voicePreview.setAttribute(`role`,`group`),this.voicePreview.setAttribute(`aria-label`,`Voice message preview`),this.voiceAudio=document.createElement(`audio`),this.voiceAudio.className=`ttcb-voice-audio`,this.voiceAudio.controls=!0,this.voiceAudio.preload=`metadata`,this.voiceAudio.setAttribute(`aria-label`,`Recorded voice message`),this.voicePreviewTime=document.createElement(`span`),this.voicePreviewTime.className=`ttcb-voice-time`,this.voiceDiscardBtn=this.createVoiceButton(`Discard voice message`,dn(),()=>this.cancelVoice()),this.voiceSendBtn=this.createVoiceButton(`Send voice message`,Yt(),()=>this.sendVoice()),this.voiceSendBtn.classList.add(`primary`),this.voicePreview.appendChild(this.voiceAudio),this.voicePreview.appendChild(this.voicePreviewTime),this.voicePreview.appendChild(this.voiceDiscardBtn),this.voicePreview.appendChild(this.voiceSendBtn),this.voicePreview}createVoiceButton(e,t,n){let r=document.createElement(`button`);return r.type=`button`,r.className=`ttcb-voice-btn`,r.setAttribute(`aria-label`,e),r.title=e,r.innerHTML=t,r.addEventListener(`click`,n),r}async startVoice(){if(!this.micBtn.disabled){if(this.closeAttachMenu(),this.showComposeError(``),!Y.isSupported())this.showComposeError(`Voice messages are not supported in this browser.`);else{this.recorder?.destroy(),this.recorder=new Y(e=>this.renderVoice(e));try{await this.recorder.start()}catch(e){this.showComposeError(e instanceof Error?e.message:`Could not start recording.`),this.recorder.destroy(),this.recorder=null,this.renderVoice({state:`idle`,elapsedSeconds:0,level:0,result:null})}}}}async stopVoice(){await this.recorder?.stop()}cancelVoice(){this.recorder?.cancel(),this.recorder?.destroy(),this.recorder=null,this.renderVoice({state:`idle`,elapsedSeconds:0,level:0,result:null}),this.input.focus()}sendVoice(){let e=this.recorder?.getSnapshot().result;e&&(this.cancelVoice(),this.callbacks.onSendVoice(e))}renderVoice(e){if(this.destroyed)return;let{state:t}=e;this.composeForm.classList.toggle(`hidden`,t!==`idle`),this.voiceBar.classList.toggle(`visible`,t===`recording`),this.voicePreview.classList.toggle(`visible`,t===`preview`),t===`recording`?(this.voiceTime.textContent=v(e.elapsedSeconds),this.voiceLevel.style.width=`${Math.max(4,Math.round(e.level*100))}%`):(h(this.voicePreviewUrl),this.voicePreviewUrl=``,this.voiceAudio.removeAttribute(`src`),t===`preview`&&e.result&&(this.voicePreviewUrl=m(new File([e.result.blob],`voice-preview`,{type:e.result.blob.type})),this.voicePreviewUrl&&(this.voiceAudio.src=this.voicePreviewUrl),this.voicePreviewTime.textContent=v(e.result.durationSeconds),queueMicrotask(()=>this.voiceSendBtn.focus())))}showComposeError(e){this.composeError.textContent=e,this.composeError.classList.toggle(`visible`,!!e)}setPanelMode(e){this.panel.classList.remove(`ttcb-mode-form`,`ttcb-mode-chat`,`ttcb-mode-compact`),this.panel.classList.add(`ttcb-mode-${e}`),e!==`chat`&&(this.requestHumanBtn.classList.add(`hidden`),this.newSessionBtn.classList.add(`hidden`),this.hideModeBanner())}buildIdentifyForm(e){let t=document.createElement(`form`);t.className=`ttcb-identify-form`,t.addEventListener(`submit`,e=>{e.preventDefault(),this.handleIdentifySubmit()}),this.nameInput=this.createIconField(t,{id:`name`,label:`Name`,required:!0,hint:`Required`,placeholder:`Your name`,type:`text`,autocomplete:`name`,icon:Zt()}),this.createPhoneField(t),this.emailInput=this.createIconField(t,{id:`email`,label:`Email (optional)`,required:!1,hint:`For chat transcript`,placeholder:`Email (optional)`,type:`email`,autocomplete:`email`,icon:Qt()}),this.identifyError=document.createElement(`p`),this.identifyError.className=`ttcb-identify-error`,t.appendChild(this.identifyError),this.identifySubmit=document.createElement(`button`),this.identifySubmit.type=`submit`,this.identifySubmit.className=`ttcb-identify-submit`,this.identifySubmit.innerHTML=`<span>Start Chatting</span>${en()}`,t.appendChild(this.identifySubmit),e.appendChild(t);let n=document.createElement(`div`);n.className=`ttcb-trust`,n.innerHTML=`${tn()}<span>Encrypted connection • No spam, ever</span>`,e.appendChild(n)}createIconField(e,t){let n=document.createElement(`div`);n.className=`ttcb-field`;let r=document.createElement(`div`);r.className=`ttcb-field-label-row`;let i=document.createElement(`label`);i.className=`ttcb-label`,i.htmlFor=`ttcb-${t.id}`,t.required?i.innerHTML=`${t.label.replace(` (optional)`,``)} <span class="ttcb-req">*</span>`:i.textContent=t.label;let a=document.createElement(`span`);a.className=`ttcb-field-hint`,a.textContent=t.hint,r.appendChild(i),r.appendChild(a);let o=document.createElement(`div`);o.className=`ttcb-input-wrap`;let s=document.createElement(`span`);s.className=`ttcb-input-icon`,s.setAttribute(`aria-hidden`,`true`),s.innerHTML=t.icon;let c=document.createElement(`input`);return c.id=`ttcb-${t.id}`,c.name=t.id,c.type=t.type,c.className=`ttcb-identify-input`,c.placeholder=t.placeholder,c.required=t.required,c.autocomplete=t.autocomplete,o.appendChild(s),o.appendChild(c),n.appendChild(r),n.appendChild(o),e.appendChild(n),c}createPhoneField(e){let t=document.createElement(`div`);t.className=`ttcb-field`;let n=document.createElement(`div`);n.className=`ttcb-field-label-row`;let r=document.createElement(`label`);r.className=`ttcb-label`,r.htmlFor=`ttcb-tel`,r.innerHTML=`Phone <span class="ttcb-req">*</span>`;let i=document.createElement(`span`);i.className=`ttcb-field-hint`,i.textContent=`SMS / WhatsApp sync`,n.appendChild(r),n.appendChild(i);let a=document.createElement(`div`);a.className=`ttcb-phone-row`,a.id=`ttcb-phone-row`,this.dialBtn=document.createElement(`button`),this.dialBtn.type=`button`,this.dialBtn.className=`ttcb-dial-btn`,this.dialBtn.setAttribute(`aria-label`,`Select country code`),this.dialBtn.setAttribute(`aria-haspopup`,`listbox`),this.dialBtn.setAttribute(`aria-expanded`,`false`),this.dialFlag=document.createElement(`span`),this.dialFlag.className=`ttcb-dial-flag`,this.dialCode=document.createElement(`span`),this.dialCode.className=`ttcb-dial-code`,this.syncDialButton(),this.dialBtn.appendChild(this.dialFlag),this.dialBtn.appendChild(this.dialCode);let o=document.createElement(`span`);o.setAttribute(`aria-hidden`,`true`),o.innerHTML=$t(),this.dialBtn.appendChild(o),this.dialBtn.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this.toggleCountryPopover()}),this.phoneInput=document.createElement(`input`),this.phoneInput.id=`ttcb-tel`,this.phoneInput.name=`tel`,this.phoneInput.type=`tel`,this.phoneInput.className=`ttcb-phone-national`,this.phoneInput.placeholder=`1712-345678`,this.phoneInput.required=!0,this.phoneInput.autocomplete=`tel-national`,this.phoneInput.setAttribute(`inputmode`,`tel`),a.appendChild(this.dialBtn),a.appendChild(this.phoneInput),this.countryPopover=document.createElement(`div`),this.countryPopover.className=`ttcb-country-popover`,this.countryPopover.setAttribute(`role`,`listbox`),this.countrySearch=document.createElement(`input`),this.countrySearch.type=`search`,this.countrySearch.className=`ttcb-country-search`,this.countrySearch.placeholder=`Search country…`,this.countrySearch.setAttribute(`aria-label`,`Search countries`),this.countrySearch.addEventListener(`input`,()=>this.renderCountryList()),this.countryList=document.createElement(`div`),this.countryList.className=`ttcb-country-list`,this.countryPopover.appendChild(this.countrySearch),this.countryPopover.appendChild(this.countryList),this.renderCountryList(),t.appendChild(n),t.appendChild(a),t.appendChild(this.countryPopover),e.appendChild(t)}syncDialButton(){this.dialFlag.textContent=this.selectedCountry.flag,this.dialCode.textContent=`+${this.selectedCountry.dial}`}toggleCountryPopover(){this.countryOpen?this.closeCountryPopover():this.openCountryPopover()}openCountryPopover(){this.countryOpen=!0,this.countryPopover.classList.add(`open`),this.dialBtn.setAttribute(`aria-expanded`,`true`),this.countrySearch.value=``,this.renderCountryList(),queueMicrotask(()=>this.countrySearch.focus())}closeCountryPopover(){this.countryOpen=!1,this.countryPopover.classList.remove(`open`),this.dialBtn.setAttribute(`aria-expanded`,`false`)}renderCountryList(){let e=this.countrySearch.value.trim().toLowerCase(),t=X.filter(t=>!e||t.name.toLowerCase().includes(e)||t.dial.includes(e)||t.iso.toLowerCase().includes(e)||`+${t.dial}`.includes(e));this.countryList.innerHTML=``;for(let e of t){let t=document.createElement(`button`);t.type=`button`,t.className=`ttcb-country-item`,t.setAttribute(`role`,`option`),t.setAttribute(`aria-selected`,e.iso===this.selectedCountry.iso?`true`:`false`),t.innerHTML=`
764
+ </svg>`}function pn(e){let t=p(e.url)?e.url:``,n=e.type.toLowerCase();if(t&&n.startsWith(`image/`)){let n=document.createElement(`a`);n.className=`ttcb-attachment ttcb-attachment-image`,n.href=t,n.target=`_blank`,n.rel=`noopener noreferrer`,n.setAttribute(`aria-label`,`Open ${e.fileName}`);let r=document.createElement(`img`);return r.src=t,r.alt=e.fileName,r.loading=`lazy`,n.appendChild(r),n}if(t&&n.startsWith(`video/`)){let n=document.createElement(`video`);return n.className=`ttcb-attachment ttcb-attachment-video`,n.controls=!0,n.preload=`metadata`,n.src=t,n.setAttribute(`aria-label`,e.fileName),n}if(t&&n.startsWith(`audio/`)){let n=document.createElement(`div`);n.className=`ttcb-attachment ttcb-attachment-voice`;let r=document.createElement(`audio`);if(r.className=`ttcb-attachment-audio`,r.controls=!0,r.preload=`metadata`,r.src=t,r.setAttribute(`aria-label`,e.fileName),n.appendChild(r),typeof e.durationSeconds==`number`&&e.durationSeconds>0){let t=document.createElement(`span`);t.className=`ttcb-attachment-duration`,t.textContent=v(e.durationSeconds),n.appendChild(t)}return n}let r=document.createElement(t?`a`:`div`);r.className=`ttcb-attachment ttcb-attachment-file`,r instanceof HTMLAnchorElement&&(r.href=t,r.target=`_blank`,r.rel=`noopener noreferrer`);let i=document.createElement(`span`);i.className=`ttcb-attachment-icon`,i.setAttribute(`aria-hidden`,`true`),i.innerHTML=fn();let a=document.createElement(`span`);a.className=`ttcb-attachment-meta`;let o=document.createElement(`span`);o.className=`ttcb-attachment-name`,o.textContent=e.fileName,a.appendChild(o);let s=te(e.size);if(s){let e=document.createElement(`span`);e.className=`ttcb-attachment-size`,e.textContent=s,a.appendChild(e)}return r.appendChild(i),r.appendChild(a),r}function mn(e){let{type:t,content:n}=e,r=e.attachments??[],i=document.createElement(`div`);i.className=`ttcb-msg ${t}`,e.pending&&i.classList.add(`ttcb-pending`);let a=document.createElement(`div`);a.className=`ttcb-msg-avatar`,a.innerHTML=t===`human`?Xt():t===`agent`?Zt():Z();let o=document.createElement(`div`);if(o.className=`ttcb-msg-body`,t===`agent`){let e=document.createElement(`span`);e.className=`ttcb-msg-label`,e.textContent=`Agent`,o.appendChild(e)}if(r.length>0){let e=document.createElement(`div`);e.className=`ttcb-attachments`;for(let t of r)e.appendChild(pn(t));o.appendChild(e)}if(r.length===0||!re(n,r)){let e=document.createElement(`div`);e.className=`ttcb-bubble`,t===`human`?e.textContent=n:e.innerHTML=Gt(n),o.appendChild(e)}if(e.pending){let e=document.createElement(`span`);e.className=`ttcb-msg-status`,e.textContent=`Uploading…`,o.appendChild(e)}return i.appendChild(a),i.appendChild(o),i}function hn(){let e=document.createElement(`div`);e.className=`ttcb-msg ai`,e.id=`ttcb-typing`;let t=document.createElement(`div`);t.className=`ttcb-msg-avatar`,t.innerHTML=Z();let n=document.createElement(`div`);return n.className=`ttcb-typing`,n.innerHTML=`<span></span><span></span><span></span>`,e.appendChild(t),e.appendChild(n),e}var gn=`image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mpeg,audio/wav,audio/x-m4a,audio/aac,audio/opus,application/pdf,text/csv`,_n=`image/jpeg,image/png,image/gif`,vn=class{constructor(e,t){this.stopViewportSync=null,this.pendingFiles=[],this.attachMenuOpen=!1,this.recorder=null,this.voicePreviewUrl=``,this.selectedCountry=Bt,this.countryOpen=!1,this.isOpen=!1,this.destroyed=!1,this.position=e.position??`bottom-right`,this.callbacks=t,this.autoOpen=e.autoOpen===!0,this.mount(e)}mount(e){this.host=document.createElement(`div`),this.host.id=`onedeskpro-chatbot-host`,this.host.style.display=`none`,this.shadow=this.host.attachShadow({mode:`closed`});let t=document.createElement(`style`);t.textContent=Ut(e.primaryColor??`#2563EB`,e.theme??`auto`),this.shadow.appendChild(t),this.fab=document.createElement(`button`),this.fab.className=`ttcb-fab ${this.position}`,this.fab.setAttribute(`aria-label`,`Open chat`),this.fab.innerHTML=qt(),this.fab.addEventListener(`click`,()=>this.toggle()),this.shadow.appendChild(this.fab),this.panel=document.createElement(`div`),this.panel.className=`ttcb-panel ${this.position} hidden ttcb-mode-compact`,this.panel.tabIndex=-1,this.panel.setAttribute(`role`,`dialog`),this.panel.setAttribute(`aria-modal`,`true`),this.panel.setAttribute(`aria-label`,e.chatbotName??`AI Assistant`),this.panel.appendChild(this.buildHeader(e)),this.identifyContainer=document.createElement(`div`),this.identifyContainer.className=`ttcb-identify`,this.buildIdentifyForm(this.identifyContainer),this.panel.appendChild(this.identifyContainer),this.messagesContainer=document.createElement(`div`),this.messagesContainer.className=`ttcb-messages`,this.messagesContainer.setAttribute(`aria-live`,`polite`),this.messagesContainer.setAttribute(`aria-label`,`Chat messages`),this.panel.appendChild(this.messagesContainer),this.modeBanner=document.createElement(`div`),this.modeBanner.className=`ttcb-mode-banner`,this.modeBanner.setAttribute(`role`,`status`),this.panel.appendChild(this.modeBanner),this.footer=document.createElement(`div`),this.footer.className=`ttcb-footer`,this.pendingTray=document.createElement(`div`),this.pendingTray.className=`ttcb-pending-tray`,this.pendingTray.setAttribute(`role`,`list`),this.pendingTray.setAttribute(`aria-label`,`Files to send`),this.footer.appendChild(this.pendingTray),this.composeError=document.createElement(`p`),this.composeError.className=`ttcb-compose-error`,this.composeError.setAttribute(`role`,`alert`),this.footer.appendChild(this.composeError),this.footer.appendChild(this.buildVoiceBar()),this.footer.appendChild(this.buildVoicePreview());let n=document.createElement(`form`);n.className=`ttcb-form`,n.addEventListener(`submit`,e=>{e.preventDefault(),this.handleSend()}),this.composeForm=n,n.appendChild(this.buildAttachControls()),this.input=document.createElement(`input`),this.input.type=`text`,this.input.className=`ttcb-input`,this.input.placeholder=e.placeholder??`Type your message…`,this.input.setAttribute(`aria-label`,`Message input`),this.input.setAttribute(`autocomplete`,`off`),this.sendBtn=document.createElement(`button`),this.sendBtn.type=`submit`,this.sendBtn.className=`ttcb-send-btn`,this.sendBtn.innerHTML=Yt(),this.sendBtn.setAttribute(`aria-label`,`Send message`),this.micBtn=document.createElement(`button`),this.micBtn.type=`button`,this.micBtn.className=`ttcb-mic-btn`,this.micBtn.setAttribute(`aria-label`,`Record voice message`),this.micBtn.title=`Record voice message`,this.micBtn.innerHTML=ln(),this.micBtn.addEventListener(`click`,()=>void this.startVoice()),n.appendChild(this.input),n.appendChild(this.micBtn),n.appendChild(this.sendBtn),this.footer.appendChild(n),this.panel.appendChild(this.footer),this.shadow.appendChild(this.panel),this.shadow.addEventListener(`click`,e=>{let t=e.target;this.attachMenuOpen&&!(t&&(this.attachBtn.contains(t)||this.attachMenu.contains(t)))&&this.closeAttachMenu(),this.countryOpen&&(t&&(this.dialBtn.contains(t)||this.countryPopover.contains(t))||this.closeCountryPopover())}),this.panel.addEventListener(`keydown`,e=>{e.key===`Escape`&&this.attachMenuOpen&&(e.stopPropagation(),this.closeAttachMenu(),this.attachBtn.focus())}),this.attachToDocument(),this.showInitialLoading()}reveal(){this.host.style.removeProperty(`display`),this.autoOpen&&!this.isOpen&&this.open()}buildHeader(e){let t=document.createElement(`div`);t.className=`ttcb-header`;let n=document.createElement(`div`);n.className=`ttcb-avatar-wrap`;let r=document.createElement(`div`);r.className=`ttcb-avatar`,r.innerHTML=Z(),n.appendChild(r);let i=document.createElement(`div`);i.className=`ttcb-header-main`;let a=document.createElement(`div`);a.className=`ttcb-header-title-row`,this.headerTitle=document.createElement(`span`),this.headerTitle.className=`ttcb-header-title`,this.headerTitle.textContent=e.chatbotName??`AI Assistant`;let o=document.createElement(`span`);o.className=`ttcb-verified`,o.setAttribute(`aria-label`,`Verified`),o.innerHTML=nn(),a.appendChild(this.headerTitle),a.appendChild(o);let s=document.createElement(`div`);s.className=`ttcb-header-meta`;let c=document.createElement(`span`);c.className=`ttcb-meta-online`,c.textContent=`Online`;let l=document.createElement(`span`);l.className=`ttcb-meta-sep`,l.setAttribute(`aria-hidden`,`true`);let u=document.createElement(`span`);u.className=`ttcb-meta-replies`,u.innerHTML=`${rn()}<span>Replies instantly</span>`,s.appendChild(c),s.appendChild(l),s.appendChild(u),i.appendChild(a),i.appendChild(s);let d=document.createElement(`div`);d.className=`ttcb-header-actions`,this.requestHumanBtn=document.createElement(`button`),this.requestHumanBtn.type=`button`,this.requestHumanBtn.className=`ttcb-request-human-btn hidden`,this.requestHumanBtn.id=`ttcb-request-human-btn`,this.requestHumanBtn.setAttribute(`aria-label`,`Request human agent`),this.requestHumanBtn.title=`Request human agent`,this.requestHumanBtn.innerHTML=an(),this.requestHumanBtn.addEventListener(`click`,()=>this.callbacks.onRequestHuman()),this.newSessionBtn=document.createElement(`button`),this.newSessionBtn.className=`ttcb-new-session-btn hidden`,this.newSessionBtn.setAttribute(`aria-label`,`New conversation`),this.newSessionBtn.title=`New conversation`,this.newSessionBtn.innerHTML=Kt(),this.newSessionBtn.addEventListener(`click`,()=>this.callbacks.onReset());let f=document.createElement(`button`);return f.className=`ttcb-close-btn`,f.setAttribute(`aria-label`,`Close chat`),f.innerHTML=Jt(),f.addEventListener(`click`,()=>this.close()),d.appendChild(this.requestHumanBtn),d.appendChild(this.newSessionBtn),d.appendChild(f),t.appendChild(n),t.appendChild(i),t.appendChild(d),t}buildAttachControls(){let e=document.createElement(`div`);e.className=`ttcb-attach`,this.attachBtn=document.createElement(`button`),this.attachBtn.type=`button`,this.attachBtn.className=`ttcb-attach-btn`,this.attachBtn.setAttribute(`aria-label`,`Add attachment`),this.attachBtn.setAttribute(`aria-haspopup`,`menu`),this.attachBtn.setAttribute(`aria-expanded`,`false`),this.attachBtn.title=`Add attachment`,this.attachBtn.innerHTML=on(),this.attachBtn.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this.toggleAttachMenu()}),this.attachMenu=document.createElement(`div`),this.attachMenu.className=`ttcb-attach-menu`,this.attachMenu.setAttribute(`role`,`menu`),this.attachFileInput=this.createFileInput(gn,`Choose files`),this.attachPhotoInput=this.createFileInput(_n,`Choose photos`);let t=[{label:`Attachment`,icon:sn(),input:this.attachFileInput},{label:`Photo`,icon:cn(),input:this.attachPhotoInput}];for(let e of t){let t=document.createElement(`button`);t.type=`button`,t.className=`ttcb-attach-item`,t.setAttribute(`role`,`menuitem`),t.innerHTML=`${e.icon}<span>${e.label}</span>`,t.addEventListener(`click`,()=>{this.closeAttachMenu(),e.input.click()}),this.attachMenu.appendChild(t)}return e.appendChild(this.attachBtn),e.appendChild(this.attachMenu),e.appendChild(this.attachFileInput),e.appendChild(this.attachPhotoInput),e}createFileInput(e,t){let n=document.createElement(`input`);return n.type=`file`,n.multiple=!0,n.accept=e,n.className=`ttcb-file-input`,n.tabIndex=-1,n.setAttribute(`aria-label`,t),n.addEventListener(`change`,()=>{this.addPendingFiles(Array.from(n.files??[])),n.value=``}),n}toggleAttachMenu(){this.attachMenuOpen?this.closeAttachMenu():this.openAttachMenu()}openAttachMenu(){if(this.attachBtn.disabled)return;this.attachMenuOpen=!0,this.attachMenu.classList.add(`open`),this.attachBtn.setAttribute(`aria-expanded`,`true`);let e=this.attachMenu.querySelector(`.ttcb-attach-item`);queueMicrotask(()=>e?.focus())}closeAttachMenu(){this.attachMenuOpen&&(this.attachMenuOpen=!1,this.attachMenu.classList.remove(`open`),this.attachBtn.setAttribute(`aria-expanded`,`false`))}addPendingFiles(e){if(e.length===0)return;let t=f([...this.pendingFiles.map(e=>e.file),...e]);if(t)this.showComposeError(t);else{this.showComposeError(``);for(let t of e){let e=t.type.startsWith(`image/`)?m(t):``;this.pendingFiles.push({file:t,previewUrl:e})}this.renderPendingTray(),this.input.focus()}}removePendingFile(e){let[t]=this.pendingFiles.splice(e,1);t&&h(t.previewUrl),this.renderPendingTray(),this.input.focus()}clearPendingFiles(){for(let e of this.pendingFiles)h(e.previewUrl);this.pendingFiles=[],this.renderPendingTray()}renderPendingTray(){this.pendingTray.innerHTML=``,this.pendingTray.classList.toggle(`visible`,this.pendingFiles.length>0),this.pendingFiles.forEach((e,t)=>{let n=document.createElement(`div`);if(n.className=`ttcb-pending-item`,n.setAttribute(`role`,`listitem`),e.previewUrl){let t=document.createElement(`img`);t.className=`ttcb-pending-thumb`,t.src=e.previewUrl,t.alt=``,n.appendChild(t)}else{let e=document.createElement(`span`);e.className=`ttcb-pending-icon`,e.setAttribute(`aria-hidden`,`true`),e.innerHTML=fn(),n.appendChild(e)}let r=document.createElement(`span`);r.className=`ttcb-pending-name`,r.textContent=e.file.name||`attachment`,r.title=e.file.name,n.appendChild(r);let i=document.createElement(`button`);i.type=`button`,i.className=`ttcb-pending-remove`,i.setAttribute(`aria-label`,`Remove ${e.file.name||`attachment`}`),i.innerHTML=Jt(),i.addEventListener(`click`,()=>this.removePendingFile(t)),n.appendChild(i),this.pendingTray.appendChild(n)})}buildVoiceBar(){this.voiceBar=document.createElement(`div`),this.voiceBar.className=`ttcb-voice-bar`,this.voiceBar.setAttribute(`role`,`group`),this.voiceBar.setAttribute(`aria-label`,`Recording voice message`);let e=document.createElement(`span`);e.className=`ttcb-voice-dot`,e.setAttribute(`aria-hidden`,`true`),this.voiceTime=document.createElement(`span`),this.voiceTime.className=`ttcb-voice-time`,this.voiceTime.setAttribute(`role`,`timer`),this.voiceTime.textContent=`0:00`;let t=document.createElement(`div`);return t.className=`ttcb-voice-meter`,t.setAttribute(`aria-hidden`,`true`),this.voiceLevel=document.createElement(`span`),this.voiceLevel.className=`ttcb-voice-level`,t.appendChild(this.voiceLevel),this.voiceCancelBtn=this.createVoiceButton(`Cancel recording`,dn(),()=>this.cancelVoice()),this.voiceStopBtn=this.createVoiceButton(`Stop recording`,un(),()=>void this.stopVoice()),this.voiceStopBtn.classList.add(`primary`),this.voiceBar.appendChild(e),this.voiceBar.appendChild(this.voiceTime),this.voiceBar.appendChild(t),this.voiceBar.appendChild(this.voiceCancelBtn),this.voiceBar.appendChild(this.voiceStopBtn),this.voiceBar}buildVoicePreview(){return this.voicePreview=document.createElement(`div`),this.voicePreview.className=`ttcb-voice-preview`,this.voicePreview.setAttribute(`role`,`group`),this.voicePreview.setAttribute(`aria-label`,`Voice message preview`),this.voiceAudio=document.createElement(`audio`),this.voiceAudio.className=`ttcb-voice-audio`,this.voiceAudio.controls=!0,this.voiceAudio.preload=`metadata`,this.voiceAudio.setAttribute(`aria-label`,`Recorded voice message`),this.voicePreviewTime=document.createElement(`span`),this.voicePreviewTime.className=`ttcb-voice-time`,this.voiceDiscardBtn=this.createVoiceButton(`Discard voice message`,dn(),()=>this.cancelVoice()),this.voiceSendBtn=this.createVoiceButton(`Send voice message`,Yt(),()=>this.sendVoice()),this.voiceSendBtn.classList.add(`primary`),this.voicePreview.appendChild(this.voiceAudio),this.voicePreview.appendChild(this.voicePreviewTime),this.voicePreview.appendChild(this.voiceDiscardBtn),this.voicePreview.appendChild(this.voiceSendBtn),this.voicePreview}createVoiceButton(e,t,n){let r=document.createElement(`button`);return r.type=`button`,r.className=`ttcb-voice-btn`,r.setAttribute(`aria-label`,e),r.title=e,r.innerHTML=t,r.addEventListener(`click`,n),r}async startVoice(){if(!this.micBtn.disabled){if(this.closeAttachMenu(),this.showComposeError(``),!Y.isSupported())this.showComposeError(`Voice messages are not supported in this browser.`);else{this.recorder?.destroy(),this.recorder=new Y(e=>this.renderVoice(e));try{await this.recorder.start()}catch(e){this.showComposeError(e instanceof Error?e.message:`Could not start recording.`),this.recorder.destroy(),this.recorder=null,this.renderVoice({state:`idle`,elapsedSeconds:0,level:0,result:null})}}}}async stopVoice(){await this.recorder?.stop()}cancelVoice(){this.recorder?.cancel(),this.recorder?.destroy(),this.recorder=null,this.renderVoice({state:`idle`,elapsedSeconds:0,level:0,result:null}),this.input.focus()}sendVoice(){let e=this.recorder?.getSnapshot().result;e&&(this.cancelVoice(),this.callbacks.onSendVoice(e))}renderVoice(e){if(this.destroyed)return;let{state:t}=e;this.composeForm.classList.toggle(`hidden`,t!==`idle`),this.voiceBar.classList.toggle(`visible`,t===`recording`),this.voicePreview.classList.toggle(`visible`,t===`preview`),t===`recording`?(this.voiceTime.textContent=v(e.elapsedSeconds),this.voiceLevel.style.width=`${Math.max(4,Math.round(e.level*100))}%`):(h(this.voicePreviewUrl),this.voicePreviewUrl=``,this.voiceAudio.removeAttribute(`src`),t===`preview`&&e.result&&(this.voicePreviewUrl=m(new File([e.result.blob],`voice-preview`,{type:e.result.blob.type})),this.voicePreviewUrl&&(this.voiceAudio.src=this.voicePreviewUrl),this.voicePreviewTime.textContent=v(e.result.durationSeconds),queueMicrotask(()=>this.voiceSendBtn.focus())))}showComposeError(e){this.composeError.textContent=e,this.composeError.classList.toggle(`visible`,!!e)}setPanelMode(e){this.panel.classList.remove(`ttcb-mode-form`,`ttcb-mode-chat`,`ttcb-mode-compact`),this.panel.classList.add(`ttcb-mode-${e}`),e!==`chat`&&(this.requestHumanBtn.classList.add(`hidden`),this.newSessionBtn.classList.add(`hidden`),this.hideModeBanner())}buildIdentifyForm(e){let t=document.createElement(`form`);t.className=`ttcb-identify-form`,t.addEventListener(`submit`,e=>{e.preventDefault(),this.handleIdentifySubmit()}),this.nameInput=this.createIconField(t,{id:`name`,label:`Name`,required:!0,hint:`Required`,placeholder:`Your name`,type:`text`,autocomplete:`name`,icon:Zt()}),this.createPhoneField(t),this.emailInput=this.createIconField(t,{id:`email`,label:`Email (optional)`,required:!1,hint:`For chat transcript`,placeholder:`Email (optional)`,type:`email`,autocomplete:`email`,icon:Qt()}),this.identifyError=document.createElement(`p`),this.identifyError.className=`ttcb-identify-error`,t.appendChild(this.identifyError),this.identifySubmit=document.createElement(`button`),this.identifySubmit.type=`submit`,this.identifySubmit.className=`ttcb-identify-submit`,this.identifySubmit.innerHTML=`<span>Start Chatting</span>${en()}`,t.appendChild(this.identifySubmit),e.appendChild(t);let n=document.createElement(`div`);n.className=`ttcb-trust`,n.innerHTML=`${tn()}<span>Encrypted connection • No spam, ever</span>`,e.appendChild(n)}createIconField(e,t){let n=document.createElement(`div`);n.className=`ttcb-field`;let r=document.createElement(`div`);r.className=`ttcb-field-label-row`;let i=document.createElement(`label`);i.className=`ttcb-label`,i.htmlFor=`ttcb-${t.id}`,t.required?i.innerHTML=`${t.label.replace(` (optional)`,``)} <span class="ttcb-req">*</span>`:i.textContent=t.label;let a=document.createElement(`span`);a.className=`ttcb-field-hint`,a.textContent=t.hint,r.appendChild(i),r.appendChild(a);let o=document.createElement(`div`);o.className=`ttcb-input-wrap`;let s=document.createElement(`span`);s.className=`ttcb-input-icon`,s.setAttribute(`aria-hidden`,`true`),s.innerHTML=t.icon;let c=document.createElement(`input`);return c.id=`ttcb-${t.id}`,c.name=t.id,c.type=t.type,c.className=`ttcb-identify-input`,c.placeholder=t.placeholder,c.required=t.required,c.autocomplete=t.autocomplete,o.appendChild(s),o.appendChild(c),n.appendChild(r),n.appendChild(o),e.appendChild(n),c}createPhoneField(e){let t=document.createElement(`div`);t.className=`ttcb-field`;let n=document.createElement(`div`);n.className=`ttcb-field-label-row`;let r=document.createElement(`label`);r.className=`ttcb-label`,r.htmlFor=`ttcb-tel`,r.innerHTML=`Phone <span class="ttcb-req">*</span>`;let i=document.createElement(`span`);i.className=`ttcb-field-hint`,i.textContent=`SMS / WhatsApp sync`,n.appendChild(r),n.appendChild(i);let a=document.createElement(`div`);a.className=`ttcb-phone-row`,a.id=`ttcb-phone-row`,this.dialBtn=document.createElement(`button`),this.dialBtn.type=`button`,this.dialBtn.className=`ttcb-dial-btn`,this.dialBtn.setAttribute(`aria-label`,`Select country code`),this.dialBtn.setAttribute(`aria-haspopup`,`listbox`),this.dialBtn.setAttribute(`aria-expanded`,`false`),this.dialFlag=document.createElement(`span`),this.dialFlag.className=`ttcb-dial-flag`,this.dialCode=document.createElement(`span`),this.dialCode.className=`ttcb-dial-code`,this.syncDialButton(),this.dialBtn.appendChild(this.dialFlag),this.dialBtn.appendChild(this.dialCode);let o=document.createElement(`span`);o.setAttribute(`aria-hidden`,`true`),o.innerHTML=$t(),this.dialBtn.appendChild(o),this.dialBtn.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this.toggleCountryPopover()}),this.phoneInput=document.createElement(`input`),this.phoneInput.id=`ttcb-tel`,this.phoneInput.name=`tel`,this.phoneInput.type=`tel`,this.phoneInput.className=`ttcb-phone-national`,this.phoneInput.placeholder=`1712-345678`,this.phoneInput.required=!0,this.phoneInput.autocomplete=`tel-national`,this.phoneInput.setAttribute(`inputmode`,`tel`),a.appendChild(this.dialBtn),a.appendChild(this.phoneInput),this.countryPopover=document.createElement(`div`),this.countryPopover.className=`ttcb-country-popover`,this.countryPopover.setAttribute(`role`,`listbox`),this.countrySearch=document.createElement(`input`),this.countrySearch.type=`search`,this.countrySearch.className=`ttcb-country-search`,this.countrySearch.placeholder=`Search country…`,this.countrySearch.setAttribute(`aria-label`,`Search countries`),this.countrySearch.addEventListener(`input`,()=>this.renderCountryList()),this.countryList=document.createElement(`div`),this.countryList.className=`ttcb-country-list`,this.countryPopover.appendChild(this.countrySearch),this.countryPopover.appendChild(this.countryList),this.renderCountryList(),t.appendChild(n),t.appendChild(a),t.appendChild(this.countryPopover),e.appendChild(t)}syncDialButton(){this.dialFlag.textContent=this.selectedCountry.flag,this.dialCode.textContent=`+${this.selectedCountry.dial}`}toggleCountryPopover(){this.countryOpen?this.closeCountryPopover():this.openCountryPopover()}openCountryPopover(){this.countryOpen=!0,this.countryPopover.classList.add(`open`),this.dialBtn.setAttribute(`aria-expanded`,`true`),this.countrySearch.value=``,this.renderCountryList(),queueMicrotask(()=>this.countrySearch.focus())}closeCountryPopover(){this.countryOpen=!1,this.countryPopover.classList.remove(`open`),this.dialBtn.setAttribute(`aria-expanded`,`false`)}renderCountryList(){let e=this.countrySearch.value.trim().toLowerCase(),t=X.filter(t=>!e||t.name.toLowerCase().includes(e)||t.dial.includes(e)||t.iso.toLowerCase().includes(e)||`+${t.dial}`.includes(e));this.countryList.innerHTML=``;for(let e of t){let t=document.createElement(`button`);t.type=`button`,t.className=`ttcb-country-item`,t.setAttribute(`role`,`option`),t.setAttribute(`aria-selected`,e.iso===this.selectedCountry.iso?`true`:`false`),t.innerHTML=`
765
765
  <span class="ttcb-dial-flag">${e.flag}</span>
766
766
  <span class="ttcb-country-item-name">${e.name}</span>
767
767
  <span class="ttcb-country-item-dial">+${e.dial}</span>
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region \0rolldown/runtime.js
1
+ // \0rolldown/runtime.js
2
2
  var e = Object.defineProperty, t = (t, n) => {
3
3
  let r = {};
4
4
  for (var i in t) e(r, i, {
@@ -95,8 +95,7 @@ var s = class {
95
95
  return this.request("GET", "/sdk/ticket-status", void 0, void 0, { "X-Visitor-Token": e });
96
96
  }
97
97
  }, c = "https://api.onedeskpro.com", l = 10485760, u = 10;
98
- //#endregion
99
- //#region src/attachments.ts
98
+ // src/attachments.ts
100
99
  function d(e) {
101
100
  if (e.length > 10) return "You can send up to 10 files at a time.";
102
101
  let t = e.find((e) => e.size > l);
@@ -153,8 +152,7 @@ function re(e, t) {
153
152
  "Attachment"
154
153
  ].includes(n) : !0;
155
154
  }
156
- //#endregion
157
- //#region src/audio.ts
155
+ // src/audio.ts
158
156
  var h = 16e3;
159
157
  function g(e) {
160
158
  return (e ?? "").split(";")[0].trim().toLowerCase() || "audio/webm";
@@ -243,8 +241,7 @@ async function de(e) {
243
241
  waveform: ue(a)
244
242
  };
245
243
  }
246
- //#endregion
247
- //#region src/event-emitter.ts
244
+ // src/event-emitter.ts
248
245
  var fe = class {
249
246
  constructor() {
250
247
  this._listeners = {};
@@ -290,8 +287,7 @@ function ye(e, t) {
290
287
  ve ||= new TextEncoder(), t(ve.encode(e));
291
288
  });
292
289
  }
293
- //#endregion
294
- //#region ../../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.js
290
+ // ../../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.js
295
291
  var be = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", S = typeof Uint8Array > "u" ? [] : /* @__PURE__ */ new Uint8Array(256);
296
292
  for (let e = 0; e < 64; e++) S[be.charCodeAt(e)] = e;
297
293
  var xe = (e) => {
@@ -397,8 +393,7 @@ function Ae(e, t) {
397
393
  }
398
394
  } });
399
395
  }
400
- //#endregion
401
- //#region ../../node_modules/.pnpm/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/lib/esm/index.js
396
+ // ../../node_modules/.pnpm/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/lib/esm/index.js
402
397
  function E(e) {
403
398
  if (e) return je(e);
404
399
  }
@@ -436,11 +431,9 @@ E.prototype.on = E.prototype.addEventListener = function(e, t) {
436
431
  }, E.prototype.hasListeners = function(e) {
437
432
  return !!this.listeners(e).length;
438
433
  };
439
- //#endregion
440
- //#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/globals.js
434
+ // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/globals.js
441
435
  var D = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), O = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), Me = "arraybuffer";
442
- //#endregion
443
- //#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/util.js
436
+ // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/util.js
444
437
  function Ne(e, ...t) {
445
438
  return t.reduce((t, n) => (e.hasOwnProperty(n) && (t[n] = e[n]), t), {});
446
439
  }
@@ -460,8 +453,7 @@ function Re(e) {
460
453
  function ze() {
461
454
  return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
462
455
  }
463
- //#endregion
464
- //#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/contrib/parseqs.js
456
+ // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/contrib/parseqs.js
465
457
  function Be(e) {
466
458
  let t = "";
467
459
  for (let n in e) e.hasOwnProperty(n) && (t.length && (t += "&"), t += encodeURIComponent(n) + "=" + encodeURIComponent(e[n]));
@@ -475,8 +467,7 @@ function Ve(e) {
475
467
  }
476
468
  return t;
477
469
  }
478
- //#endregion
479
- //#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transport.js
470
+ // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transport.js
480
471
  var He = class extends Error {
481
472
  constructor(e, t, n) {
482
473
  super(e), this.description = t, this.context = n, this.type = "TransportError";
@@ -580,8 +571,7 @@ try {
580
571
  We = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
581
572
  } catch {}
582
573
  var Ge = We;
583
- //#endregion
584
- //#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transports/polling-xhr.js
574
+ // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transports/polling-xhr.js
585
575
  function Ke() {}
586
576
  var qe = class extends Ue {
587
577
  constructor(e) {
@@ -690,11 +680,10 @@ function Ze(e) {
690
680
  if (typeof XMLHttpRequest < "u" && (!t || Ge)) return new XMLHttpRequest();
691
681
  } catch {}
692
682
  if (!t) try {
693
- return new O[["Active", "Object"].join("X")]("Microsoft.XMLHTTP");
683
+ return new O.ActiveXObject("Microsoft.XMLHTTP");
694
684
  } catch {}
695
685
  }
696
- //#endregion
697
- //#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transports/websocket.js
686
+ // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transports/websocket.js
698
687
  var Qe = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative", $e = class extends A {
699
688
  get name() {
700
689
  return "websocket";
@@ -827,8 +816,7 @@ function it(e, t) {
827
816
  t && (n[t] = r);
828
817
  }), n;
829
818
  }
830
- //#endregion
831
- //#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/socket.js
819
+ // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/socket.js
832
820
  var P = typeof addEventListener == "function" && typeof removeEventListener == "function", F = [];
833
821
  P && addEventListener("offline", () => {
834
822
  F.forEach((e) => e());
@@ -1054,16 +1042,14 @@ var at = class extends I {
1054
1042
  }
1055
1043
  };
1056
1044
  ot.protocol;
1057
- //#endregion
1058
- //#region ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/url.js
1045
+ // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/url.js
1059
1046
  function st(e, t = "", n) {
1060
1047
  let r = e;
1061
1048
  n ||= typeof location < "u" && location, e ??= n.protocol + "//" + n.host, typeof e == "string" && (e.charAt(0) === "/" && (e = e.charAt(1) === "/" ? n.protocol + e : n.host + e), /^(https?|wss?):\/\//.test(e) || (e = n === void 0 ? "https://" + e : n.protocol + "//" + e), r = N(e)), r.port || (/^(http|ws)$/.test(r.protocol) ? r.port = "80" : /^(http|ws)s$/.test(r.protocol) && (r.port = "443")), r.path = r.path || "/";
1062
1049
  let i = r.host.indexOf(":") === -1 ? r.host : "[" + r.host + "]";
1063
1050
  return r.id = r.protocol + "://" + i + ":" + r.port + t, r.href = r.protocol + "://" + i + (n && n.port === r.port ? "" : ":" + r.port), r;
1064
1051
  }
1065
- //#endregion
1066
- //#region ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/is-binary.js
1052
+ // ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/is-binary.js
1067
1053
  var ct = typeof ArrayBuffer == "function", lt = (e) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(e) : e.buffer instanceof ArrayBuffer, ut = Object.prototype.toString, dt = typeof Blob == "function" || typeof Blob < "u" && ut.call(Blob) === "[object BlobConstructor]", ft = typeof File == "function" || typeof File < "u" && ut.call(File) === "[object FileConstructor]";
1068
1054
  function L(e) {
1069
1055
  return ct && (e instanceof ArrayBuffer || lt(e)) || dt && e instanceof Blob || ft && e instanceof File;
@@ -1079,8 +1065,7 @@ function R(e, t) {
1079
1065
  for (let t in e) if (Object.prototype.hasOwnProperty.call(e, t) && R(e[t])) return !0;
1080
1066
  return !1;
1081
1067
  }
1082
- //#endregion
1083
- //#region ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/binary.js
1068
+ // ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/binary.js
1084
1069
  function pt(e) {
1085
1070
  let t = [], n = e.data, r = e;
1086
1071
  return r.data = z(n, t), r.attachments = t.length, {
@@ -1123,8 +1108,7 @@ function B(e, t) {
1123
1108
  else if (typeof e == "object") for (let n in e) Object.prototype.hasOwnProperty.call(e, n) && (e[n] = B(e[n], t));
1124
1109
  return e;
1125
1110
  }
1126
- //#endregion
1127
- //#region ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/index.js
1111
+ // ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/index.js
1128
1112
  var ht = /* @__PURE__ */ t({
1129
1113
  Decoder: () => vt,
1130
1114
  Encoder: () => _t,
@@ -1280,15 +1264,13 @@ function Ct(e, t) {
1280
1264
  function wt(e) {
1281
1265
  return bt(e.nsp) && St(e.id) && Ct(e.type, e.data);
1282
1266
  }
1283
- //#endregion
1284
- //#region ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/on.js
1267
+ // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/on.js
1285
1268
  function U(e, t, n) {
1286
1269
  return e.on(t, n), function() {
1287
1270
  e.off(t, n);
1288
1271
  };
1289
1272
  }
1290
- //#endregion
1291
- //#region ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/socket.js
1273
+ // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/socket.js
1292
1274
  var Tt = Object.freeze({
1293
1275
  connect: 1,
1294
1276
  connect_error: 1,
@@ -1525,8 +1507,7 @@ var Tt = Object.freeze({
1525
1507
  }
1526
1508
  }
1527
1509
  };
1528
- //#endregion
1529
- //#region ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/contrib/backo2.js
1510
+ // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/contrib/backo2.js
1530
1511
  function W(e) {
1531
1512
  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;
1532
1513
  }
@@ -1546,8 +1527,7 @@ W.prototype.duration = function() {
1546
1527
  }, W.prototype.setJitter = function(e) {
1547
1528
  this.jitter = e;
1548
1529
  };
1549
- //#endregion
1550
- //#region ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/manager.js
1530
+ // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/manager.js
1551
1531
  var G = class extends E {
1552
1532
  constructor(e, t) {
1553
1533
  super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t ||= {}, t.path = t.path || "/socket.io", this.opts = t, k(this, t), this.reconnection(t.reconnection !== !1), this.reconnectionAttempts(t.reconnectionAttempts || Infinity), this.reconnectionDelay(t.reconnectionDelay || 1e3), this.reconnectionDelayMax(t.reconnectionDelayMax || 5e3), this.randomizationFactor(t.randomizationFactor ?? .5), this.backoff = new W({
@@ -1687,8 +1667,7 @@ Object.assign(q, {
1687
1667
  io: q,
1688
1668
  connect: q
1689
1669
  });
1690
- //#endregion
1691
- //#region src/sdk-socket.ts
1670
+ // src/sdk-socket.ts
1692
1671
  function Dt(e) {
1693
1672
  let t = e.replace(/\/$/, "");
1694
1673
  try {
@@ -2282,8 +2261,7 @@ function Bt(e, t) {
2282
2261
  let r = n.replace(/\D/g, "");
2283
2262
  return !r || (r = r.replace(/^0+/, ""), !r) ? "" : `+${e}${r}`;
2284
2263
  }
2285
- //#endregion
2286
- //#region src/widget/styles.ts
2264
+ // src/widget/styles.ts
2287
2265
  var Vt = "(max-width: 640px), (max-height: 500px) and (pointer: coarse)";
2288
2266
  function Ht(e, t) {
2289
2267
  let n = `
@@ -2985,8 +2963,7 @@ function Ht(e, t) {
2985
2963
  }
2986
2964
  `;
2987
2965
  }
2988
- //#endregion
2989
- //#region src/widget/render.ts
2966
+ // src/widget/render.ts
2990
2967
  function Ut(e) {
2991
2968
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
2992
2969
  }
@@ -3149,23 +3126,8 @@ function mn() {
3149
3126
  let n = document.createElement("div");
3150
3127
  return n.className = "ttcb-typing", n.innerHTML = "<span></span><span></span><span></span>", e.appendChild(t), e.appendChild(n), e;
3151
3128
  }
3152
- //#endregion
3153
- //#region src/widget/widget.ts
3154
- var hn = [
3155
- "image/jpeg",
3156
- "image/png",
3157
- "image/gif",
3158
- "video/mp4",
3159
- "video/webm",
3160
- "audio/ogg",
3161
- "audio/mpeg",
3162
- "audio/wav",
3163
- "audio/x-m4a",
3164
- "audio/aac",
3165
- "audio/opus",
3166
- "application/pdf",
3167
- "text/csv"
3168
- ].join(","), gn = "image/jpeg,image/png,image/gif", _n = class {
3129
+ // src/widget/widget.ts
3130
+ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mpeg,audio/wav,audio/x-m4a,audio/aac,audio/opus,application/pdf,text/csv", gn = "image/jpeg,image/png,image/gif", _n = class {
3169
3131
  constructor(e, t) {
3170
3132
  this.stopViewportSync = null, this.pendingFiles = [], this.attachMenuOpen = !1, this.recorder = null, this.voicePreviewUrl = "", this.selectedCountry = zt, this.countryOpen = !1, this.isOpen = !1, this.destroyed = !1, this.position = e.position ?? "bottom-right", this.callbacks = t, this.autoOpen = e.autoOpen === !0, this.mount(e);
3171
3133
  }
@@ -4078,5 +4040,4 @@ var Dn = class {
4078
4040
  return $;
4079
4041
  }
4080
4042
  };
4081
- //#endregion
4082
4043
  export { s as ApiClient, Dn as ChatbotCore, c as DEFAULT_API_BASE_URL, n as DEFAULT_REQUEST_TIMEOUT_MS, fe as EventEmitter, On as OnedeskProChatbot, u as SDK_CHAT_MAX_ATTACHMENTS, l as SDK_UPLOAD_MAX_BYTES, Ot as SdkSocket, Mt as SessionManager, Nt as VOICE_MAX_DURATION_SECONDS, Y as VoiceRecorder, o as isChatbotRequestError, Dt as resolveSdkSocketUrl };
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@onedeskpro/chatbot-core",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Framework-independent core for the Onedesk Pro Chatbot SDK",
5
5
  "license": "MIT",
6
6
  "author": "Typetech IT <support@onedeskpro.com>",
7
- "homepage": "https://github.com/onedeskpro/onedeskpro-chatbot-sdk#readme",
7
+ "homepage": "https://github.com/onedeskpro/onedeskpro-chatbot#readme",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/onedeskpro/onedeskpro-chatbot-sdk.git",
10
+ "url": "git+https://github.com/onedeskpro/onedeskpro-chatbot.git",
11
11
  "directory": "packages/core"
12
12
  },
13
13
  "bugs": {
14
- "url": "https://github.com/onedeskpro/onedeskpro-chatbot-sdk/issues"
14
+ "url": "https://github.com/onedeskpro/onedeskpro-chatbot/issues"
15
15
  },
16
16
  "keywords": [
17
17
  "onedeskpro",
@@ -48,7 +48,7 @@
48
48
  "access": "public"
49
49
  },
50
50
  "dependencies": {
51
- "@onedeskpro/chatbot-types": "0.3.0",
51
+ "@onedeskpro/chatbot-types": "0.3.1",
52
52
  "socket.io-client": "^4.8.4"
53
53
  },
54
54
  "devDependencies": {
@@ -59,7 +59,7 @@
59
59
  "jsdom": "^30.1.3",
60
60
  "msw": "^3.0.3",
61
61
  "typescript": "^6",
62
- "vite": "^8.3.4",
62
+ "vite": "^8.3.5",
63
63
  "vite-plugin-dts": "^5.1.2",
64
64
  "vitest": "^5.0.5"
65
65
  },