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};(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();function n({connectError:e}={}){return`
    <div class="offlinescreen_screen">
      <div class="offlinescreen_status">Offline</div>
      <div class="offlinescreen_version">v0.0.2</div>
      <div class="offlinescreen_center">
        ${e?`<div class="offlinescreen_connect_error">${e}</div>`:``}
      </div>
      <div class="offlinescreen_bottom_nav">
        <button type="button" class="offlinescreen_nav_btn" data-offlinescreen-action="connect">Connect</button>
        <button type="button" class="offlinescreen_nav_btn">System</button>
        <button type="button" class="offlinescreen_nav_btn">Reboot</button>
        <button type="button" class="offlinescreen_nav_btn" data-offlinescreen-action="power-off">Power Off</button>
      </div>
    </div>
  `}function r(e,{onAction:t}){e.querySelectorAll(`[data-offlinescreen-action]`).forEach(e=>{e.addEventListener(`click`,()=>{t(e.dataset.offlinescreenAction)})})}function i(){return`
    <div class="onlinescreen_screen">
      <div class="onlinescreen_status">Online</div>
      <div class="onlinescreen_center">Connected....</div>
      <div class="onlinescreen_bottom_nav">
        <button type="button" class="onlinescreen_nav_btn" data-onlinescreen-action="disconnect">Disconnect</button>
        <button type="button" class="onlinescreen_nav_btn" data-onlinescreen-action="login-screen">Login</button>
        <button type="button" class="onlinescreen_nav_btn">System</button>
        <button type="button" class="onlinescreen_nav_btn">Reboot</button>
        <button type="button" class="onlinescreen_nav_btn" data-onlinescreen-action="power-off">Power Off</button>
      </div>
    </div>
  `}function a(e,{onAction:t}){e.querySelectorAll(`[data-onlinescreen-action]`).forEach(e=>{e.addEventListener(`click`,()=>{t(e.dataset.onlinescreenAction)})})}var o=Object.create(null);o.open=`0`,o.close=`1`,o.ping=`2`,o.pong=`3`,o.message=`4`,o.upgrade=`5`,o.noop=`6`;var s=Object.create(null);Object.keys(o).forEach(e=>{s[o[e]]=e});var c={type:`error`,data:`parser error`},l=typeof Blob==`function`||typeof Blob<`u`&&Object.prototype.toString.call(Blob)===`[object BlobConstructor]`,u=typeof ArrayBuffer==`function`,d=e=>typeof ArrayBuffer.isView==`function`?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,f=({type:e,data:t},n,r)=>l&&t instanceof Blob?n?r(t):p(t,r):u&&(t instanceof ArrayBuffer||d(t))?n?r(t):p(new Blob([t]),r):r(o[e]+(t||``)),p=(e,t)=>{let n=new FileReader;return n.onload=function(){let e=n.result.split(`,`)[1];t(`b`+(e||``))},n.readAsDataURL(e)};function m(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var ee;function te(e,t){if(l&&e.data instanceof Blob)return e.data.arrayBuffer().then(m).then(t);if(u&&(e.data instanceof ArrayBuffer||d(e.data)))return t(m(e.data));f(e,!1,e=>{ee||=new TextEncoder,t(ee.encode(e))})}var ne=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,h=typeof Uint8Array>`u`?[]:new Uint8Array(256);for(let e=0;e<64;e++)h[ne.charCodeAt(e)]=e;var re=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=h[e.charCodeAt(r)],o=h[e.charCodeAt(r+1)],s=h[e.charCodeAt(r+2)],c=h[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},ie=typeof ArrayBuffer==`function`,ae=(e,t)=>{if(typeof e!=`string`)return{type:`message`,data:se(e,t)};let n=e.charAt(0);return n===`b`?{type:`message`,data:oe(e.substring(1),t)}:s[n]?e.length>1?{type:s[n],data:e.substring(1)}:{type:s[n]}:c},oe=(e,t)=>ie?se(re(e),t):{base64:!0,data:e},se=(e,t)=>{switch(t){case`blob`:return e instanceof Blob?e:new Blob([e]);default:return e instanceof ArrayBuffer?e:e.buffer}},ce=``,le=(e,t)=>{let n=e.length,r=Array(n),i=0;e.forEach((e,a)=>{f(e,!1,e=>{r[a]=e,++i===n&&t(r.join(ce))})})},ue=(e,t)=>{let n=e.split(ce),r=[];for(let e=0;e<n.length;e++){let i=ae(n[e],t);if(r.push(i),i.type===`error`)break}return r};function de(){return new TransformStream({transform(e,t){te(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 fe;function pe(e){return e.reduce((e,t)=>e+t.length,0)}function me(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 he(e,t){fe||=new TextDecoder;let n=[],r=0,i=-1,a=!1;return new TransformStream({transform(o,s){for(n.push(o);;){if(r===0){if(pe(n)<1)break;let e=me(n,1);a=(e[0]&128)==128,i=e[0]&127,r=i<126?3:i===126?1:2}else if(r===1){if(pe(n)<2)break;let e=me(n,2);i=new DataView(e.buffer,e.byteOffset,e.length).getUint16(0),r=3}else if(r===2){if(pe(n)<8)break;let e=me(n,8),t=new DataView(e.buffer,e.byteOffset,e.length),a=t.getUint32(0);if(a>2**21-1){s.enqueue(c);break}i=a*2**32+t.getUint32(4),r=3}else{if(pe(n)<i)break;let e=me(n,i);s.enqueue(ae(a?e:fe.decode(e),t)),r=0}if(i===0||i>e){s.enqueue(c);break}}}})}function g(e){if(e)return ge(e)}function ge(e){for(var t in g.prototype)e[t]=g.prototype[t];return e}g.prototype.on=g.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks[`$`+e]=this._callbacks[`$`+e]||[]).push(t),this},g.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},g.prototype.off=g.prototype.removeListener=g.prototype.removeAllListeners=g.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},g.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},g.prototype.emitReserved=g.prototype.emit,g.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks[`$`+e]||[]},g.prototype.hasListeners=function(e){return!!this.listeners(e).length};var _e=typeof Promise==`function`&&typeof Promise.resolve==`function`?e=>Promise.resolve().then(e):(e,t)=>t(e,0),_=typeof self<`u`?self:typeof window<`u`?window:Function(`return this`)(),ve=`arraybuffer`;function ye(e,...t){return t.reduce((t,n)=>(e.hasOwnProperty(n)&&(t[n]=e[n]),t),{})}var be=_.setTimeout,xe=_.clearTimeout;function Se(e,t){t.useNativeTimers?(e.setTimeoutFn=be.bind(_),e.clearTimeoutFn=xe.bind(_)):(e.setTimeoutFn=_.setTimeout.bind(_),e.clearTimeoutFn=_.clearTimeout.bind(_))}var Ce=1.33;function we(e){return typeof e==`string`?Te(e):Math.ceil((e.byteLength||e.size)*Ce)}function Te(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 Ee(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function De(e){let t=``;for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+=`&`),t+=encodeURIComponent(n)+`=`+encodeURIComponent(e[n]));return t}function Oe(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 ke=class extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type=`TransportError`}},Ae=class extends g{constructor(e){super(),this.writable=!1,Se(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 ke(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=ae(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=De(e);return t.length?`?`+t:``}},je=class extends Ae{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){ue(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,le(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]=Ee()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}},Me=!1;try{Me=typeof XMLHttpRequest<`u`&&`withCredentials`in new XMLHttpRequest}catch{}var Ne=Me;function Pe(){}var Fe=class extends je{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}},Ie=class e extends g{constructor(e,t,n){super(),this.createRequest=e,Se(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=ye(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=Pe,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(Ie.requestsCount=0,Ie.requests={},typeof document<`u`){if(typeof attachEvent==`function`)attachEvent(`onunload`,Le);else if(typeof addEventListener==`function`){let e=`onpagehide`in _?`pagehide`:`unload`;addEventListener(e,Le,!1)}}function Le(){for(let e in Ie.requests)Ie.requests.hasOwnProperty(e)&&Ie.requests[e].abort()}var Re=(function(){let e=Be({xdomain:!1});return e&&e.responseType!==null})(),ze=class extends Fe{constructor(e){super(e);let t=e&&e.forceBase64;this.supportsBinary=Re&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new Ie(Be,this.uri(),e)}};function Be(e){let t=e.xdomain;try{if(typeof XMLHttpRequest<`u`&&(!t||Ne))return new XMLHttpRequest}catch{}if(!t)try{return new _[[`Active`,`Object`].join(`X`)](`Microsoft.XMLHTTP`)}catch{}}var Ve=typeof navigator<`u`&&typeof navigator.product==`string`&&navigator.product.toLowerCase()===`reactnative`,He=class extends Ae{get name(){return`websocket`}doOpen(){let e=this.uri(),t=this.opts.protocols,n=Ve?{}:ye(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;f(n,this.supportsBinary,e=>{try{this.doWrite(n,e)}catch{}r&&_e(()=>{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]=Ee()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}},Ue=_.WebSocket||_.MozWebSocket,We={websocket:class extends He{createSocket(e,t,n){return Ve?new Ue(e,t,n):t?new Ue(e,t):new Ue(e)}doWrite(e,t){this.ws.send(t)}},webtransport:class extends Ae{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=he(2**53-1,this.socket.binaryType),n=e.readable.pipeThrough(t).getReader(),r=de();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&&_e(()=>{this.writable=!0,this.emitReserved(`drain`)},this.setTimeoutFn)})}}doClose(){var e;(e=this._transport)==null||e.close()}},polling:ze},Ge=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Ke=[`source`,`protocol`,`authority`,`userInfo`,`user`,`password`,`host`,`port`,`relative`,`path`,`directory`,`file`,`query`,`anchor`];function qe(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=Ge.exec(e||``),a={},o=14;for(;o--;)a[Ke[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=Je(a,a.path),a.queryKey=Ye(a,a.query),a}function Je(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 Ye(e,t){let n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(e,t,r){t&&(n[t]=r)}),n}var Xe=typeof addEventListener==`function`&&typeof removeEventListener==`function`,Ze=[];Xe&&addEventListener(`offline`,()=>{Ze.forEach(e=>e())},!1);var Qe=class e extends g{constructor(e,t){if(super(),this.binaryType=ve,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=qe(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=qe(t.host).host);Se(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=Oe(this.opts.query)),Xe&&(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`})},Ze.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);break}}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+=we(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,_e(()=>{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(),Xe&&(this._beforeunloadEventListener&&removeEventListener(`beforeunload`,this._beforeunloadEventListener,!1),this._offlineEventListener)){let e=Ze.indexOf(this._offlineEventListener);e!==-1&&Ze.splice(e,1)}this.readyState=`closed`,this.id=null,this.emitReserved(`close`,e,t),this.writeBuffer=[],this._prevBufferLen=0}}};Qe.protocol=4;var $e=class extends Qe{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;Qe.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;Qe.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}},et=class extends $e{constructor(e,t={}){let n=typeof e==`object`?e:t;(!n.transports||n.transports&&typeof n.transports[0]==`string`)&&(n.transports=(n.transports||[`polling`,`websocket`,`webtransport`]).map(e=>We[e]).filter(e=>!!e)),super(e,n)}};et.protocol;function tt(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=qe(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 nt=typeof ArrayBuffer==`function`,rt=e=>typeof ArrayBuffer.isView==`function`?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,it=Object.prototype.toString,at=typeof Blob==`function`||typeof Blob<`u`&&it.call(Blob)===`[object BlobConstructor]`,ot=typeof File==`function`||typeof File<`u`&&it.call(File)===`[object FileConstructor]`;function st(e){return nt&&(e instanceof ArrayBuffer||rt(e))||at&&e instanceof Blob||ot&&e instanceof File}function ct(e,t){if(!e||typeof e!=`object`)return!1;if(Array.isArray(e)){for(let t=0,n=e.length;t<n;t++)if(ct(e[t]))return!0;return!1}if(st(e))return!0;if(e.toJSON&&typeof e.toJSON==`function`&&arguments.length===1)return ct(e.toJSON(),!0);for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t)&&ct(e[t]))return!0;return!1}function lt(e){let t=[],n=e.data,r=e;return r.data=ut(n,t),r.attachments=t.length,{packet:r,buffers:t}}function ut(e,t){if(!e)return e;if(st(e)){let n={_placeholder:!0,num:t.length};return t.push(e),n}else if(Array.isArray(e)){let n=Array(e.length);for(let r=0;r<e.length;r++)n[r]=ut(e[r],t);return n}else if(typeof e==`object`&&!(e instanceof Date)){let n={};for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=ut(e[r],t));return n}return e}function dt(e,t){return e.data=ft(e.data,t),delete e.attachments,e}function ft(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`)}else if(Array.isArray(e))for(let n=0;n<e.length;n++)e[n]=ft(e[n],t);else if(typeof e==`object`)for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(e[n]=ft(e[n],t));return e}var pt=t({Decoder:()=>gt,Encoder:()=>ht,PacketType:()=>v,isPacketValid:()=>Ct,protocol:()=>5}),mt=[`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 ht=class{constructor(e){this.replacer=e}encode(e){return(e.type===v.EVENT||e.type===v.ACK)&&ct(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=lt(e),n=this.encodeAsString(t.packet),r=t.buffers;return r.unshift(n),r}},gt=class e extends g{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 _t(t),t.attachments===0&&super.emitReserved(`decoded`,t)):super.emitReserved(`decoded`,t)}else if(st(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(!yt(a)||a<0)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 xt(t);case v.DISCONNECT:return t===void 0;case v.CONNECT_ERROR:return typeof t==`string`||xt(t);case v.EVENT:case v.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]==`number`||typeof t[0]==`string`&&mt.indexOf(t[0])===-1);case v.ACK:case v.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&=(this.reconstructor.finishedReconstruction(),null)}},_t=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=dt(this.reconPack,this.buffers);return this.finishedReconstruction(),e}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};function vt(e){return typeof e==`string`}var yt=Number.isInteger||function(e){return typeof e==`number`&&isFinite(e)&&Math.floor(e)===e};function bt(e){return e===void 0||yt(e)}function xt(e){return Object.prototype.toString.call(e)===`[object Object]`}function St(e,t){switch(e){case v.CONNECT:return t===void 0||xt(t);case v.DISCONNECT:return t===void 0;case v.EVENT:return Array.isArray(t)&&(typeof t[0]==`number`||typeof t[0]==`string`&&mt.indexOf(t[0])===-1);case v.ACK:return Array.isArray(t);case v.CONNECT_ERROR:return typeof t==`string`||xt(t);default:return!1}}function Ct(e){return vt(e.nsp)&&bt(e.id)&&St(e.type,e.data)}function y(e,t,n){return e.on(t,n),function(){e.off(t,n)}}var wt=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),Tt=class extends g{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=[y(e,`open`,this.onopen.bind(this)),y(e,`packet`,this.onpacket.bind(this)),y(e,`error`,this.onerror.bind(this)),y(e,`close`,this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState===`open`&&this.onopen(),this)}open(){return this.connect()}send(...e){return e.unshift(`message`),this.emit.apply(this,e),this}emit(e,...t){if(wt.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);break}}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 Et(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}Et.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},Et.prototype.reset=function(){this.attempts=0},Et.prototype.setMin=function(e){this.ms=e},Et.prototype.setMax=function(e){this.max=e},Et.prototype.setJitter=function(e){this.jitter=e};var Dt=class extends g{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,Se(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 Et({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||pt;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 et(this.uri,this.opts);let t=this.engine,n=this;this._readyState=`opening`,this.skipReconnect=!1;let r=y(t,`open`,function(){n.onopen(),e&&e()}),i=t=>{this.cleanup(),this._readyState=`closed`,this.emitReserved(`error`,t),e?e(t):this.maybeReconnectOnOpen()},a=y(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(y(e,`ping`,this.onping.bind(this)),y(e,`data`,this.ondata.bind(this)),y(e,`error`,this.onerror.bind(this)),y(e,`close`,this.onclose.bind(this)),y(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){_e(()=>{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 Tt(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)}},Ot={};function kt(e,t){typeof e==`object`&&(t=e,e=void 0),t||={};let n=tt(e,t.path||`/socket.io`),r=n.source,i=n.id,a=n.path,o=Ot[i]&&a in Ot[i].nsps,s=t.forceNew||t[`force new connection`]||!1===t.multiplex||o,c;return s?c=new Dt(r,t):(Ot[i]||(Ot[i]=new Dt(r,t)),c=Ot[i]),n.query&&!t.query&&(t.query=n.queryKey),c.socket(n.path,t)}Object.assign(kt,{Manager:Dt,Socket:Tt,io:kt,connect:kt});var At=`[delux_socket_client]`,b=null;function jt(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(jt);let t={};for(let[n,r]of Object.entries(e))/password|passwd|pwd|secret|token|authorization/i.test(n)?t[n]=r!=null&&String(r).length>0?`***`:r:typeof r==`object`&&r?t[n]=jt(r):t[n]=r;return t}function x(e,t,n){let r=jt(n),i=r===void 0?``:` ${JSON.stringify(r)}`;console.log(`${At} ${e} evt=${t}${i}`)}function Mt(e){if(e)try{e.disconnect()}catch{}}function Nt(e){e.onAny((e,...t)=>{x(`IN`,e,t.length===0?void 0:t.length===1?t[0]:t)}),e.on(`connect`,()=>{x(`CONN`,`socket_connect`,{id:e.id})}),e.on(`disconnect`,e=>{x(`DISC`,`socket_disconnect`,{reason:e})}),e.on(`connect_error`,e=>{x(`ERR`,`socket_connect_error`,{message:e?.message})})}function Pt(){return`http://68.178.166.16:5677`}function Ft(){return Pt()}async function It(){let e=Pt();return b?.connected?b:(b&&=(Mt(b),null),x(`OPEN`,`io`,{url:e}),b=kt(e,{transports:[`websocket`,`polling`],reconnection:!0,reconnectionAttempts:10,reconnectionDelay:1e3}),Nt(b),new Promise((e,t)=>{let n=setTimeout(()=>{t(Error(`CONNECT_TIMEOUT`))},15e3);b.once(`connect`,()=>{clearTimeout(n),e(b)}),b.once(`connect_error`,e=>{clearTimeout(n),Mt(b),b=null,t(e)})}))}function Lt(){b&&=(x(`CLOSE`,`disconnectDeluxSocket`,{}),Mt(b),null)}async function Rt(e,t){return b?.connected?(x(`OUT`,`delux_login`,{userCode:e,password:t}),new Promise(n=>{let r=setTimeout(()=>{b.off(`delux_login_response`,i),x(`ERR`,`delux_login_timeout`,{error:`TIMEOUT`}),n({ok:!1,error:`TIMEOUT`})},15e3);function i(e){clearTimeout(r),n(e)}b.once(`delux_login_response`,i),b.emit(`delux_login`,{userCode:e,password:t})})):(x(`SKIP`,`delux_login`,{ok:!1,error:`NOT_CONNECTED`}),{ok:!1,error:`NOT_CONNECTED`})}async function zt(e,t,n){return b?.connected?(x(`OUT`,`delux_place_bet`,{userCode:e,drawTime:t,betListArray:n}),new Promise(r=>{let i=setTimeout(()=>{b.off(`delux_place_bet_response`,a),x(`ERR`,`delux_place_bet_timeout`,{error:`TIMEOUT`}),r({ok:!1,error:`TIMEOUT`})},15e3);function a(e){clearTimeout(i),r(e)}b.once(`delux_place_bet_response`,a),b.emit(`delux_place_bet`,{userCode:e,drawTime:t,mainbetarray:n})})):(x(`SKIP`,`delux_place_bet`,{ok:!1,error:`NOT_CONNECTED`}),{ok:!1,error:`NOT_CONNECTED`})}async function Bt(e){return b?.connected?(x(`OUT`,`delux_get_balance`,{userCode:e}),new Promise(t=>{let n=setTimeout(()=>{b.off(`delux_get_balance_response`,r),x(`ERR`,`delux_get_balance_timeout`,{error:`TIMEOUT`}),t({ok:!1,error:`TIMEOUT`})},15e3);function r(e){clearTimeout(n),t(e)}b.once(`delux_get_balance_response`,r),b.emit(`delux_get_balance`,{userCode:e})})):(x(`SKIP`,`delux_get_balance`,{ok:!1,error:`NOT_CONNECTED`}),{ok:!1,error:`NOT_CONNECTED`})}async function Vt(e,t){if(!b?.connected)return x(`SKIP`,`delux_get_result_history`,{ok:!1,error:`NOT_CONNECTED`}),{ok:!1,error:`NOT_CONNECTED`};let n={userCode:e};return t!=null&&String(t).trim()!==``&&(n.lotdate=String(t).trim()),x(`OUT`,`delux_get_result_history`,n),new Promise(e=>{let t=setTimeout(()=>{b.off(`delux_get_result_history_response`,r),x(`ERR`,`delux_get_result_history_timeout`,{error:`TIMEOUT`}),e({ok:!1,error:`TIMEOUT`})},15e3);function r(n){clearTimeout(t),e(n)}b.once(`delux_get_result_history_response`,r),b.emit(`delux_get_result_history`,n)})}async function Ht(){return b?.connected?(x(`OUT`,`delux_get_winning_number`,{}),new Promise(e=>{let t=setTimeout(()=>{b.off(`delux_get_winning_number_response`,n),x(`ERR`,`delux_get_winning_number_timeout`,{error:`TIMEOUT`}),e({ok:!1,error:`TIMEOUT`})},15e3);function n(n){clearTimeout(t),e(n)}b.once(`delux_get_winning_number_response`,n),b.emit(`delux_get_winning_number`,{})})):(x(`SKIP`,`delux_get_winning_number`,{ok:!1,error:`NOT_CONNECTED`}),{ok:!1,error:`NOT_CONNECTED`})}async function Ut(e){if(!b?.connected)return x(`SKIP`,`delux_get_last_bet_receipt`,{ok:!1,error:`NOT_CONNECTED`}),{ok:!1,error:`NOT_CONNECTED`};let t=e==null?``:String(e).trim();return t?(x(`OUT`,`delux_get_last_bet_receipt`,{userCode:t}),new Promise(e=>{let n=setTimeout(()=>{b.off(`delux_get_last_bet_receipt_response`,r),x(`ERR`,`delux_get_last_bet_receipt_timeout`,{error:`TIMEOUT`}),e({ok:!1,error:`TIMEOUT`})},15e3);function r(t){clearTimeout(n),e(t)}b.once(`delux_get_last_bet_receipt_response`,r),b.emit(`delux_get_last_bet_receipt`,{userCode:t})})):(x(`SKIP`,`delux_get_last_bet_receipt`,{ok:!1,error:`MISSING_FIELDS`}),{ok:!1,error:`MISSING_FIELDS`})}async function Wt(e,t={}){if(!b?.connected)return x(`SKIP`,`delux_get_user_tickets`,{ok:!1,error:`NOT_CONNECTED`}),{ok:!1,error:`NOT_CONNECTED`};let n=typeof t==`object`&&t&&!Array.isArray(t)?{...t}:{},r=e==null?``:String(e).trim();if(r)n.userCode=r,delete n.regid;else if(n.regid!=null&&n.regid!==``){let e=Number(n.regid);n.regid=Number.isFinite(e)?e:n.regid}if(!n.userCode&&(n.regid==null||n.regid===``))return x(`SKIP`,`delux_get_user_tickets`,{ok:!1,error:`MISSING_FIELDS`}),{ok:!1,error:`MISSING_FIELDS`};let i=n;return x(`OUT`,`delux_get_user_tickets`,i),new Promise(e=>{let t=setTimeout(()=>{b.off(`delux_get_user_tickets_response`,n),x(`ERR`,`delux_get_user_tickets_timeout`,{error:`TIMEOUT`}),e({ok:!1,error:`TIMEOUT`})},3e4);function n(n){clearTimeout(t),e(n)}b.once(`delux_get_user_tickets_response`,n),b.emit(`delux_get_user_tickets`,i)})}async function Gt(e,t){let n=Ft();try{let r=await fetch(`${n}/api/tickets/single-detail`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({userCode:e,barcode:t})}),i=await r.json().catch(()=>({}));return r.status===404?{ok:!1,error:`NOT_FOUND`,...i}:r.ok?i:{ok:!1,error:i.error||`HTTP_${r.status}`,...i}}catch{return{ok:!1,error:`NETWORK_ERROR`}}}async function Kt(e,t){let n=Ft();try{let r=await fetch(`${n}/api/tickets/cancel`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({userCode:e,barcode:t})}),i=await r.json().catch(()=>({}));return r.ok?i:{ok:!1,error:i.error||`HTTP_${r.status}`,...i}}catch{return{ok:!1,error:`NETWORK_ERROR`}}}async function qt(e,t){return b?.connected?(x(`OUT`,`delux_check_user_winning`,{userCode:e,lottime:t}),new Promise(n=>{let r=setTimeout(()=>{b.off(`delux_check_user_winning_response`,i),x(`ERR`,`delux_check_user_winning_timeout`,{error:`TIMEOUT`}),n({ok:!1,error:`TIMEOUT`})},15e3);function i(e){clearTimeout(r),n(e)}b.once(`delux_check_user_winning_response`,i),b.emit(`delux_check_user_winning`,{userCode:e,lottime:t})})):(x(`SKIP`,`delux_check_user_winning`,{ok:!1,error:`NOT_CONNECTED`}),{ok:!1,error:`NOT_CONNECTED`})}function Jt(){return{exists:!!b,connected:b?.connected||!1,id:b?.id||null}}var S=`Asia/Kolkata`,Yt=[`JAN`,`FEB`,`MAR`,`APR`,`MAY`,`JUN`,`JUL`,`AUG`,`SEP`,`OCT`,`NOV`,`DEC`],Xt=null;function Zt(e){return e&&e.utcMs!=null&&Number.isFinite(Number(e.utcMs))?(Xt=Number(e.utcMs),!0):!1}function Qt(){return Xt}function $t(){return Xt==null?null:new Date(Xt)}function en(){let e=$t();return e?new Date(e.getTime()):new Date(0)}function C(e,t){let n=new Intl.DateTimeFormat(`en-CA`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hourCycle:`h23`}).formatToParts(e),r={};for(let e of n)e.type!==`literal`&&(r[e.type]=e.value);return{year:Number(r.year),month:Number(r.month),day:Number(r.day),hour:Number(r.hour),minute:Number(r.minute),second:Number(r.second)}}function tn(e,t,n,r,i,a){let o=e=>String(e).padStart(2,`0`);return new Date(`${e}-${o(t)}-${o(n)}T${o(r)}:${o(i)}:${o(a)}+05:30`)}function nn(e){let t=C(e,S);return{date:`${Yt[t.month-1]} ${t.day} ${t.year}`,time:`${String(t.hour).padStart(2,`0`)}:${String(t.minute).padStart(2,`0`)}:${String(t.second).padStart(2,`0`)}`}}function rn(e){if(!e||typeof e!=`string`)return``;let t=e.trim().split(`:`);if(t.length<2)return``;let n=Number(t[0]),r=Number(t[1]);if(!Number.isFinite(n)||!Number.isFinite(r))return``;let i=n>=12?`PM`:`AM`,a=(n+11)%12+1;return`${String(a).padStart(2,`0`)}:${String(r).padStart(2,`0`)} ${i}`}var an=null;function on(){an&&=(clearInterval(an),null)}function sn({pin:e,password:t,loginError:n}){return`
    <div class="loginscreen_screen">
      <div class="loginscreen_marquee_outer" aria-hidden="true">
        <div class="loginscreen_marquee_inner">
          <span class="loginscreen_marquee_text">welcome.. to northen delux.</span>
        </div>
      </div>
      <div class="loginscreen_date_chip">
        <div class="loginscreen_date_chip_title" id="loginscreen_server_date">—</div>
        <div class="loginscreen_date_chip_time" id="loginscreen_server_time">—:—:—</div>
      </div>
      <div class="loginscreen_form">
        ${n?`<div class="loginscreen_error">contact admin for login</div>`:``}
        <div class="loginscreen_field_row">
          <label for="loginscreen_pin">Pin Number</label>
          <input id="loginscreen_pin" value="${e}" />
        </div>
        <div class="loginscreen_field_row">
          <label for="loginscreen_password">Password</label>
          <input id="loginscreen_password" type="password" value="${t}" />
        </div>
        <div class="loginscreen_form_actions">
          <button type="button" class="loginscreen_mini_btn" data-loginscreen-action="enter-dashboard">Enter</button>
          <button type="button" class="loginscreen_mini_btn" data-loginscreen-action="back-to-connect">Back</button>
        </div>
      </div>
    </div>
  `}function cn(e,{onAction:t,onPinInput:n,onPasswordInput:r}){let i=Ft(),a=e.querySelector(`#loginscreen_server_date`),o=e.querySelector(`#loginscreen_server_time`);async function s(){try{let e=await fetch(`${i}/api/time`,{cache:`no-store`});if(!e.ok)return;let t=await e.json();t.utcMs!=null&&Zt(t),a&&t.date&&(a.textContent=t.date),o&&t.time&&(o.textContent=t.time)}catch{a&&(a.textContent=`—`),o&&(o.textContent=`—:—:—`)}}s(),an=setInterval(s,1e3),e.querySelectorAll(`[data-loginscreen-action]`).forEach(e=>{e.addEventListener(`click`,()=>{t(e.dataset.loginscreenAction)})});let c=e.querySelector(`#loginscreen_pin`),l=e.querySelector(`#loginscreen_password`);c&&c.addEventListener(`input`,e=>{n(e.target.value)}),l&&l.addEventListener(`input`,e=>{r(e.target.value)})}var ln=class{constructor(e={}){this.options={onClose:()=>{},...e},this.element=null,this.isVisible=!1}create(e){let t=document.createElement(`div`);t.className=`popup_overlay`,t.innerHTML=`
      <div class="popup_container">
        <div class="popup_content">
          <div class="popup_body">
            ${e}
          </div>
        </div>
      </div>
    `,t.addEventListener(`click`,e=>{e.target===t&&this.hide()});let n=e=>{e.key===`Escape`&&this.isVisible&&this.hide()};return document.addEventListener(`keydown`,n),this.element=t,this.escapeHandler=n,t}show(){this.element&&(this.isVisible=!0,this.element.classList.add(`popup_overlay--visible`),document.body.style.overflow=`hidden`)}hide(){this.element&&(this.isVisible=!1,this.element.classList.remove(`popup_overlay--visible`),document.body.style.overflow=``,this.options.onClose())}mount(e){this.element&&e.appendChild(this.element)}destroy(){this.element&&this.element.parentNode&&this.element.parentNode.removeChild(this.element),document.removeEventListener(`keydown`,this.escapeHandler),this.element=null}};function w(e){return e==null?``:String(e).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/"/g,`&quot;`)}var un=[`Barcode`,`Game ID`,`Start Point`,`Play`,`Win`,`End Point`,`Claim`,`Result`,`Draw Time`,`Ticket Time`],dn=[{label:`AllClaim`,action:`allclaim`},{label:`Claim`,action:`claim`},{label:`Cancel`,action:`cancel`},{label:`Details`,action:`details`},{label:`Close`,action:`close`},{label:`Reprint`,action:`reprint`}];function fn({onAction:e}){return`
    <div class="sh_wrapper">
      <div class="sh_table_section">
        <table class="sh_table">
          <thead class="sh_table_head">
            <tr>${un.map(e=>`<th class="sh_table_header">${e}</th>`).join(``)}</tr>
          </thead>
          <tbody class="sh_table_body sh_tickets_tbody"></tbody>
        </table>
      </div>
      <div class="sh_sidebar">
        <div class="sh_buttons">
          ${dn.map(e=>{let t=e.action===`allclaim`||e.action===`claim`?` disabled`:``;return`<button type="button" class="sh_sidebar_btn" data-action="${e.action}"${t}>${e.label}</button>`}).join(``)}
        </div>
        <div class="sh_filters">
          <label class="sh_checkbox_label">
            <input type="checkbox" class="sh_checkbox" id="sh_show_all" />
            <span>Show All Tickets</span>
          </label>
          <label class="sh_checkbox_label">
            <input type="checkbox" class="sh_checkbox" id="sh_winning_only" />
            <span>Show Winning Tickets Only</span>
          </label>
        </div>
        <button type="button" class="sh_result_btn" data-action="result">Result</button>
      </div>
    </div>
  `}function pn(e,{onAction:t,isBetLocked:n}){e.querySelectorAll(`[data-action]`).forEach(e=>{e.addEventListener(`click`,()=>{let n=e.dataset.action;t&&t(n)})});let r=e.querySelector(`tbody.sh_tickets_tbody`);r&&t&&!r.dataset.shRowBound&&(r.dataset.shRowBound=`1`,r.addEventListener(`click`,e=>{let i=e.target.closest(`tr.sh_table_row`);if(!i||typeof n==`function`&&n())return;let a=i.getAttribute(`data-ticket-id`)||``,o=i.getAttribute(`data-barcode`)||``;r.querySelectorAll(`tr.sh_table_row`).forEach(e=>e.classList.remove(`sh_table_row--selected`)),i.classList.add(`sh_table_row--selected`),t(`select`,{ticketId:a,barcode:o})}));let i=e.querySelector(`#sh_show_all`),a=e.querySelector(`#sh_winning_only`);i&&!i.dataset.shFilterBound&&(i.dataset.shFilterBound=`1`,i.addEventListener(`change`,e=>{t&&t(`filter`,{showAll:e.target.checked,winningOnly:a?.checked})})),a&&!a.dataset.shFilterBound&&(a.dataset.shFilterBound=`1`,a.addEventListener(`change`,e=>{t&&t(`filter`,{showAll:i?.checked,winningOnly:e.target.checked})}))}function mn(e,t){let n=e.querySelector(`tbody.sh_tickets_tbody`);if(n){if(!t){n.innerHTML=``;return}n.innerHTML=`<tr class="sh_placeholder_row"><td class="sh_table_cell sh_placeholder_cell" colspan="10">${w(t)}</td></tr>`}}function hn(e,t){let n=e.querySelector(`tbody.sh_tickets_tbody`);n&&(n.innerHTML=(Array.isArray(t)?t:[]).map(e=>`
    <tr class="sh_table_row" data-ticket-id="${w(e.ticketId)}" data-barcode="${w(e.barcode)}">
      <td class="sh_table_cell">${w(e.barcode)}</td>
      <td class="sh_table_cell">${w(e.gameId)}</td>
      <td class="sh_table_cell">${w(e.startPoint)}</td>
      <td class="sh_table_cell">${w(e.play)}</td>
      <td class="sh_table_cell">${w(e.win)}</td>
      <td class="sh_table_cell">${w(e.endPoint)}</td>
      <td class="sh_table_cell">${w(e.claim)}</td>
      <td class="sh_table_cell">${w(e.result)}</td>
      <td class="sh_table_cell">${w(e.drawTime)}</td>
      <td class="sh_table_cell">${w(e.ticketTime)}</td>
    </tr>
  `).join(``))}var gn=class{constructor(){let e=en();this.currentDate=new Date(e.getTime()),this.selectedDate=new Date(e.getTime()),this.isVisible=!1,this.targetInput=null,this.calendarElement=null}show(e){this.targetInput=e,this.selectedDate=this.parseInputDate(e.value)||en(),this.currentDate=new Date(this.selectedDate.getTime()),this.calendarElement||this.createCalendar(),this.updateCalendar(),this.positionCalendar(e),this.calendarElement.style.display=`block`,this.isVisible=!0}hide(){this.calendarElement&&(this.calendarElement.style.display=`none`),this.isVisible=!1,this.targetInput=null}parseInputDate(e){if(!e)return null;let t=e.split(`/`);if(t.length===3){let e=parseInt(t[0],10),n=parseInt(t[1],10)-1,r=parseInt(t[2],10);return new Date(r,n,e)}return null}formatDate(e){return`${String(e.getDate()).padStart(2,`0`)}/${String(e.getMonth()+1).padStart(2,`0`)}/${e.getFullYear()}`}createCalendar(){this.calendarElement=document.createElement(`div`),this.calendarElement.className=`rf_calendar`,this.calendarElement.innerHTML=`
      <div class="rf_calendar_header">
        <button type="button" class="rf_calendar_nav" data-nav="prev-month">◀</button>
        <span class="rf_calendar_month"></span>
        <button type="button" class="rf_calendar_nav" data-nav="next-month">▶</button>
      </div>
      <div class="rf_calendar_weekdays">
        <div class="rf_calendar_weekday">S</div>
        <div class="rf_calendar_weekday">M</div>
        <div class="rf_calendar_weekday">T</div>
        <div class="rf_calendar_weekday">W</div>
        <div class="rf_calendar_weekday">T</div>
        <div class="rf_calendar_weekday">F</div>
        <div class="rf_calendar_weekday">S</div>
      </div>
      <div class="rf_calendar_days"></div>
      <div class="rf_calendar_actions">
        <button type="button" class="rf_calendar_btn rf_calendar_btn--close">Close</button>
        <button type="button" class="rf_calendar_btn rf_calendar_btn--apply">Apply</button>
      </div>
    `,this.calendarElement.addEventListener(`click`,e=>{let t=e.target.dataset.nav;if(t===`prev-month`)this.currentDate.setMonth(this.currentDate.getMonth()-1),this.updateCalendar();else if(t===`next-month`)this.currentDate.setMonth(this.currentDate.getMonth()+1),this.updateCalendar();else if(e.target.classList.contains(`rf_calendar_day`)){let t=parseInt(e.target.textContent,10);isNaN(t)||(this.selectedDate=new Date(this.currentDate.getFullYear(),this.currentDate.getMonth(),t),this.selectDate())}else e.target.classList.contains(`rf_calendar_btn--apply`)?this.selectDate():e.target.classList.contains(`rf_calendar_btn--close`)&&this.hide()}),document.body.appendChild(this.calendarElement)}updateCalendar(){let e=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],t=this.calendarElement.querySelector(`.rf_calendar_month`);t.textContent=`${e[this.currentDate.getMonth()]} ${this.currentDate.getFullYear()}`;let n=this.calendarElement.querySelector(`.rf_calendar_days`);n.innerHTML=``;let r=new Date(this.currentDate.getFullYear(),this.currentDate.getMonth(),1);new Date(this.currentDate.getFullYear(),this.currentDate.getMonth()+1,0);let i=new Date(r);i.setDate(i.getDate()-r.getDay());for(let e=0;e<42;e++){let t=new Date(i);t.setDate(i.getDate()+e);let r=document.createElement(`div`);r.className=`rf_calendar_day`,r.textContent=t.getDate(),t.getMonth()!==this.currentDate.getMonth()&&r.classList.add(`rf_calendar_day--other-month`),this.selectedDate&&t.getDate()===this.selectedDate.getDate()&&t.getMonth()===this.selectedDate.getMonth()&&t.getFullYear()===this.selectedDate.getFullYear()&&r.classList.add(`rf_calendar_day--selected`);let a=$t(),o=a?C(a,S):null;if(o){let e=C(t,S);e.year===o.year&&e.month===o.month&&e.day===o.day&&r.classList.add(`rf_calendar_day--today`)}n.appendChild(r)}}positionCalendar(e){let t=e.getBoundingClientRect();this.calendarElement.style.position=`absolute`,this.calendarElement.style.top=`${t.bottom+window.scrollY+5}px`,this.calendarElement.style.left=`${t.left+window.scrollX}px`,this.calendarElement.style.zIndex=`10000`}selectDate(){this.targetInput&&(this.targetInput.value=this.formatDate(this.selectedDate)),this.hide()}destroy(){this.calendarElement&&=(document.body.removeChild(this.calendarElement),null)}},T=null,_n=[`From Date`,`To Date`,`Sale Point`,`Win Point`,`Commission Point`,`NTP Point`,`Operator Point`];function vn({onAction:e}){return`
    <div class="rf_wrapper">
      <div class="rf_header">
        <div class="rf_date_section">
          <span class="rf_label">Report From</span>
          <div class="rf_date_input_container">
          <input type="text" class="rf_date_input" id="rf_from_date" value="08/04/2026" readonly />
          <button type="button" class="rf_calendar_btn" data-action="calendar-from">📅</button>
          </div>
          <span class="rf_label">To</span>
          <div class="rf_date_input_container">
          <input type="text" class="rf_date_input" id="rf_to_date" value="08/04/2026" readonly />
          <button type="button" class="rf_calendar_btn" data-action="calendar-to">📅</button>
          </div>
        </div>
        <div class="rf_actions">
          <button type="button" class="rf_action_btn" data-action="show">Show</button>
          <button type="button" class="rf_action_btn" data-action="print">Print</button>
          <button type="button" class="rf_action_btn" data-action="close">Close</button>
        </div>
      </div>
      <div class="rf_table_section">
        <table class="rf_table">
          <thead class="rf_table_head">
            <tr>${_n.map(e=>`<th class="rf_table_header">${e}</th>`).join(``)}</tr>
          </thead>
          <tbody class="rf_table_body" id="rf_table_body">
            <!-- Table rows will be populated dynamically -->
          </tbody>
        </table>
      </div>
    </div>
  `}function yn(e,{onAction:t}){T||=new gn,e.querySelectorAll(`[data-action]`).forEach(n=>{n.addEventListener(`click`,()=>{let r=n.dataset.action;if(r===`calendar-from`){let t=e.querySelector(`#rf_from_date`);t&&T.show(t)}else if(r===`calendar-to`){let t=e.querySelector(`#rf_to_date`);t&&T.show(t)}else t&&(r===`show`||r===`print`||r===`close`)&&t(r)})}),document.addEventListener(`click`,e=>{T&&T.isVisible&&!T.calendarElement.contains(e.target)&&!e.target.classList.contains(`rf_calendar_btn`)&&T.hide()})}function bn(){T&&=(T.destroy(),null)}var xn=new URL(``+new URL(`btn2-TQ6WoDI6.wav`,import.meta.url).href,``+import.meta.url).href,Sn=new URL(``+new URL(`numberspinner-CA5xOemr.mp3`,import.meta.url).href,``+import.meta.url).href,Cn=new URL(``+new URL(`nomorebetplease-C12XxtAo.wav`,import.meta.url).href,``+import.meta.url).href,E=null,wn=!1;function Tn(){new Audio(xn).play().catch(()=>{})}function En(e){e?(E||=new Audio(Sn),E.loop=!0,E.currentTime=0,E.play().catch(()=>{})):E&&(E.pause(),E.currentTime=0)}function Dn(){new Audio(Cn).play().catch(()=>{})}function On(e){e===`BETTING_LOCKED`&&Dn()}function kn(){wn||(wn=!0,document.addEventListener(`click`,e=>{let t=e.target;t instanceof Element&&t.closest(`button`)&&Tn()},!0))}function An(e){if(!e||typeof e!=`string`)return`PR`;let t=e.replace(/\s*(AM|PM)\s*$/i,``).split(`:`);if(t.length>=2){let e=Number(t[1]);if(Number.isFinite(e))return e%2==0?`PR`:`NR`}return`PR`}function jn(e){return`${An(e)} 00`}function Mn({onAction:e,data:t,reveal:n}){let r=t?.date||`—`,i=t?.time||`—`,a=t?.drawTime||i,o=t?.result||`NR 22`,s=t?.drawType||`MINOR NR`,c=!!n,l=c?`flex`:`none`,u=c?`none`:`block`,d=c?``:o;return`
    <div class="lp_container">
      <button type="button" class="lp_close_btn" data-action="close">&times;</button>
        <div class="lp_header">
          <h1 class="lp_title">Northern Deluxe</h1>
          <div class="lp_info">
          <span class="lp_date" id="lp_date">${r}</span>
          <span class="lp_time" id="lp_time">${i}</span>
        </div>
      </div>
      <div class="lp_content">
        <div class="lp_draw_info">
          <span class="lp_draw_type" id="lp_draw_type">${s}</span>
          <span class="lp_draw_time" id="lp_draw_time">${a}</span>
        </div>
        <div class="lp_result_box lp_result_box--reveal">
          <div class="lp_reveal_phase" id="lp_reveal_phase" style="display: ${l}">
            <div class="lp_spin_number" id="lp_spin_number">${c?jn(a):``}</div>
          </div>
          <div class="lp_final_phase" id="lp_final_phase" style="display: ${u}">
            <span class="lp_result_text" id="lp_result_text">${d}</span>
          </div>
        </div>
      </div>
    </div>
  `}function Nn(e,t,n,r,i=null){if(!e)return;e._lpRevealInterval&&=(clearInterval(e._lpRevealInterval),null),e._lpRevealTimer&&=(clearTimeout(e._lpRevealTimer),null);let a=e.querySelector(`#lp_reveal_phase`),o=e.querySelector(`#lp_final_phase`),s=e.querySelector(`#lp_spin_number`),c=e.querySelector(`#lp_result_text`);if(!a||!o||!s||!c){typeof r==`function`&&r();return}a.style.display=`flex`,o.style.display=`none`,o.classList.remove(`lp_final_phase--show`);let l=An(i);En(!0),e._lpRevealInterval=setInterval(()=>{s.textContent=`${l} ${String(Math.floor(Math.random()*100)).padStart(2,`0`)}`},65),e._lpRevealTimer=setTimeout(()=>{e._lpRevealInterval&&=(clearInterval(e._lpRevealInterval),null),e._lpRevealTimer=null,En(!1),a.style.display=`none`,c.textContent=t!=null&&String(t).length>0?String(t):`—`,o.style.display=`block`,o.classList.add(`lp_final_phase--show`),typeof r==`function`&&r()},n)}function D(e){e&&(En(!1),e._lpRevealInterval&&=(clearInterval(e._lpRevealInterval),null),e._lpRevealTimer&&=(clearTimeout(e._lpRevealTimer),null))}function Pn(e,{onAction:t}){let n=e.querySelector(`[data-action="close"]`);n&&n.addEventListener(`click`,()=>{D(e),t&&t(`close`)});let r=n=>{n.key===`Escape`&&(D(e),t&&t(`close`),document.removeEventListener(`keydown`,r))};document.addEventListener(`keydown`,r)}function Fn(e){return e==null?``:String(e).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/"/g,`&quot;`)}var O=null;function In(e,t,n,r){if(O){let e=O.element.querySelector(`.popup_body`);e&&(e.innerHTML=Ln(t,{onAction:(e,t)=>{console.log(`Upcoming draw action:`,e,t),e===`close`||e===`cancel`?O.hide():e===`confirm`?(console.log(`Selected times:`,t.selectedTimes),r&&typeof r==`function`&&r(t.selectedTimes),O.hide()):e===`select-all`?k(O.element,!0):e===`unselect-all`&&k(O.element,!1)}}),Rn(e,{onAction:(e,t)=>{console.log(`Upcoming draw action:`,e,t),e===`close`||e===`cancel`?O.hide():e===`confirm`?(console.log(`Selected times:`,t.selectedTimes),r&&typeof r==`function`&&r(t.selectedTimes),O.hide()):e===`select-all`?k(O.element,!0):e===`unselect-all`&&k(O.element,!1)}}))}else{let e=Ln(t,{onAction:(e,t)=>{console.log(`Upcoming draw action:`,e,t),e===`close`||e===`cancel`?O.hide():e===`confirm`?(console.log(`Selected times:`,t.selectedTimes),r&&typeof r==`function`&&r(t.selectedTimes),O.hide()):e===`select-all`?k(O.element,!0):e===`unselect-all`&&k(O.element,!1)}});O=new ln({onClose:()=>{console.log(`Upcoming draw popup closed`)}}),O.create(e),Rn(O.element.querySelector(`.popup_body`),{onAction:(e,t)=>{console.log(`Upcoming draw action:`,e,t),e===`close`||e===`cancel`?O.hide():e===`confirm`?(console.log(`Selected times:`,t.selectedTimes),r&&typeof r==`function`&&r(t.selectedTimes),O.hide()):e===`select-all`?k(O.element,!0):e===`unselect-all`&&k(O.element,!1)}}),document.body.appendChild(O.element)}O.show()}function Ln(e,{onAction:t}){return`
    <div class="upcoming_modal">
      <div class="upcoming_grid">
        ${e.map(e=>`<div class="upcoming_cell upcoming_cell--active" data-time="${Fn(e)}">
      <span class="upcoming_time">${Fn(e)}</span>
      <input type="checkbox" class="upcoming_checkbox" value="${Fn(e)}" />
    </div>`).join(``)}
      </div>
      <div class="upcoming_actions">
        <button type="button" class="upcoming_action_btn upcoming_action_btn--unselect" data-action="unselect-all">UnselectAll</button>
        <button type="button" class="upcoming_action_btn upcoming_action_btn--select" data-action="select-all">SelectAll</button>
        <button type="button" class="upcoming_action_btn upcoming_action_btn--confirm" data-action="confirm">Confirm</button>
        <button type="button" class="upcoming_action_btn upcoming_action_btn--cancel" data-action="cancel">Cancel</button>
      </div>
    </div>
  `}function Rn(e,{onAction:t}){e&&(e.querySelectorAll(`.upcoming_cell`).forEach(e=>{e.addEventListener(`click`,t=>{if(t.target.type===`checkbox`)return;let n=e.querySelector(`.upcoming_checkbox`);n&&(n.checked=!n.checked)})}),e.querySelectorAll(`[data-action]`).forEach(n=>{n.addEventListener(`click`,()=>{let r=n.dataset.action;if(r===`confirm`){let n=Array.from(e.querySelectorAll(`.upcoming_checkbox:checked`)).map(e=>e.value);console.log(`Checkbox selection - found checked checkboxes:`,e.querySelectorAll(`.upcoming_checkbox:checked`).length),console.log(`Checkbox selection - selected times:`,n),t(r,{selectedTimes:n})}else t(r)})}))}function k(e,t){e&&e.querySelectorAll(`.upcoming_checkbox`).forEach(e=>{e.checked=t})}function zn(){if(O)try{O.hide()}catch{}}function Bn(){O&&=(O.destroy(),null)}var A=null;function Vn(e,t,n){if(A){A.style.display=`flex`,A.dataset.userCode=e||``,A.dataset.apiBaseUrl=t||``;return}A=document.createElement(`div`),A.className=`cp_overlay`,A.dataset.userCode=e||``,A.dataset.apiBaseUrl=t||``,A.innerHTML=`
    <div class="cp_modal">
      <div class="cp_header">
        <h3 class="cp_title">Change password</h3>
        <button type="button" class="cp_close_btn" data-action="close">&times;</button>
      </div>
      <div class="cp_body">
        <div class="cp_message" id="cp_message"></div>
        <div class="cp_field">
          <label class="cp_label">Current password</label>
          <input type="password" class="cp_input" id="cp_current_password" />
        </div>
        <div class="cp_field">
          <label class="cp_label">New password</label>
          <input type="password" class="cp_input" id="cp_new_password" />
        </div>
        <div class="cp_field">
          <label class="cp_label">Confirm password</label>
          <input type="password" class="cp_input" id="cp_confirm_password" />
        </div>
        <button type="button" class="cp_update_btn" data-action="update">Update password</button>
      </div>
    </div>
  `,Gn(A,n),document.body.appendChild(A),A.style.display=`flex`}function Hn(){A&&(A.style.display=`none`,A.querySelectorAll(`.cp_input`).forEach(e=>e.value=``))}function Un(){A&&=(document.body.removeChild(A),null)}function j(e,t,n=!1){let r=e.querySelector(`#cp_message`);r&&(r.textContent=t,r.className=`cp_message`+(n?` cp_message--error`:` cp_message--success`))}async function Wn(e,t){let n=e.querySelector(`#cp_current_password`).value,r=e.querySelector(`#cp_new_password`).value,i=e.querySelector(`#cp_confirm_password`).value;if(!n||!r||!i){j(e,`Please fill all fields`,!0);return}if(r!==i){j(e,`New password and confirm password do not match`,!0);return}if(r.length<4){j(e,`Password must be at least 4 characters long`,!0);return}let a=e.dataset.userCode,o=e.dataset.apiBaseUrl;if(!a||!o){j(e,`Error: User not logged in properly`,!0);return}let s=e.querySelector(`.cp_update_btn`),c=s.textContent;s.textContent=`Updating...`,s.disabled=!0;try{let i=`${o}/api/change-password`,s=await fetch(i,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({userCode:a,currentPassword:n,newPassword:r})}),c=await s.json();s.ok?(j(e,`Password changed successfully!`),e.querySelectorAll(`.cp_input`).forEach(e=>e.value=``),t&&t(`success`,{message:`Password changed successfully`}),setTimeout(()=>{Hn()},1500)):(j(e,c.message||`Failed to change password`,!0),t&&t(`error`,{message:c.message||`Failed to change password`}))}catch(n){console.error(`Password change error:`,n),j(e,`Network error. Please try again.`,!0),t&&t(`error`,{message:`Network error`})}finally{s.textContent=c,s.disabled=!1}}function Gn(e,t){e.addEventListener(`click`,n=>{let r=n.target.dataset.action;r===`close`?(Hn(),t&&t(`close`)):r===`update`&&Wn(e,t)}),e.addEventListener(`click`,n=>{n.target===e&&(Hn(),t&&t(`close`))});let n=e=>{e.key===`Escape`&&(Hn(),t&&t(`close`),document.removeEventListener(`keydown`,n))};document.addEventListener(`keydown`,n)}var Kn=null;function qn(){return`
    <div class="result_popup_wrapper">
      <div class="result_popup_header">
        <div class="result_popup_field">
          <label class="result_popup_label">Select Date</label>
          <div class="result_popup_input_group">
            <input type="text" class="result_popup_date_input" id="result_date_input" value="${new Date().toLocaleDateString(`en-GB`,{day:`2-digit`,month:`2-digit`,year:`numeric`}).replace(/\//g,`/`)}" readonly />
            <button type="button" class="result_popup_calendar_btn" id="result_calendar_btn">
              <svg viewBox="0 0 24 24" width="18" height="18">
                <path fill="currentColor" d="M19 3h-1V1h-2v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V8h14v11z"/>
              </svg>
            </button>
          </div>
        </div>
        <div class="result_popup_field">
          <label class="result_popup_label">Select Stone</label>
          <select class="result_popup_select" id="result_stone_select">
            <option value="PR">PR</option>
            <option value="NR">NR</option>
          </select>
        </div>
        <div class="result_popup_buttons">
          <button type="button" class="result_popup_btn result_popup_btn--show" id="result_show_btn">show</button>
          <button type="button" class="result_popup_btn result_popup_btn--close" id="result_close_btn">close</button>
        </div>
      </div>
      <div class="result_popup_table_container">
        <table class="result_popup_table">
          <thead class="result_popup_table_head">
            <tr>
              <th class="result_popup_table_header">DrawTime</th>
              <th class="result_popup_table_header">Result</th>
            </tr>
          </thead>
          <tbody class="result_popup_table_body" id="result_table_body">
            <!-- Table rows will be populated dynamically -->
          </tbody>
        </table>
      </div>
    </div>
  `}function Jn(e,{onAction:t,onShow:n}){Kn||=new gn;let r=e.querySelector(`#result_show_btn`);r&&r.addEventListener(`click`,()=>{if(n){let t=e.querySelector(`#result_date_input`),r=e.querySelector(`#result_stone_select`);n({date:t?t.value:``,stone:r?r.value:`PR`})}});let i=e.querySelector(`#result_close_btn`);i&&i.addEventListener(`click`,()=>{t&&t(`close`)});let a=e.querySelector(`#result_calendar_btn`),o=e.querySelector(`#result_date_input`);a&&o&&a.addEventListener(`click`,()=>{Kn.show(o)}),document.addEventListener(`click`,e=>{Kn&&Kn.isVisible&&!Kn.calendarElement.contains(e.target)&&!e.target.closest(`#result_calendar_btn`)&&Kn.hide()})}function Yn(e,t){let n=e.querySelector(`#result_table_body`);if(n){if(!t||t.length===0){n.innerHTML=`<tr><td colspan="2" class="result_popup_empty">No results found</td></tr>`;return}n.innerHTML=t.map(e=>`
    <tr class="result_popup_table_row">
      <td class="result_popup_table_cell">${e.drawTime||``}</td>
      <td class="result_popup_table_cell">${e.result||``}</td>
    </tr>
  `).join(``)}}function Xn(){let e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:null;return e&&typeof e.JsBarcode==`function`?e.JsBarcode:null}function M(e){return e==null?``:String(e).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/"/g,`&quot;`)}function Zn(e){let t=String(e??``).trim();if(!t)return``;let n=parseInt(t,10);return Number.isFinite(n)?String(n):t.replace(/^0+/,``)||`0`}function Qn(e){let t=Xn();if(!t)return``;let n=String(e??``).trim()||`0`,r=document.createElement(`canvas`);try{return t(r,n,{format:`CODE128`,height:40,displayValue:!1}),r.toDataURL(`image/png`)}catch{return``}}function $n(e){let t=typeof window<`u`?window.electronAPI:null,n=t&&typeof t.send==`function`?t.send.bind(t):null;if(n){n(`print`,e);return}}var er=`
    body{font-family:monospace;width:50mm;margin:0;padding:0;font-weight:bold;text-align:center}
    .ticket{width:50mm;background:#fff;text-align:left;padding:5px}
    .ticket h2,.ticket h3,.ticket h4{text-align:left;margin:5px 0;font-size:11px}
    .ticket p{margin:3px 0;font-size:10px}
    .barcode-container{text-align:left;margin-top:6px;height:40px}
    .barcodeImage{height:40px}
    .footer{font-weight:bold;margin-top:6px;font-size:9px;text-align:center}
    .items-table{width:100%;text-align:center;margin-top:5px;border-collapse:collapse;font-size:9px}
    .items-table th,.items-table td{padding:2px;border:1px solid #000}
    .items-table th{background:#ddd}
    .meta{font-size:9px}
    @media print{body{margin:0;padding:0}.ticket{width:50mm}}
`;function tr(e){let t=[];for(let n of Array.isArray(e)?e:[]){let e=n.cellID??n.cellid,r=Number(n.cv);e==null||e===``||!Number.isFinite(r)||r<=0||t.push({cellID:String(e),cv:r})}return t.sort((e,t)=>String(e.cellID).localeCompare(String(t.cellID),void 0,{numeric:!0})),t}function nr(e){let t=``;for(let n=0;n<e.length;n+=2){let r=e[n],i=e[n+1];t+=`<tr style="font-weight:bold">
      <td>${M(Zn(r.cellID))}</td><td>${M(r.cv)}</td>
      <td>${i?M(Zn(i.cellID)):``}</td><td>${i?M(i.cv):``}</td>
    </tr>`}return t}function rr({terminal:e,barcode:t,lotdate:n,drawTimeHms:r,ticketTime:i,ticketStatus:a,lines:o,heading:s,footNote:c}){let l=tr(o);if(l.length===0)return;let u=String(t??``).trim(),d=u?Qn(u):``,f=Array.isArray(o)&&o[0]?o[0]:{},p=f.ticketTot!=null&&f.ticketTot!==``?Number(f.ticketTot):l.reduce((e,t)=>e+t.cv,0),m=Number.isFinite(p)?String(p):`—`,ee=n&&r?`${M(n)} ${M(r)}`:M(r||n||`—`),te=s?M(s):`BET RECEIPT`,ne=c?`<div class="footer">${M(c)}</div>`:``;$n(`<!DOCTYPE html><html><head><meta charset="utf-8"><title>Delux</title><style>${er}</style></head><body>
  <div class="ticket">
    <h3>For Amusement Only</h3>
    <h2>NORTHERN DELUX</h2>
    <p class="meta"><strong>${te}</strong></p>
    <p><strong>Terminal:</strong> ${M(e||`—`)}</p>
    <p><strong>Barcode:</strong> ${M(u||`—`)}</p>
    <p><strong>Draw:</strong> ${ee}</p>
    <p><strong>Ticket time:</strong> ${M(i||`—`)}</p>
    <p><strong>Status:</strong> ${M(a==null?`—`:String(a))}</p>
    <p><strong>Total points:</strong> ${M(m)}</p>
    <table class="items-table"><thead><tr><th>Cell</th><th>Pt</th><th>Cell</th><th>Pt</th></tr></thead><tbody>${nr(l)}</tbody></table>
    ${d?`<div class="barcode-container"><img class="barcodeImage" src="${d}" alt="" /></div>`:``}
    <div class="footer">**Ticket not for sale**</div>
    ${ne}
  </div></body></html>`)}function ir(e){rr({...e,heading:e.heading||`ADVANCE BET`})}function ar(e){let t=[];for(let n of Array.isArray(e)?e:[]){let e=n.cellID??n.cellid,r=Number(n.cv);e==null||e===``||!Number.isFinite(r)||r<=0||t.push({cellID:String(e),cv:r})}return t.sort((e,t)=>String(e.cellID).localeCompare(String(t.cellID),void 0,{numeric:!0})),t}function or(e){let t=``;for(let n=0;n<e.length;n+=2){let r=e[n],i=e[n+1];t+=`<tr style="font-weight:bold">
      <td>${M(Zn(r.cellID))}</td><td>${M(r.cv)}</td>
      <td>${i?M(Zn(i.cellID)):``}</td><td>${i?M(i.cv):``}</td>
    </tr>`}return t}function sr(e,t,n={}){if(!e||e.ok!==!0)return null;let r=Array.isArray(e.cells)?e.cells:[];if(r.length===0)return null;let i=Array.isArray(e.tickets)&&e.tickets.length?e.tickets[0]:null,a=i&&i.drawTime!=null?String(i.drawTime).trim():``,o=``,s=``,c=/^(\d{4}-\d{2}-\d{2})\s+(\d{1,2}:\d{2}(?::\d{2})?)/.exec(a);c&&(o=c[1],s=c[2].split(`:`).length===2?`${c[2]}:00`:c[2]);let l=i&&i.ticketTime!=null?String(i.ticketTime).trim():``,u=n&&typeof n==`object`?n:{},d=`Duplicate / reprint`;if(`footerLine2`in u){let e=u.footerLine2;d=e===!1||e===null||e===``?``:String(e)}return{heading:u.heading==null?`STONE REPRINT`:String(u.heading),footerLine2:d,terminal:t||`—`,barcode:String(e.barcode??``).trim(),lotdate:o,lotTime:s,placedAt:l,ticketStatus:`ticketStatus`in u?u.ticketStatus:null,cells:r}}function cr({heading:e,footerLine2:t,terminal:n,barcode:r,lotdate:i,lotTime:a,placedAt:o,ticketStatus:s,cells:c}){let l=ar(c);if(l.length===0)return;let u=String(r??``).trim(),d=u?Qn(u):``,f=i==null?``:String(i),p=a==null?``:String(a),m=o==null?``:String(o),ee=f&&p?`${M(f)} ${M(p)}`:M(p||f||`—`),te=M(n||`—`),ne=M(e||`RECEIPT`),h=Array.isArray(c)&&c[0]?c[0]:{},re=h.ticketTot!=null&&h.ticketTot!==``?Number(h.ticketTot):l.reduce((e,t)=>e+t.cv,0),ie=Number.isFinite(re)?String(re):`—`,ae=s!=null&&String(s)!==``?`<p><strong>Status:</strong> ${M(String(s))}</p>`:``,oe=t!=null&&String(t).trim()!==``?`<div class="footer">${M(String(t))}</div>`:``;$n(`<!DOCTYPE html><html><head><meta charset="utf-8"><title>Delux</title><style>${er}</style></head><body>
  <div class="ticket">
    <h3>For Amusement Only</h3>
    <h2>NORTHERN DELUX</h2>
    <p class="meta"><strong>${ne}</strong></p>
    <p><strong>Terminal:</strong> ${te}</p>
    <p><strong>Barcode:</strong> ${M(u||`—`)}</p>
    <p><strong>Draw:</strong> ${ee}</p>
    <p><strong>Placed:</strong> ${M(m||`—`)}</p>
    ${ae}
    <p><strong>Total points:</strong> ${M(ie)}</p>
    <table class="items-table"><thead><tr><th>Cell</th><th>Pt</th><th>Cell</th><th>Pt</th></tr></thead><tbody>${or(l)}</tbody></table>
    ${d?`<div class="barcode-container"><img class="barcodeImage" src="${d}" alt="" /></div>`:``}
    <div class="footer">**Ticket not for sale**</div>
    ${oe}
  </div></body></html>`)}function lr(e,{terminal:t}={}){if(!e||e.ok!==!0||e.hasReceipt!==!0)return;let n=Array.isArray(e.cells)?e.cells:[];cr({heading:`LAST RECEIPT`,footerLine2:`Duplicate / reprint`,terminal:t||`—`,barcode:e.barcode,lotdate:e.lotdate==null?``:String(e.lotdate),lotTime:e.lotTime==null?``:String(e.lotTime),placedAt:e.placedAt==null?``:String(e.placedAt),ticketStatus:e.ticketStatus,cells:n})}var ur=t({default:()=>dr}),dr=``+new URL(`4161854560_c48b3bbcbe-iJHQIlrj.jpg`,import.meta.url).href,fr=t({default:()=>pr}),pr=``+new URL(`Durga-Yantra-6x6-Front_1200_klein-CjkmTqLQ.jpg`,import.meta.url).href,mr=t({default:()=>hr}),hr=``+new URL(`Ganesha_Yantra-CrRaf6Zg.jpg`,import.meta.url).href,gr=t({default:()=>_r}),_r=``+new URL(`Tripura-bhairavi_yantra_color-DS4ciZRR.jpg`,import.meta.url).href,vr=t({default:()=>yr}),yr=``+new URL(`bagalamukhi-yantra-cOlD-yPl.jpg`,import.meta.url).href,br=t({default:()=>xr}),xr=``+new URL(`il_fullxfull.1598885277_esyt-Cw0wiXt6.jpg`,import.meta.url).href,Sr=t({default:()=>Cr}),Cr=``+new URL(`venkatesh-yantra-CBa8UIzd.png`,import.meta.url).href,wr=1e3,Tr=Object.assign({"../media/slideshow/4161854560_c48b3bbcbe.jpg":ur,"../media/slideshow/Durga-Yantra-6x6-Front_1200_klein.jpg":fr,"../media/slideshow/Ganesha_Yantra.jpg":mr,"../media/slideshow/Tripura-bhairavi_yantra_color.jpg":gr,"../media/slideshow/bagalamukhi-yantra.jpg":vr,"../media/slideshow/il_fullxfull.1598885277_esyt.jpg":br,"../media/slideshow/venkatesh-yantra.png":Sr});function Er(e){if(typeof e==`string`)return e;let t=e&&e.default;return typeof t==`function`?t():typeof t==`string`?t:e}function Dr(){return Object.keys(Tr).sort().map(e=>Er(Tr[e]))}function Or(e){if(!e)return()=>{};let t=Dr();e.textContent=``,e.classList.add(`gamescreen_slideshow`);let n=document.createElement(`img`),r=document.createElement(`img`);if(n.className=`gamescreen_slideshow_layer`,r.className=`gamescreen_slideshow_layer`,n.alt=``,r.alt=``,n.draggable=!1,r.draggable=!1,e.appendChild(n),e.appendChild(r),t.length===0)return()=>{e.textContent=``,e.classList.remove(`gamescreen_slideshow`)};let i=n,a=r,o=0;if(i.src=t[0],i.classList.add(`gamescreen_slideshow_layer--active`),t.length<2)return()=>{e.textContent=``,e.classList.remove(`gamescreen_slideshow`)};let s=null,c=async()=>{o=(o+1)%t.length,a.removeAttribute(`src`),a.src=t[o];try{await a.decode()}catch{await new Promise(e=>{let t=()=>e();a.onload=t,a.onerror=t})}a.classList.add(`gamescreen_slideshow_layer--active`),i.classList.remove(`gamescreen_slideshow_layer--active`);let e=i;i=a,a=e};return s=window.setInterval(()=>{c()},wr),()=>{s!=null&&(clearInterval(s),s=null),e.textContent=``,e.classList.remove(`gamescreen_slideshow`)}}function kr(e){return e==null?``:String(e).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/"/g,`&quot;`)}var N={startHour:0,startMinute:10,endHour:23,endMinute:55,interval:5};function Ar(e){let t=[],n=e.startHour*60+e.startMinute,r=e.endHour*60+e.endMinute;for(;n<=r;){let r=Math.floor(n/60),i=n%60;t.push(`${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`),n+=e.interval}return console.log(`Generated draw times (first 10):`,t.slice(0,10)),t}function jr(e,t){let n=C(t,S),r=n.hour*60+n.minute,i=N.startHour*60+N.startMinute,a;if(r<i)a=i;else{let e=r-i;a=i+(Math.floor(e/N.interval)+1)*N.interval}let o=e.filter(e=>{let[t,n]=e.split(`:`).map(Number);return t*60+n>=a});return console.log(`Current time: ${n.hour}:${String(n.minute).padStart(2,`0`)} (${r} min)`),console.log(`Next draw starts at: ${Math.floor(a/60)}:${String(a%60).padStart(2,`0`)} (${a} min)`),console.log(`Upcoming times:`,o),o}function Mr(){let e=Ar(N),t=[];for(let n=0;n<e.length;n+=2){let r=e[n],i=e[n+1]||``;t.push([r,``,i,``])}return t}var Nr=Mr();function P(e,t,n=3e3){let r=e&&e.querySelector&&e.querySelector(`.gamescreen_place_chips`);r&&(e._placeChipsMsgTimer&&=(clearTimeout(e._placeChipsMsgTimer),null),r.textContent=t,e._placeChipsMsgTimer=setTimeout(()=>{r.textContent=``,e._placeChipsMsgTimer=null},n))}var Pr=2,Fr=2200,Ir=2400;function Lr(e,t){!e||!e.querySelector||(e._advanceChipsMsgQueue||=[],e._advanceChipsMsgQueue.push(String(t)),!e._advanceChipsMsgDrainRunning&&(e._advanceChipsMsgDrainRunning=!0,(async()=>{for(;e._advanceChipsMsgQueue&&e._advanceChipsMsgQueue.length>0;)P(e,e._advanceChipsMsgQueue.shift(),Fr),await new Promise(e=>setTimeout(e,Ir));e._advanceChipsMsgDrainRunning=!1})()))}function Rr(){let e=``;for(let t=0;t<10;t++){e+=`<div class="gamescreen_pr_row">`;for(let n=0;n<10;n++){let r=t*10+n,i=`PR${String(r).padStart(2,`0`)}`;e+=`<div class="gamescreen_pr_cell"><span class="gamescreen_pr_label">${i}</span><input type="text" class="gamescreen_pr_input" value="" /></div>`}e+=`<div class="gamescreen_all_cell"><span class="gamescreen_all_label">ALL A</span><input type="text" class="gamescreen_all_input" value="" /></div></div>`}return e}function zr(){return Array(10).fill(0).map(()=>`<div class="gamescreen_all_cell"><span class="gamescreen_all_label">ALL B</span><input type="text" class="gamescreen_all_input" value="" /></div>`).join(``)}function Br(){return Array(10).fill(0).map(()=>`<div class="gamescreen_all_cell"><span class="gamescreen_all_label">ALL C</span><input type="text" class="gamescreen_all_input" value="" /></div>`).join(``)}function Vr(){return Nr.map(e=>`<div class="gamescreen_time_row">${e.map((t,n)=>t?`<div class="${n===0||n===2?`gamescreen_time_cell gamescreen_time_cell--time`:`gamescreen_time_cell gamescreen_time_cell--code`}">${kr(t)}</div>`:`<div class="gamescreen_time_cell gamescreen_time_cell--code" data-lot-time="${kr(n===1?e[0]:n===3?e[2]:``)}"></div>`).join(``)}
      </div>`).join(``)}function Hr(e){if(!e)return``;let t=String(e).trim();return t?t.length>=5?t.slice(0,5):t:``}function Ur(e){if(e==null)return``;let t=String(e).replace(/\D/g,``);return t?t.slice(-2).padStart(2,`0`):``}function Wr(e){let t=Hr(e).split(`:`);if(t.length<2)return`PR`;let n=Number(t[0]),r=Number(t[1]);return!Number.isFinite(n)||!Number.isFinite(r)||r%2==0?`PR`:`NR`}function Gr(e){if(!e)return;let t=J?ni(J):null,n=`PR`;if(t){let e=C(t,S);n=Wr(`${String(e.hour).padStart(2,`0`)}:${String(e.minute).padStart(2,`0`)}`)}e.querySelectorAll(`.gamescreen_pr_label`).forEach((e,t)=>{e.textContent=`${n}${String(t).padStart(2,`0`)}`})}function Kr(e){let t=Hr(e);return t?rn(`${t}:00`):``}async function qr(e){if(!e)return;let t=await Vt(``);if(!t||!t.ok)return;let n=Array.isArray(t.results)?t.results:[];n[0],Gr(e);let r=J||$t(),i=r?ni(r):null,a=Ar(N),o=1440;if(i){let e=C(i,S);o=e.hour*60+e.minute}console.log(`Next draw time:`,i?C(i,S):`none`),console.log(`Next draw minutes:`,o);let s=new Map;n.forEach(e=>{let t=Hr(e.lotTime??e.lottime),n=Wr(t);s.set(t,{lotTime:t,cellID:`${n}${Ur(e.cellID)}`.trim()})});let c=e.querySelectorAll(`.gamescreen_time_row`),l=0,u=!1;c.forEach(e=>{let t=e.querySelectorAll(`.gamescreen_time_cell`),n=a[l++]||``,r=a[l++]||``,i=!1,c=!1;if(n){let[e,t]=n.split(`:`).map(Number);i=e*60+t<o}if(r){let[e,t]=r.split(`:`).map(Number);c=e*60+t<o}let d=n?s.get(n):null,f=r?s.get(r):null;t[0]&&(t[0].textContent=i?n:``),t[1]&&(t[1].textContent=i&&d?d.cellID:``),t[2]&&(t[2].textContent=c?r:``),t[3]&&(t[3].textContent=c&&f?f.cellID:``);let p=i||c;e.style.display=p?`grid`:`none`,p&&(u=!0)}),console.log(`Has any visible rows:`,u);let d=e.querySelector(`.gamescreen_time_table_wrap`);d&&setTimeout(()=>{d.scrollTop=d.scrollHeight},100)}function Jr(){return`
    <div class="gamescreen_wrap">
      <div class="gamescreen_scale">
      <div class="gamescreen_screen">
        <!-- TOP SECTION -->
        <div class="gamescreen_header">
          <div class="gamescreen_title">Northern Deluxe</div>
          <div class="gamescreen_cb_row">
            <label class="gamescreen_cb" for="gs_cb_print">
              <input id="gs_cb_print" type="checkbox" checked />
              <span>PRINT <br />TICKET</span>
            </label>
            <label class="gamescreen_cb" for="gs_cb_ac">
              <input id="gs_cb_ac" type="checkbox" checked />
              <span>AC</span>
            </label>
          </div>
          <div class="gamescreen_meta_stack">
            <div class="gamescreen_amount">0.00</div>
            <div class="gamescreen_date_box">08/04/2026</div>
            <div class="gamescreen_pno">P.No.Nrd01</div>
          </div>
          <div class="gamescreen_time_sections">
          <div class="gamescreen_clock">13:48:49</div>
          <div class="gamescreen_bulb" aria-hidden="true">
            <span class="gamescreen_bulb_glow"></span>
          </div>
          </div>
        </div>
        <!-- MIDDLE SECTION -->
        <div class="gamescreen_middle">
          <div class="gamescreen_left_panel">
            <div class="gamescreen_time_section">
              <div class="gamescreen_time_group">
                <div class="gamescreen_lbl_time">Next Draw</div>
                <div class="gamescreen_val_time">--:--</div>
              </div>
              <div class="gamescreen_time_group">
                <div class="gamescreen_lbl_timeleft">Time Left</div>
                <div class="gamescreen_val_timeleft">00:00:58</div>
              </div>
            </div>
            <div class="gamescreen_img_panel">
              <div class="gamescreen_slideshow_host"></div>
            </div>
            <div class="gamescreen_caption">
              <div>To Get Stones</div>
              <div>Choose Your Product Codes</div>
            </div>
            <div class="gamescreen_time_table_wrap">
              <div class="gamescreen_time_table">${Vr()}</div>
            </div>
            <button type="button" class="gamescreen_fbtn gamescreen_fbtn--stone gamescreen_stone_left" data-gamescreen-action="stone-report">Stone</button>
          </div>
          <div class="gamescreen_right_panel">
            <div class="gamescreen_green">
              <div class="gamescreen_pr_block" id="gamescreen_pr_block">
                <div class="gamescreen_pr_main">${Rr()}</div>
                <div class="gamescreen_allb_row">${zr()}</div>
                <div class="gamescreen_allc_row">${Br()}</div>
              </div>
              <div class="gamescreen_draw_closed" id="gamescreen_draw_closed" style="display: none;">
                <div class="gamescreen_draw_closed_text">Draw Closed</div>
              </div>
            </div>
            <div class="gamescreen_right_bottom">
              <button type="button" class="gamescreen_heera">HEERA Stones<br />Product codes</button>
              <div class="gamescreen_place_chips"></div>
              <div class="gamescreen_lucky_container">
                <input type="text" class="gamescreen_lucky_input" maxlength="2" placeholder="1" />
                <button type="button" class="gamescreen_lucky" data-gamescreen-action="lucky-pick">L - Lucky Pick</button>
              </div>
            </div>
          </div>
        </div>
        <!-- BOTTOM SECTION -->
        <div class="gamescreen_bottom">
          <div class="gamescreen_mid">
            <div class="gamescreen_center_controls">
              <div class="gamescreen_toggles">
                <button type="button" class="gamescreen_toggle gamescreen_toggle--on" id="gs_toggle_current">Current</button>
                <button type="button" class="gamescreen_toggle" id="gs_toggle_upcoming">Upcoming</button>
              </div>
              <div class="gamescreen_stats">
                <div class="gamescreen_stat gamescreen_stat--w">0.00</div>
                <div class="gamescreen_stat gamescreen_stat--g">0</div>
              </div>
            </div>
            <div class="gamescreen_barcode_section">
              <span class="gamescreen_barcode_lbl">F8<br />Barcode</span>
              <input class="gamescreen_barcode_inp" type="text" readonly value="" />
            </div>
          </div>
          <div class="gamescreen_footer">
            <div class="gamescreen_footer_center">
              <button type="button" class="gamescreen_fbtn gamescreen_fbtn--buy">F6-Buy</button>
              <button type="button" class="gamescreen_fbtn gamescreen_fbtn--cyan">F5-Clear</button>
              <button type="button" class="gamescreen_fbtn gamescreen_fbtn--cyan">F9-Can. Rec.</button>
              <button type="button" class="gamescreen_fbtn gamescreen_fbtn--cyan2" data-gamescreen-action="last-receipt">Last Receipt</button>
              <button type="button" class="gamescreen_fbtn gamescreen_fbtn--white" data-gamescreen-action="change-password">Change Password</button>
              <button type="button" class="gamescreen_fbtn gamescreen_fbtn--exit" data-gamescreen-action="exit-offline">Exit</button>
              <button type="button" class="gamescreen_fbtn gamescreen_fbtn--white" data-gamescreen-action="purchase-details">Purchase Details</button>
            </div>
          </div>
        </div>
      </div>
      </div>
    </div>
  `}var Yr=null,Xr=null,Zr=null;function Qr(){Yr&&=(window.removeEventListener(`resize`,Yr),null)}function $r(e){let t=e.querySelector(`.gamescreen_scale`),n=e.querySelector(`.gamescreen_screen`);if(!t||!n)return;let r=window.innerWidth/1366,i=window.innerHeight/768;t.style.width=`${window.innerWidth}px`,t.style.height=`${window.innerHeight}px`,n.style.transform=`scale(${r}, ${i})`}var F=null,ei=null,I=null,L=null,R=null,z=null,B=null,V={timeLeftSeconds:0,isBettingAllowed:!0,isPopupShowing:!1,popupTimeoutId:null,currentDrawTime:null,winningRequestedForDrawTs:null,winningFetchPending:!1,prevCountdownSeconds:null,autoBetSubmittedForDrawTs:null,prevNextDrawTs:null,afterLuckyPickDismiss:null},ti={startHour:N.startHour,startMinute:N.startMinute,endHour:N.endHour,endMinute:N.endMinute,intervalMinutes:N.interval};function ni(e){let t=C(e,S),n=t.hour*60+t.minute,r=(Math.floor(n/ti.intervalMinutes)+1)*ti.intervalMinutes;if(r>=1440){let e=tn(t.year,t.month,t.day,0,0,0);return new Date(e.getTime()+1440*60*1e3)}let i=Math.floor(r/60),a=r%60;return tn(t.year,t.month,t.day,i,a,0)}function ri(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function ii(e){z||(z=document.createElement(`div`),z.className=`gs_spinner_overlay`,z.innerHTML=`<div class="gs_spinner" aria-hidden="true"></div>`,document.body.appendChild(z)),e?(En(!0),z.classList.remove(`gs_spinner_overlay--visible`),z.offsetHeight,requestAnimationFrame(()=>{z&&z.classList.add(`gs_spinner_overlay--visible`)})):(z.classList.remove(`gs_spinner_overlay--visible`),En(!1))}function ai(e){let t=C(new Date(e),S);return`${String(t.hour).padStart(2,`0`)}:${String(t.minute).padStart(2,`0`)}:00`}function oi(e){if(!Array.isArray(e))return 0;let t=0;for(let n of e){let e=parseFloat(String(n&&n.claimAmount!=null?n.claimAmount:``).replace(/[^0-9.-]/g,``));Number.isFinite(e)&&(t+=e)}return t}function si(){B&&B.classList.remove(`gs_winning_modal_overlay--visible`)}function ci(e){B||(B=document.createElement(`div`),B.className=`gs_winning_modal_overlay`,document.body.appendChild(B),B.addEventListener(`click`,e=>{(e.target===B||e.target&&e.target.classList&&e.target.classList.contains(`gs_winning_modal_ok`))&&si()})),B.innerHTML=`<div class="gs_winning_modal_panel" role="dialog" aria-modal="true">
    <div class="gs_winning_modal_title">Winning</div>
    <div class="gs_winning_modal_amount">${kr(e)}</div>
    <button type="button" class="gs_winning_modal_ok">OK</button>
  </div>`,B.classList.remove(`gs_winning_modal_overlay--visible`),B.offsetHeight,requestAnimationFrame(()=>{B&&B.classList.add(`gs_winning_modal_overlay--visible`)})}function li(){let e=V.afterLuckyPickDismiss;if(V.afterLuckyPickDismiss=null,typeof e==`function`)try{e()}catch{}}function ui(e=3e3){V.popupTimeoutId&&clearTimeout(V.popupTimeoutId),V.popupTimeoutId=setTimeout(()=>{L&&(D(L),L.classList.remove(`lp_overlay--visible`),document.body.style.overflow=``),V.isPopupShowing=!1,V.popupTimeoutId=null,li()},e)}function di(e){return!0}function fi(e){let t=parseFloat(e.value);return isNaN(t)?0:t}function pi(e,t){e.value=t>0?t:``}function mi(e){let t=e.replace(/[^0-9.]/g,``),n=t.split(`.`);return n.length>2&&(t=n[0]+`.`+n.slice(1).join(``)),t}var H={baseValues:Array(100).fill(0),allA:Array(10).fill(0),allB:Array(10).fill(0),allC:Array(10).fill(0)};function hi(){H.baseValues.fill(0),H.allA.fill(0),H.allB.fill(0),H.allC.fill(0)}function gi(){return{baseValues:H.baseValues.slice(),allA:H.allA.slice(),allB:H.allB.slice(),allC:H.allC.slice()}}function _i(e){H.baseValues.splice(0,e.baseValues.length,...e.baseValues),H.allA.splice(0,e.allA.length,...e.allA),H.allB.splice(0,e.allB.length,...e.allB),H.allC.splice(0,e.allC.length,...e.allC)}function vi(e){let t=parseFloat(String(e).replace(/[^0-9.-]/g,``));return Number.isFinite(t)?t:0}function yi(){if(F)try{F.hide()}catch{}if(I)try{I.hide()}catch{}if(R)try{R.hide()}catch{}zn(),Hn(),L&&L.classList.contains(`lp_overlay--visible`)&&(D(L),L.classList.remove(`lp_overlay--visible`)),V.afterLuckyPickDismiss=null,Y(),si(),document.body.style.overflow=``}function bi(e,t){e&&e.querySelectorAll(`.gamescreen_pr_input, .gamescreen_all_input`).forEach(e=>{e.readOnly=t})}function xi(e){let t=e&&e.querySelector(`.gamescreen_amount`);if(!t)return;let n=U(e);t.textContent=Math.max(0,Fi-n).toFixed(2)}function Si(e,t){return e*10+t}function Ci(e,t,n){return(t-n+10)%10==9-e}function wi(e,t){let n=0;for(let r=0;r<10;r++)Ci(e,t,r)&&(n+=H.allC[r]||0);return n}function Ti(e,t){let n=Si(e,t),r=H.baseValues[n],i=H.allA[e]||0,a=H.allB[t]||0,o=wi(e,t);return r+i+a+o}function Ei(e){e.querySelectorAll(`.gamescreen_pr_row`).forEach((e,t)=>{e.querySelectorAll(`.gamescreen_pr_input`).forEach((e,n)=>{pi(e,Ti(t,n))})}),U(e),xi(e)}function U(e){let t=0;for(let e=0;e<10;e++)for(let n=0;n<10;n++)t+=Ti(e,n);let n=e.querySelector(`.gamescreen_stat--w`);return n&&(n.textContent=t.toFixed(2)),t}function Di(e){hi(),e.querySelectorAll(`.gamescreen_pr_input`).forEach(e=>{e.value=``}),e.querySelectorAll(`.gamescreen_pr_row .gamescreen_all_input`).forEach(e=>{e.value=``});let t=e.querySelector(`.gamescreen_allb_row`);t&&t.querySelectorAll(`.gamescreen_all_input`).forEach(e=>{e.value=``});let n=e.querySelector(`.gamescreen_allc_row`);n&&n.querySelectorAll(`.gamescreen_all_input`).forEach(e=>{e.value=``});let r=e.querySelector(`.gamescreen_stat--w`);r&&(r.textContent=`0.00`),xi(e)}function Oi(e){if(q()){P(e,`Lucky pick is not available in advance bet mode.`);return}let t=Qi();if(t){On(t),P(e,$i(t));return}let n=Math.floor(Math.random()*100),r=e.querySelector(`.gamescreen_lucky_input`),i=1;if(r&&r.value.trim()){let t=parseInt(r.value.trim(),10);if(t>=0&&t<=99)i=t;else{P(e,`Enter value between 0-99`);return}}let a=Si(Math.floor(n/10),n%10),o=gi();if(H.baseValues[a]=(H.baseValues[a]||0)+i,Ei(e),U(e)>Fi+1e-9){_i(o),Ei(e),P(e,`Insufficient balance to place this bet.`);return}P(e,`Lucky pick: ${String(n).padStart(2,`0`)} (+${i})`)}function ki(e,t){let n=e.querySelectorAll(`.gamescreen_pr_row`),r=e.querySelector(`.gamescreen_allb_row`),i=e.querySelector(`.gamescreen_allc_row`);for(let e=0;e<n.length;e++){let r=n[e].querySelectorAll(`.gamescreen_pr_input`);for(let n=0;n<r.length;n++)if(r[n]===t)return{type:`pr`,row:e,col:n};if(n[e].querySelector(`.gamescreen_all_input`)===t)return{type:`alla`,row:e,col:10}}if(r){let e=r.querySelectorAll(`.gamescreen_all_input`);for(let n=0;n<e.length;n++)if(e[n]===t)return{type:`allb`,row:10,col:n}}if(i){let e=i.querySelectorAll(`.gamescreen_all_input`);for(let n=0;n<e.length;n++)if(e[n]===t)return{type:`allc`,row:11,col:n}}return null}function Ai(e,t){let n=e.querySelectorAll(`.gamescreen_pr_row`),r=e.querySelector(`.gamescreen_allb_row`),i=e.querySelector(`.gamescreen_allc_row`),a=null;switch(t.type){case`pr`:if(t.row>=0&&t.row<10&&t.col>=0&&t.col<10){let e=n[t.row];e&&(a=e.querySelectorAll(`.gamescreen_pr_input`)[t.col])}break;case`alla`:if(t.row>=0&&t.row<10){let e=n[t.row];e&&(a=e.querySelector(`.gamescreen_all_input`))}break;case`allb`:r&&t.col>=0&&t.col<10&&(a=r.querySelectorAll(`.gamescreen_all_input`)[t.col]);break;case`allc`:i&&t.col>=0&&t.col<10&&(a=i.querySelectorAll(`.gamescreen_all_input`)[t.col]);break}a&&a.focus()}function W(e,t,n){let r=ki(e,t);if(!r)return;let i=null;switch(r.type){case`pr`:i=ji(r,n);break;case`alla`:i=Mi(r,n);break;case`allb`:i=Ni(r,n);break;case`allc`:i=Pi(r,n);break}i&&Ai(e,i)}function ji(e,t){switch(t){case`up`:if(e.row>0)return{type:`pr`,row:e.row-1,col:e.col};break;case`down`:if(e.row<9)return{type:`pr`,row:e.row+1,col:e.col};if(e.row===9)return{type:`allb`,row:10,col:e.col};break;case`left`:if(e.col>0)return{type:`pr`,row:e.row,col:e.col-1};if(e.col===0&&e.row>0)return{type:`pr`,row:e.row-1,col:9};break;case`right`:if(e.col<9)return{type:`pr`,row:e.row,col:e.col+1};if(e.col===9)return{type:`alla`,row:e.row,col:10};break}return null}function Mi(e,t){switch(t){case`up`:if(e.row>0)return{type:`alla`,row:e.row-1,col:10};break;case`down`:if(e.row<9)return{type:`alla`,row:e.row+1,col:10};break;case`left`:return{type:`pr`,row:e.row,col:9};case`right`:break}return null}function Ni(e,t){switch(t){case`up`:return{type:`pr`,row:9,col:e.col};case`down`:return{type:`allc`,row:11,col:e.col};case`left`:if(e.col>0)return{type:`allb`,row:10,col:e.col-1};break;case`right`:if(e.col<9)return{type:`allb`,row:10,col:e.col+1};break}return null}function Pi(e,t){switch(t){case`up`:return{type:`allb`,row:10,col:e.col};case`down`:break;case`left`:if(e.col>0)return{type:`allc`,row:11,col:e.col-1};break;case`right`:if(e.col<9)return{type:`allc`,row:11,col:e.col+1};break}return null}var Fi=0;async function Ii(e,t){if(t&&e.querySelector(`.gamescreen_amount`))try{let n=await Bt(t);n&&n.ok&&n.balance!==void 0&&(Fi=parseFloat(n.balance)||0,xi(e))}catch(e){console.error(`Error getting balance:`,e)}}function Li(){let e=Qt();return(e==null?String(Math.floor(Math.random()*1e8)).padStart(8,`0`):String(e).slice(-8))+Math.floor(Math.random()*1e4).toString().padStart(4,`0`)}function Ri(){let e=Qt();return`TXN${String(e??Math.floor(Math.random()*0xe8d4a51000))}${Math.floor(Math.random()*1e3).toString().padStart(3,`0`)}`}var G={date:``,time:``},K=[],zi=`current`;function q(){return zi===`advance`}function Bi(){return V.isBettingAllowed||q()}function Vi(e,t){zi=t===`advance`?`advance`:`current`;let n=e.querySelector(`#gs_toggle_current`),r=e.querySelector(`#gs_toggle_upcoming`);n&&r&&(q()?(n.classList.remove(`gamescreen_toggle--on`),r.classList.add(`gamescreen_toggle--on`)):(n.classList.add(`gamescreen_toggle--on`),r.classList.remove(`gamescreen_toggle--on`),K=[])),e&&J&&Wi(e)}function Hi(e){let t=Hr(e?.lotTime??e?.lottime),n=Wr(t),r=Ur(e?.cellID),i=r?`${n} ${r}`:n,a=G.date||`—`,o=G.time||`—`;return{date:a,time:o,drawTime:Kr(t)||o,result:i,drawType:`${n} ${t||``}`.trim()}}async function Ui(e,t,n){V.winningFetchPending=!1,ii(!1);let r=t&&t.ok&&t.result?t.result:null,i=null,a=e._deluxUserCode;a&&n!=null&&(i=await qt(a,ai(n))),qr(e),a&&await Ii(e,a);let o=i&&i.ok&&i.hasWinning?oi(i.wins):0,s=o>0?()=>ci(o.toFixed(2)):null;V.isPopupShowing=!0,Ta(e,r?Hi(r):null,{reveal:!0,onAfterDismiss:s})}var J=null;function Wi(e){if(!J)return;let t=e.querySelector(`.gamescreen_val_timeleft`);if(!t)return;let n=e.querySelector(`.gamescreen_val_time`);if(!di(J)){t.textContent=`Closed`,n&&(n.textContent=`--:--`),V.timeLeftSeconds=0,V.isBettingAllowed=!1,V.currentDrawTime=null,q()?bi(e,!1):bi(e,!0);let r=e.querySelector(`.gamescreen_fbtn--buy`);r&&(r.disabled=!0);return}let r=ni(J);if(!r){t.textContent=`Closed`,n&&(n.textContent=`--:--`),V.timeLeftSeconds=0,V.isBettingAllowed=!1,V.currentDrawTime=null,q()?bi(e,!1):bi(e,!0);let r=e.querySelector(`.gamescreen_fbtn--buy`);r&&(r.disabled=!0);return}V.currentDrawTime=r;let i=r.getTime()-J.getTime(),a=Math.max(0,Math.ceil(i/1e3));if(t.textContent=ri(a),n){let e=C(r,S);n.textContent=`${String(e.hour).padStart(2,`0`)}:${String(e.minute).padStart(2,`0`)}`}V.timeLeftSeconds=a,V.isBettingAllowed=a>10,Gr(e);let o=r.getTime(),s=V.prevCountdownSeconds;if(s!=null&&s>10&&a<=10){yi();let t=e._deluxUserCode;t&&Zi(e,t,o)}V.prevCountdownSeconds=a,q()?bi(e,!1):bi(e,a<=10);let c=e.querySelector(`.gamescreen_fbtn--buy`);c&&(q()?c.disabled=!0:c.disabled=a<=10),F?.isVisible&&ga();let l=V.prevNextDrawTs,u=l!=null&&l!==o,d=u?l:null;u&&d!=null&&d!==V.winningRequestedForDrawTs&&!V.winningFetchPending&&(V.winningRequestedForDrawTs=d,V.winningFetchPending=!0,ii(!0),Ht().then(t=>Ui(e,t,d)).catch(()=>Ui(e,null,d))),V.prevNextDrawTs=o}function Gi(){V.popupTimeoutId&&(clearTimeout(V.popupTimeoutId),V.popupTimeoutId=null),V={timeLeftSeconds:0,isBettingAllowed:!0,isPopupShowing:!1,popupTimeoutId:null,currentDrawTime:null,winningRequestedForDrawTs:null,winningFetchPending:!1,prevCountdownSeconds:null,autoBetSubmittedForDrawTs:null,prevNextDrawTs:null,afterLuckyPickDismiss:null}}async function Ki(){try{let e=Ft(),t=await fetch(`${e}/api/time`,{cache:`no-store`});if(t.ok){let e=await t.json();if(e.utcMs!=null){Zt(e);let t=e.date&&e.time?{date:e.date,time:e.time}:nn(new Date(Number(e.utcMs)));return G.date=t.date,G.time=t.time,{...e,date:t.date,time:t.time}}}}catch(e){console.error(`Error fetching server time:`,e)}let e=$t();if(e){let t=nn(e);return G.date=t.date,G.time=t.time,{date:t.date,time:t.time,utcMs:Qt()}}return{date:G.date,time:G.time,utcMs:Qt()}}function qi(){if(G.date&&G.time)return{date:G.date,time:G.time};let e=$t();return e?nn(e):{date:``,time:``}}function Ji(){let e=J?new Date(J.getTime()):$t();if(!e)return qi();let t=ni(e);if(!t)return qi();let n=C(t,S),r=n.year,i=String(n.month).padStart(2,`0`),a=String(n.day).padStart(2,`0`),o=String(n.hour).padStart(2,`0`),s=String(n.minute).padStart(2,`0`);return{date:`${r}-${i}-${a}`,time:`${o}:${s}:00`}}function Yi(e,t,n={}){let r=n.advanceOnly===!0,i=[],a=Ji(),o=Li(),s=Ri(),c=e&&e.querySelector?U(e):0;function l(e,n,r){let l=r??c,u=n?Xi(e):a;for(let e=0;e<10;e++)for(let r=0;r<10;r++){let c=Ti(e,r);if(c>0){let d=Si(e,r),f={uID:t,point:0,cv:parseFloat(c),cellid:String(d).padStart(4,`0`),sernum:1e3,lotnum:0,lotdate:u.date,lottime:u.time,barcode:o,transId:s,isadvance:n,ticketTot:l,qtytot:0,printtime:a.time,printflag:0,dateAdded:a.date,dateModified:a.date,status:1,curAdvDraw:0};i.push(f)}}}if(r){let e=n.advanceDrawTime;return e==null||String(e).trim()===``||c<=0||l(String(e).trim(),!0,c),i}return l(null,!1,c),K&&K.length>0&&K.forEach(e=>{l(e,!0,c)}),i}function Xi(e){let[t,n]=e.split(`:`).map(Number),r=J?new Date(J):$t();if(!r)return{date:``,time:`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}:00`};let i=C(r,S),a=tn(i.year,i.month,i.day,t,n,0);a<=r&&(a=new Date(a.getTime()+1440*60*1e3));let o=C(a,S);return{date:`${o.year}-${String(o.month).padStart(2,`0`)}-${String(o.day).padStart(2,`0`)}`,time:`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}:00`}}async function Zi(e,t,n){!e||!t||q()||V.autoBetSubmittedForDrawTs!==n&&(U(e)<=0||(V.autoBetSubmittedForDrawTs=n,await ia(e,t,{allowWhenLocked:!0,silentReceipt:!0})))}function Qi(){return V.isBettingAllowed?null:V.currentDrawTime!=null&&V.timeLeftSeconds>=1&&V.timeLeftSeconds<=10?`BETTING_LOCKED`:`BETTING_CLOSED`}function $i(e){return e===`BETTING_LOCKED`?`Bet locked.`:`Betting is closed.`}function ea(e){switch(e){case`NO_BETS`:return`No bets to place. Please select numbers first.`;case`INSUFFICIENT_BALANCE`:return`Insufficient balance to place this bet.`;case`NO_USER_CODE`:return`User not logged in properly.`;case`NOT_CONNECTED`:return`Not connected to server. Please reconnect.`;case`TIMEOUT`:return`Request timed out. Please try again.`;case`NETWORK_ERROR`:return`Network error. Please try again.`;case`BETTING_LOCKED`:return`Bet locked.`;case`BETTING_CLOSED`:return`Betting is closed.`;case`NO_BETS_CREATED`:return`No bets could be created. Check your grid.`;case`MISSING_FIELDS`:return`Invalid bet data. Please try again.`;case`NO_ADVANCE_TIMES`:return`Select at least one draw time.`;default:return`Failed to place bet: ${e}`}}function ta(e){let t=localStorage.getItem(`username`);return t!=null&&String(t).trim()!==``?String(t).trim():e||`—`}function na(e){if(e&&e.timestamp){let t=new Date(e.timestamp);if(!Number.isNaN(t.getTime()))return t.toLocaleString()}try{return new Date().toLocaleString()}catch{return``}}function ra(e,t,n,r){if(!t?.ok||!Array.isArray(n)||n.length===0)return;let i=ta(e),a=n[0]?.lotdate==null?``:String(n[0].lotdate),o=t.drawTime!=null&&String(t.drawTime).trim()!==``?String(t.drawTime).trim():n[0]?.lottime==null?``:String(n[0].lottime),s={terminal:i,barcode:t.barcode,lotdate:a,drawTimeHms:o,ticketTime:na(t),ticketStatus:t.ticketStatus,lines:n};r?ir(s):rr({...s,heading:`BET RECEIPT`})}async function ia(e,t,n={}){if(!t)return{ok:!1,error:`NO_USER_CODE`};let r=n.advanceOnly===!0,i=n.allowWhenLocked===!0,a=n.silentReceipt===!0;if(r){if(!K||K.length===0)return{ok:!1,error:`NO_ADVANCE_TIMES`};let t=U(e)*K.length;if(t<=0)return{ok:!1,error:`NO_BETS`};if(t>Fi)return{ok:!1,error:`INSUFFICIENT_BALANCE`}}else{if(!i){let e=Qi();if(e)return On(e),{ok:!1,error:e}}let t=U(e);if(t<=0)return{ok:!1,error:`NO_BETS`};if(t>Fi)return{ok:!1,error:`INSUFFICIENT_BALANCE`}}try{let n=localStorage.getItem(`userID`)||t;if(r){let r=K.slice();console.log(`Processing advance bets for time slots:`,r);let i=null;async function o(r){console.log(`Placing advance bet for slot:`,r);let i=Yi(e,n,{advanceOnly:!0,advanceDrawTime:r});if(console.log(`Created bet list for slot`,r,`with`,i.length,`bets`),i.length===0)return{ok:!1,errResponse:{ok:!1,error:`NO_BETS_CREATED`}};let o=Xi(r);console.log(`Parsed draw time for slot`,r,`:`,o);let s=await zt(t,o.time,i);if(console.log(`Place bet response for slot`,r,`:`,s),!s||!s.ok)return{ok:!1,errResponse:s||{ok:!1,error:`UNKNOWN_ERROR`}};let c=s.barcode!=null&&String(s.barcode).trim()!==``?String(s.barcode).trim():`—`;Lr(e,`Draw ${String(r).trim()}: bet placed. Barcode ${c}`);let l=e.querySelector(`#gs_cb_print`),u=l?l.checked:!0;return console.log(`Print checkbox checked:`,u),!a&&u&&ra(t,s,i,!0),{ok:!0,response:s}}for(let e=0;e<r.length;e+=Pr){let t=r.slice(e,e+Pr);console.log(`Processing chunk:`,t);let n=await Promise.all(t.map(e=>o(e)));for(let e of n){if(!e.ok)return console.log(`Failed result:`,e.errResponse),e.errResponse||{ok:!1,error:`UNKNOWN_ERROR`};i=e.response}}return Di(e),K=[],i||{ok:!1,error:`UNKNOWN_ERROR`}}let i=Yi(e,n,{advanceOnly:!1});if(i.length===0)return{ok:!1,error:`NO_BETS_CREATED`};let o=Ji().time,s=await zt(t,o,i);if(s&&s.ok){let n=e.querySelector(`#gs_cb_print`),r=n?n.checked:!0;return console.log(`Regular bet - Print checkbox checked:`,r),!a&&r&&ra(t,s,i,!1),Di(e),K=[],s}return s||{ok:!1,error:`UNKNOWN_ERROR`}}catch(e){return console.error(`Error placing bet:`,e),{ok:!1,error:`NETWORK_ERROR`}}finally{try{await Ii(e,t)}catch{}}}function aa(e){e.addEventListener(`focus`,()=>{e.style.backgroundColor=`#0066ff`,e.style.color=`#ffffff`}),e.addEventListener(`blur`,()=>{e.style.backgroundColor=``,e.style.color=``})}function oa(e){if(Qr(),e&&e._slideshowTeardown&&(e._slideshowTeardown(),e._slideshowTeardown=null),Xr&&=(clearInterval(Xr),null),Zr&&=(clearInterval(Zr),null),Gi(),J=null,zi=`current`,K=[],Y(),F&&=(F.destroy(),null),I&&=(I.destroy(),null),bn(),Bn(),Un(),L&&=(D(L),document.body.removeChild(L),null),z&&=(En(!1),document.body.removeChild(z),null),B&&=(document.body.removeChild(B),null),e&&e._placeChipsMsgTimer&&(clearTimeout(e._placeChipsMsgTimer),e._placeChipsMsgTimer=null),e){e._advanceChipsMsgQueue=null,e._advanceChipsMsgDrainRunning=!1;let t=e.querySelector(`.gamescreen_place_chips`);t&&(t.textContent=``)}e&&e._f5Handler&&(document.removeEventListener(`keydown`,e._f5Handler),e._f5Handler=null),e&&e._f6Handler&&(document.removeEventListener(`keydown`,e._f6Handler),e._f6Handler=null),e&&e._upcomingDrawRefresh&&(e._upcomingDrawRefresh=null)}async function sa(e,t){if(V.isBettingAllowed){if(!I){let e=vn({onAction:e=>{console.log(`Report filter action:`,e),e===`close`?I.hide():e===`show`?console.log(`Show report`):e===`print`&&console.log(`Print report`)}});I=new ln({onClose:()=>{console.log(`Report filter popup closed`)}}),I.create(e),yn(I.element.querySelector(`.popup_body`),{onAction:e=>{console.log(`Report filter action:`,e),e===`close`&&I.hide()}}),document.body.appendChild(I.element)}I.show()}}function Y(){ei&&ei.parentNode&&ei.parentNode.removeChild(ei),ei=null}function ca(e){Y();let t=Array.isArray(e.cells)?e.cells:[],n=[];for(let e=0;e<t.length;e+=2){let r=t[e],i=t[e+1];n.push(`<tr>
      <td>${kr(r?.cellID)}</td><td>${kr(r?.cv)}</td>
      <td>${i?kr(i.cellID):``}</td><td>${i?kr(i.cv):``}</td>
    </tr>`)}let r=n.join(``),i=document.createElement(`div`);i.className=`td_overlay`,i.innerHTML=`
    <div class="td_panel">
      <div class="td_title">Ticket details</div>
      <table class="td_table">
        <thead><tr>
          <th>Cell</th><th>Value</th><th>Cell</th><th>Value</th>
        </tr></thead>
        <tbody>${r}</tbody>
      </table>
      <button type="button" class="td_close">Close</button>
    </div>`,i.addEventListener(`click`,e=>{e.target===i&&Y()});let a=i.querySelector(`.td_close`);a&&a.addEventListener(`click`,()=>Y()),document.body.appendChild(i),ei=i}function la(e){if(!e||typeof e!=`string`)return null;let t=/^(\d{4})-(\d{2})-(\d{2})\s+(\d{1,2}):(\d{2})(?::(\d{2}))?/.exec(String(e).trim());return t?tn(Number(t[1]),Number(t[2]),Number(t[3]),Number(t[4]),Number(t[5]),t[6]==null?0:Number(t[6])):null}function ua(e,t){if(!e||!t)return!1;let n=la(e);if(!n)return!1;let r=C(n,S),i=C(t,S);return r.year===i.year&&r.month===i.month&&r.day===i.day&&r.hour===i.hour&&r.minute===i.minute}function da(e,t){if(!e||!t)return!1;let n=la(e);return n?n.getTime()<t.getTime():!1}function fa(e){let t=e.result==null?``:String(e.result),n=Number(e.claim),r=e.claim!=null&&e.claim!==``&&Number.isFinite(n)?n:null,i=Number(e.win),a=e.win!=null&&e.win!==``&&Number.isFinite(i)?i:null,o=e.ticketTot==null?NaN:Number(e.ticketTot),s=``;return Number.isFinite(o)?s=Math.abs(o-Math.round(o))<1e-9?String(Math.round(o)):String(o):e.play!=null&&e.play!==``&&(s=String(e.play)),{ticketId:e.ticketId==null?``:e.ticketId,barcode:e.barcode==null?``:String(e.barcode),gameId:e.gameId==null?``:e.gameId,startPoint:e.startPoint==null?``:e.startPoint,play:s,endPoint:``,drawTime:(()=>{let t=e.drawTime!=null&&String(e.drawTime).trim()!==``?String(e.drawTime).trim():``;if(t)return t;let n=e.lotdate??e.lotDate,r=e.lotTime??e.lottime;return n!=null&&r!=null?`${String(n).trim()} ${String(r).trim()}`:``})(),ticketTime:e.ticketTime==null?``:e.ticketTime,claimRaw:r,winRaw:a,_result:t}}function pa(e){if(!Array.isArray(e))return[];let t=new Map;for(let n of e){let e=n.barcode==null?``:String(n.barcode).trim(),r=e===``?`t:${n.ticketId}`:`b:${e}`;if(!t.has(r)){t.set(r,{...n});continue}let i=t.get(r);if(n.claimRaw!=null&&Number.isFinite(Number(n.claimRaw))){let e=Number(n.claimRaw),t=i.claimRaw!=null&&Number.isFinite(Number(i.claimRaw))?Number(i.claimRaw):null;i.claimRaw=t==null?e:Math.max(t,e)}if(n.winRaw!=null&&Number.isFinite(Number(n.winRaw))){let e=Number(n.winRaw),t=i.winRaw!=null&&Number.isFinite(Number(i.winRaw))?Number(i.winRaw):null;i.winRaw=t==null?e:Math.max(t,e)}}return Array.from(t.values())}function ma(e){let t=J?ni(J):null;return e.map(e=>{let n=e.claimRaw!=null&&Number.isFinite(Number(e.claimRaw))?Number(e.claimRaw):null,r=e.winRaw!=null&&Number.isFinite(Number(e.winRaw))?Number(e.winRaw):null,i=``;n!=null&&n>0?i=n.toFixed(2):r!=null&&r>0&&(i=String(r));let a=n!=null&&n>0?`true`:`false`,o=``;return o=e._result===`Cancelled`?`Cancelled`:t&&e.drawTime?ua(e.drawTime,t)?`Pending`:da(e.drawTime,t)?`Completed`:`Pending`:e._result||`Pending`,{...e,win:i,claim:a,result:o}})}function ha(){let e=_a();if(!e)return;let t=e.querySelector(`[data-action="cancel"]`);if(!t)return;if(!V.isBettingAllowed){t.disabled=!0;return}let n=F?._session?.selectedBarcode;if(!n){t.disabled=!0;return}let r=(F._allTickets||[]).find(e=>String(e.barcode)===String(n));if(!r){t.disabled=!0;return}let i=J?ni(J):null;t.disabled=!(r._result!==`Cancelled`&&i!=null&&ua(r.drawTime,i))}function ga(){let e=_a();if(!e)return;let t=!V.isBettingAllowed;e.querySelectorAll(`[data-action]`).forEach(e=>{let n=e.dataset.action;n===`close`?e.disabled=!1:n===`reprint`?e.disabled=!F?._session?.selectedBarcode:n===`allclaim`||n===`claim`||t?e.disabled=!0:e.disabled=!1});let n=e.querySelector(`#sh_show_all`),r=e.querySelector(`#sh_winning_only`);n&&(n.disabled=t),r&&(r.disabled=t),ha()}function _a(){return F?.element?F.element.querySelector(`.popup_body`)||F.element:null}function va(){if(!F)return;let e=_a();if(!e)return;let t=e.querySelector(`#sh_show_all`)?.checked??!1,n=e.querySelector(`#sh_winning_only`)?.checked??!1,r=F._allTickets||[];r=Array.isArray(r)?[...r]:[],n&&(r=r.filter(e=>e._result===`Win`));let i=J?ni(J):null;!t&&i&&(r=r.filter(e=>ua(e.drawTime,i))),hn(e,ma(r)),ga()}async function ya(){let e=_a();if(!F||!e||!F._session?.userCode)return;let t=F._session.userCode;if(mn(e,`Loading…`),!Jt().connected){F._allTickets=[],mn(e,`Not connected. Log in and wait for connection.`);return}let n=await Wt(t,{limit:5e3}),r=n&&n.ok&&Array.isArray(n.tickets)?n.tickets:[];if(n&&n.ok&&r.length===0){let e=typeof localStorage<`u`?localStorage.getItem(`userID`):null,t=e==null?``:String(e).trim();if(t&&/^\d+$/.test(t)){let e=await Wt(null,{regid:Number(t),limit:5e3});e&&e.ok&&Array.isArray(e.tickets)&&e.tickets.length>0&&(n=e,r=e.tickets)}}if(!n||!n.ok){F._allTickets=[],mn(e,n?.error===`TIMEOUT`?`Request timed out.`:n?.error===`MISSING_FIELDS`?`Missing user.`:`Could not load tickets.`);return}F._allTickets=pa(r.map(fa)),F._session&&(F._session.selectedBarcode=``),mn(e,``),va()}function ba(e,t){let n=F?._session?.root,r=F?._session?.userCode;if(F&&!(e!==`close`&&e!==`reprint`&&!V.isBettingAllowed)){if(e===`close`){Y(),F.hide();return}if(e===`select`){F._session&&(F._session.selectedBarcode=t?.barcode||``),ga();return}if(e===`filter`){va();return}if(!(!n||!r)){if(e===`result`){Y(),Sa();return}if(e===`allclaim`||e===`claim`){P(n,`Not available.`);return}if(e===`reprint`){(async()=>{let e=F._session?.selectedBarcode||``;if(!e){P(n,`Select a ticket row.`);return}let t=await Gt(r,e);if(!t||!t.ok){P(n,t?.error===`NOT_FOUND`?`Ticket not found.`:`Reprint could not load ticket.`);return}let i=sr(t,ta(r));if(!i){P(n,`Nothing to print for this ticket.`);return}let a=n.querySelector(`#gs_cb_print`),o=a?a.checked:!0;console.log(`Reprint - Print checkbox checked:`,o),o?cr(i):P(n,`Printing disabled - reprint not printed.`)})();return}if(e===`details`){(async()=>{let e=F._session?.selectedBarcode||``;if(!e){P(n,`Select a ticket row.`);return}let t=await Gt(r,e);if(!t||!t.ok){P(n,t?.error===`NOT_FOUND`?`Ticket not found.`:`Details request failed.`);return}ca(t)})();return}if(e===`cancel`){if(!V.isBettingAllowed||_a()?.querySelector(`[data-action="cancel"]`)?.disabled)return;(async()=>{let e=F._session?.selectedBarcode||``;if(!e){P(n,`Select a ticket row.`);return}let t=await Gt(r,e);if(!t||!t.ok){P(n,t?.error===`NOT_FOUND`?`Ticket not found.`:`Could not load ticket for cancel.`);return}let i=await Kt(r,e);if(P(n,i?.str||(i?.ok?`Done.`:`Cancellation failed.`)),i&&i.ok){let e=sr(t,ta(r),{heading:`TICKET CANCELLED`,ticketStatus:`Cancelled`,footerLine2:`** Ticket cancelled **`});if(e){let t=n.querySelector(`#gs_cb_print`),r=t?t.checked:!0;console.log(`Cancel receipt - Print checkbox checked:`,r),r?cr(e):P(n,`Printing disabled - cancel receipt not printed.`)}await ya(),await Ii(n,r)}})();return}}}}async function xa(e,t){if(!F){let e=fn({onAction:()=>{}});F=new ln({onClose:()=>{Y()}}),F.create(e),pn(F.element.querySelector(`.popup_body`),{onAction:(e,t)=>ba(e,t),isBetLocked:()=>!V.isBettingAllowed}),document.body.appendChild(F.element)}F._session={userCode:t,root:e,selectedBarcode:``},F.show(),await ya(),ga()}async function Sa(){if(!R){let e=qn();R=new ln({onClose:()=>{console.log(`Result popup closed`);let e=document.querySelector(`.result_calendar_picker`);e&&e.remove()}}),R.create(e),Jn(R.element.querySelector(`.popup_body`),{onAction:e=>{e===`close`&&R.hide()},onShow:async({date:e,stone:t})=>{await Ca(e,t)}}),document.body.appendChild(R.element)}R.show(),await Ca(``,`PR`)}async function Ca(e,t){if(!R)return;let n=await Vt(``);if(!n||!n.ok){Yn(R.element,[]);return}let r=(Array.isArray(n.results)?n.results:[]).filter(e=>Wr(Hr(e.lotTime??e.lottime))===t).map(e=>{let t=Hr(e.lotTime??e.lottime);return{drawTime:t,result:`${Wr(t)} ${Ur(e.cellID)}`.trim()}});Yn(R.element,r)}function wa(e,t={}){if(!t.skipBettingCheck&&!V.isBettingAllowed)return;let n=t.userCode||e?._deluxUserCode||``,r=()=>{let e=Ar(N);return J?jr(e,J):e};In(e,r(),J,t=>{let r=Array.isArray(t)?t:[];if(K=r,console.log(`Selected future draw times:`,K),r.length===0){P(e,`Select at least one draw time, then Confirm.`);return}(async()=>{let t=await ia(e,n,{advanceOnly:!0});if(!t||!t.ok){let n=t?.error||`UNKNOWN_ERROR`;n===`BETTING_LOCKED`&&Dn(),P(e,ea(n))}})()}),e._upcomingDrawRefresh=()=>{let t=r();upcomingDrawPopup&&upcomingDrawPopup.element&&In(e,t,J,t=>{let r=Array.isArray(t)?t:[];if(K=r,r.length===0){P(e,`Select at least one draw time, then Confirm.`);return}(async()=>{let t=await ia(e,n,{advanceOnly:!0});if(!t||!t.ok){let n=t?.error||`UNKNOWN_ERROR`;n===`BETTING_LOCKED`&&Dn(),P(e,ea(n))}})()})}}function Ta(e,t,n={}){let r=n.reveal===!0;if(!r&&!V.isBettingAllowed)return;V.popupTimeoutId&&(clearTimeout(V.popupTimeoutId),V.popupTimeoutId=null),V.afterLuckyPickDismiss=typeof n.onAfterDismiss==`function`?n.onAfterDismiss:null;let i=qi(),a=t||{date:i.date||`—`,time:rn(i.time)||i.time||`—`,drawTime:rn(i.time)||i.time||`—`,result:`—`,drawType:`Result`};L&&D(L);let o=Mn({data:a,reveal:r});if(L||(L=document.createElement(`div`),L.className=`lp_overlay`,document.body.appendChild(L)),L.innerHTML=o,Pn(L,{onAction:e=>{console.log(`Lucky pick action:`,e),e===`close`&&(D(L),V.popupTimeoutId&&(clearTimeout(V.popupTimeoutId),V.popupTimeoutId=null),L.classList.remove(`lp_overlay--visible`),document.body.style.overflow=``,V.isPopupShowing=!1,li())}}),L.classList.add(`lp_overlay--visible`),document.body.style.overflow=`hidden`,r){let e=a.result||`—`,t=a.drawTime||null;Nn(L,e,2800,()=>{ui(3200)},t)}else ui(3e3)}function Ea(e,{onAction:t,sessionUser:n}){Qr(),$r(e),Yr=()=>$r(e),window.addEventListener(`resize`,Yr),hi(),zi=`current`,K=[];let r=n?.userCode||n?.id||`dev`;e._deluxUserCode=r,Ii(e,r),qr(e),Gr(e);let i=e.querySelector(`.gamescreen_slideshow_host`);i&&(e._slideshowTeardown&&=(e._slideshowTeardown(),null),e._slideshowTeardown=Or(i));let a=e.querySelector(`#gs_cb_print`),o=e.querySelector(`#gs_cb_ac`);a&&(a.disabled=!1,a.checked=!0),o&&(o.disabled=!1,o.checked=!0,o.addEventListener(`change`,e=>{console.log(`AC checkbox changed:`,e.target.checked)}));async function s(){let t=await Ki(),n=e.querySelector(`.gamescreen_date_box`);n&&t.date&&(n.textContent=t.date);let r=e.querySelector(`.gamescreen_clock`);r&&t.time&&(r.textContent=t.time),t.utcMs!=null&&(J=new Date(Number(t.utcMs))),Wi(e)}s(),Zr=setInterval(s,1e3);let c=e.querySelectorAll(`.gamescreen_pr_row`);c.forEach((t,n)=>{t.querySelectorAll(`.gamescreen_pr_input`).forEach((t,r)=>{aa(t),t.addEventListener(`input`,t=>{if(!Bi())return;let i=mi(t.target.value),a=Si(n,r);H.baseValues[a]=vi(i),t.target.value=i,Ei(e)}),t.addEventListener(`keydown`,n=>{switch(n.key){case`ArrowUp`:n.preventDefault(),W(e,t,`up`);break;case`ArrowDown`:n.preventDefault(),W(e,t,`down`);break;case`ArrowLeft`:n.preventDefault(),W(e,t,`left`);break;case`ArrowRight`:n.preventDefault(),W(e,t,`right`);break}})})}),c.forEach((t,n)=>{let r=t.querySelector(`.gamescreen_all_input`);r&&(aa(r),r.addEventListener(`input`,t=>{if(!Bi())return;let i=mi(t.target.value);t.target.value=i,H.allA[n]=fi(r),Ei(e)}),r.addEventListener(`keydown`,t=>{switch(t.key){case`ArrowUp`:case`ArrowDown`:case`ArrowLeft`:case`ArrowRight`:t.preventDefault(),W(e,r,t.key.replace(`Arrow`,``).toLowerCase());break}}))});let l=e.querySelector(`.gamescreen_allb_row`);l&&l.querySelectorAll(`.gamescreen_all_input`).forEach((t,n)=>{aa(t),t.addEventListener(`input`,r=>{if(!Bi())return;let i=mi(r.target.value);r.target.value=i,H.allB[n]=fi(t),Ei(e)}),t.addEventListener(`keydown`,n=>{switch(n.key){case`ArrowUp`:case`ArrowDown`:case`ArrowLeft`:case`ArrowRight`:n.preventDefault(),W(e,t,n.key.replace(`Arrow`,``).toLowerCase());break}})});let u=e.querySelector(`.gamescreen_allc_row`);u&&u.querySelectorAll(`.gamescreen_all_input`).forEach((t,n)=>{aa(t),t.addEventListener(`input`,r=>{if(!Bi())return;let i=mi(r.target.value);r.target.value=i,H.allC[n]=fi(t),Ei(e)}),t.addEventListener(`keydown`,n=>{switch(n.key){case`ArrowUp`:case`ArrowDown`:case`ArrowLeft`:case`ArrowRight`:n.preventDefault(),W(e,t,n.key.replace(`Arrow`,``).toLowerCase());break}})});let d=e.querySelector(`.gamescreen_fbtn--cyan`);d&&d.textContent.includes(`F5-Clear`)&&d.addEventListener(`click`,()=>{Di(e)});let f=t=>{t.key===`F5`&&(t.preventDefault(),Di(e))};document.addEventListener(`keydown`,f),e._f5Handler=f;let p=e.querySelector(`.gamescreen_lucky_input`);p&&(aa(p),p.addEventListener(`input`,e=>{let t=e.target.value.replace(/\D/g,``);t.length>2&&(t=t.slice(0,2)),t!==``&&parseInt(t,10)>99&&(t=`99`),e.target.value=t}),p.addEventListener(`keypress`,e=>{!/\d/.test(e.key)&&![`Backspace`,`Delete`,`Tab`,`Enter`,`ArrowLeft`,`ArrowRight`].includes(e.key)&&e.preventDefault()}),p.addEventListener(`paste`,e=>{e.preventDefault();let t=(e.clipboardData||window.clipboardData).getData(`text`).replace(/\D/g,``).slice(0,2);e.target.value=t}));let m=e.querySelector(`.gamescreen_fbtn--buy`);m&&m.addEventListener(`click`,async()=>{if(q()){P(e,`Upcoming bets: choose chips, tap Upcoming, pick draw times, then Confirm.`);return}let t=Qi();if(t){On(t),P(e,$i(t));return}let n=m.textContent;m.textContent=`Placing Bet...`,m.disabled=!0;try{let t=K.length,n=await ia(e,r);if(n&&n.ok)P(e,t>0?`Bet placed successfully for current draw + ${t} future draw(s).`:`Bet placed successfully.`);else{let t=n?.error||`Unknown error`;t===`BETTING_LOCKED`&&Dn(),P(e,ea(t))}}catch(t){console.error(`Error in bet placement:`,t),P(e,`An error occurred while placing the bet.`)}finally{m.textContent=n,q()?m.disabled=!0:m.disabled=!1}});let ee=t=>{if(t.key===`F6`){if(t.preventDefault(),q()){P(e,`Upcoming bets: choose chips, tap Upcoming, pick draw times, then Confirm.`);return}let n=Qi();if(n){On(n),P(e,$i(n));return}m&&m.click()}};document.addEventListener(`keydown`,ee),e._f6Handler=ee,e.querySelectorAll(`[data-gamescreen-action]`).forEach(n=>{n.addEventListener(`click`,()=>{let i=n.dataset.gamescreenAction;i===`purchase-details`?sa(e,r):i===`stone-report`?xa(e,r):i===`lucky-pick`?Oi(e):i===`change-password`?Vn(r,Ft(),(t,n)=>{t===`success`?P(e,`Password changed successfully!`):t===`error`&&P(e,n?.message||`Failed to change password`)}):i===`last-receipt`?(async()=>{if(!Jt().connected){P(e,`Not connected to server.`);return}let t=await Ut(r);if(!t||t.ok!==!0){P(e,t?.error===`TIMEOUT`?`Last receipt request timed out.`:`Could not load last receipt.`);return}if(!t.hasReceipt){P(e,`No receipt to print.`);return}let n=e.querySelector(`#gs_cb_print`),i=n?n.checked:!0;console.log(`Last receipt - Print checkbox checked:`,i),i?lr(t,{terminal:ta(r)}):P(e,`Printing disabled - receipt not printed.`)})():t(i)})});let te=e.querySelector(`#gs_toggle_current`),ne=e.querySelector(`#gs_toggle_upcoming`),h=e.querySelector(`#gamescreen_pr_block`),re=e.querySelector(`#gamescreen_draw_closed`);te&&ne&&h&&re&&(te.addEventListener(`click`,()=>{Vi(e,`current`),h.style.display=`flex`,re.style.display=`none`}),ne.addEventListener(`click`,()=>{Vi(e,`advance`),h.style.display=`flex`,re.style.display=`none`,wa(e,{skipBettingCheck:!0,userCode:r})}))}async function Da(){try{let e=typeof window<`u`?window.electronAPI:null;if(e&&typeof e.closeApp==`function`){await e.closeApp();return}}catch{}typeof window<`u`&&window.close()}var Oa=document.querySelector(`#app`),ka=``,Aa=``,ja=`deluxAuth`;function Ma(){try{let e=localStorage.getItem(ja);if(!e)return null;let t=JSON.parse(e);return t&&typeof t==`object`?t:null}catch{return null}}function Na(e,t,n){try{localStorage.setItem(ja,JSON.stringify({pin:e||``,password:t||``,sessionUser:n||null}))}catch{}}function Pa(){Q=null,Na(Z,Ia,null);try{localStorage.removeItem(`userID`)}catch{}}var Fa=Ma(),X=`offline`,Z=Fa?.pin||ka,Ia=Fa?.password||Aa,La=``,Ra=``,Q=null;function za(e){return{INVALID_CREDENTIALS:`Invalid user code or password.`,MISSING_FIELDS:`Enter user code and password.`,NOT_CONNECTED:`Not connected to server.`,TIMEOUT:`Login timed out.`,SERVER_ERROR:`Server error. Try again.`,DB_ACCESS_DENIED:`Database rejected the app login. Run the API on the database machine (localhost/socket) or allow remote MySQL for this app user.`}[e]||`Login failed.`}function Ba(e){return e&&e.message===`CONNECT_TIMEOUT`?`Connection timed out.`:`Could not reach server.`}function $(){on();let e=Oa.querySelector(`.app_shell`);e?.querySelector(`.gamescreen_wrap`)&&oa(e),Oa.innerHTML=`<div class="app_shell">${X===`offline`?n({connectError:La}):X===`online`?i():X===`login`?sn({pin:Z,password:Ia,loginError:Ra}):Jr({sessionUser:Q})}</div>`,Va()}function Va(){let e=Oa.querySelector(`.app_shell`);e&&(X!==`game`&&Qr(),X===`offline`&&r(e,{async onAction(e){if(e===`connect`){La=``,$();try{await It(),X=`online`}catch{La=Ba()}$()}e===`power-off`&&await Da()}}),X===`online`&&a(e,{async onAction(e){e===`disconnect`&&(Lt(),X=`offline`,$()),e===`login-screen`&&(Ra=``,X=`login`,$()),e===`power-off`&&await Da()}}),X===`login`&&cn(e,{async onAction(e){if(e===`enter-dashboard`){Ra=``;let e=await Rt(Z,Ia);e&&e.ok?(Q=e.user||null,Q&&localStorage.setItem(`userID`,Q.id||Q.userCode||Z),Na(Z,Ia,Q),X=`game`):Ra=za(e&&e.error),$()}e===`back-to-connect`&&(Ra=``,X=`online`,$())},onPinInput(e){Z=e,Na(Z,Ia,Q)},onPasswordInput(e){Ia=e,Na(Z,Ia,Q)}}),X===`game`&&Ea(e,{sessionUser:Q,onAction(e){e===`exit-offline`&&(Pa(),Ra=``,La=``,Lt(),X=`offline`,$())}}))}async function Ha(){kn(),$()}Ha();