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.5</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 h;function g(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=>{h||=new TextEncoder,t(h.encode(e))})}var ee=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,_=typeof Uint8Array>`u`?[]:new Uint8Array(256);for(let e=0;e<64;e++)_[ee.charCodeAt(e)]=e;var te=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=_[e.charCodeAt(r)],o=_[e.charCodeAt(r+1)],s=_[e.charCodeAt(r+2)],c=_[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},ne=typeof ArrayBuffer==`function`,re=(e,t)=>{if(typeof e!=`string`)return{type:`message`,data:ae(e,t)};let n=e.charAt(0);return n===`b`?{type:`message`,data:ie(e.substring(1),t)}:s[n]?e.length>1?{type:s[n],data:e.substring(1)}:{type:s[n]}:c},ie=(e,t)=>ne?ae(te(e),t):{base64:!0,data:e},ae=(e,t)=>{switch(t){case`blob`:return e instanceof Blob?e:new Blob([e]);default:return e instanceof ArrayBuffer?e:e.buffer}},oe=``,se=(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(oe))})})},ce=(e,t)=>{let n=e.split(oe),r=[];for(let e=0;e<n.length;e++){let i=re(n[e],t);if(r.push(i),i.type===`error`)break}return r};function le(){return new TransformStream({transform(e,t){g(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 ue;function de(e){return e.reduce((e,t)=>e+t.length,0)}function fe(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 pe(e,t){ue||=new TextDecoder;let n=[],r=0,i=-1,a=!1;return new TransformStream({transform(o,s){for(n.push(o);;){if(r===0){if(de(n)<1)break;let e=fe(n,1);a=(e[0]&128)==128,i=e[0]&127,r=i<126?3:i===126?1:2}else if(r===1){if(de(n)<2)break;let e=fe(n,2);i=new DataView(e.buffer,e.byteOffset,e.length).getUint16(0),r=3}else if(r===2){if(de(n)<8)break;let e=fe(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(de(n)<i)break;let e=fe(n,i);s.enqueue(re(a?e:ue.decode(e),t)),r=0}if(i===0||i>e){s.enqueue(c);break}}}})}function v(e){if(e)return me(e)}function me(e){for(var t in v.prototype)e[t]=v.prototype[t];return e}v.prototype.on=v.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks[`$`+e]=this._callbacks[`$`+e]||[]).push(t),this},v.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},v.prototype.off=v.prototype.removeListener=v.prototype.removeAllListeners=v.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},v.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},v.prototype.emitReserved=v.prototype.emit,v.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks[`$`+e]||[]},v.prototype.hasListeners=function(e){return!!this.listeners(e).length};var he=typeof Promise==`function`&&typeof Promise.resolve==`function`?e=>Promise.resolve().then(e):(e,t)=>t(e,0),y=typeof self<`u`?self:typeof window<`u`?window:Function(`return this`)(),ge=`arraybuffer`;function _e(e,...t){return t.reduce((t,n)=>(e.hasOwnProperty(n)&&(t[n]=e[n]),t),{})}var ve=y.setTimeout,ye=y.clearTimeout;function be(e,t){t.useNativeTimers?(e.setTimeoutFn=ve.bind(y),e.clearTimeoutFn=ye.bind(y)):(e.setTimeoutFn=y.setTimeout.bind(y),e.clearTimeoutFn=y.clearTimeout.bind(y))}var xe=1.33;function Se(e){return typeof e==`string`?Ce(e):Math.ceil((e.byteLength||e.size)*xe)}function Ce(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 we(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function Te(e){let t=``;for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+=`&`),t+=encodeURIComponent(n)+`=`+encodeURIComponent(e[n]));return t}function Ee(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 De=class extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type=`TransportError`}},Oe=class extends v{constructor(e){super(),this.writable=!1,be(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 De(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=re(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=Te(e);return t.length?`?`+t:``}},ke=class extends Oe{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){ce(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,se(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]=we()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}},Ae=!1;try{Ae=typeof XMLHttpRequest<`u`&&`withCredentials`in new XMLHttpRequest}catch{}var je=Ae;function Me(){}var Ne=class extends ke{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}},Pe=class e extends v{constructor(e,t,n){super(),this.createRequest=e,be(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=_e(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=Me,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(Pe.requestsCount=0,Pe.requests={},typeof document<`u`){if(typeof attachEvent==`function`)attachEvent(`onunload`,Fe);else if(typeof addEventListener==`function`){let e=`onpagehide`in y?`pagehide`:`unload`;addEventListener(e,Fe,!1)}}function Fe(){for(let e in Pe.requests)Pe.requests.hasOwnProperty(e)&&Pe.requests[e].abort()}var Ie=(function(){let e=Re({xdomain:!1});return e&&e.responseType!==null})(),Le=class extends Ne{constructor(e){super(e);let t=e&&e.forceBase64;this.supportsBinary=Ie&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new Pe(Re,this.uri(),e)}};function Re(e){let t=e.xdomain;try{if(typeof XMLHttpRequest<`u`&&(!t||je))return new XMLHttpRequest}catch{}if(!t)try{return new y[[`Active`,`Object`].join(`X`)](`Microsoft.XMLHTTP`)}catch{}}var ze=typeof navigator<`u`&&typeof navigator.product==`string`&&navigator.product.toLowerCase()===`reactnative`,Be=class extends Oe{get name(){return`websocket`}doOpen(){let e=this.uri(),t=this.opts.protocols,n=ze?{}:_e(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&&he(()=>{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]=we()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}},Ve=y.WebSocket||y.MozWebSocket,He={websocket:class extends Be{createSocket(e,t,n){return ze?new Ve(e,t,n):t?new Ve(e,t):new Ve(e)}doWrite(e,t){this.ws.send(t)}},webtransport:class extends Oe{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=pe(2**53-1,this.socket.binaryType),n=e.readable.pipeThrough(t).getReader(),r=le();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&&he(()=>{this.writable=!0,this.emitReserved(`drain`)},this.setTimeoutFn)})}}doClose(){var e;(e=this._transport)==null||e.close()}},polling:Le},Ue=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,We=[`source`,`protocol`,`authority`,`userInfo`,`user`,`password`,`host`,`port`,`relative`,`path`,`directory`,`file`,`query`,`anchor`];function Ge(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=Ue.exec(e||``),a={},o=14;for(;o--;)a[We[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=Ke(a,a.path),a.queryKey=qe(a,a.query),a}function Ke(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 qe(e,t){let n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(e,t,r){t&&(n[t]=r)}),n}var Je=typeof addEventListener==`function`&&typeof removeEventListener==`function`,Ye=[];Je&&addEventListener(`offline`,()=>{Ye.forEach(e=>e())},!1);var Xe=class e extends v{constructor(e,t){if(super(),this.binaryType=ge,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=Ge(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=Ge(t.host).host);be(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=Ee(this.opts.query)),Je&&(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`})},Ye.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+=Se(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,he(()=>{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(),Je&&(this._beforeunloadEventListener&&removeEventListener(`beforeunload`,this._beforeunloadEventListener,!1),this._offlineEventListener)){let e=Ye.indexOf(this._offlineEventListener);e!==-1&&Ye.splice(e,1)}this.readyState=`closed`,this.id=null,this.emitReserved(`close`,e,t),this.writeBuffer=[],this._prevBufferLen=0}}};Xe.protocol=4;var Ze=class extends Xe{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;Xe.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;Xe.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}},Qe=class extends Ze{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=>He[e]).filter(e=>!!e)),super(e,n)}};Qe.protocol;function $e(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=Ge(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 et=typeof ArrayBuffer==`function`,tt=e=>typeof ArrayBuffer.isView==`function`?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,nt=Object.prototype.toString,rt=typeof Blob==`function`||typeof Blob<`u`&&nt.call(Blob)===`[object BlobConstructor]`,it=typeof File==`function`||typeof File<`u`&&nt.call(File)===`[object FileConstructor]`;function at(e){return et&&(e instanceof ArrayBuffer||tt(e))||rt&&e instanceof Blob||it&&e instanceof File}function ot(e,t){if(!e||typeof e!=`object`)return!1;if(Array.isArray(e)){for(let t=0,n=e.length;t<n;t++)if(ot(e[t]))return!0;return!1}if(at(e))return!0;if(e.toJSON&&typeof e.toJSON==`function`&&arguments.length===1)return ot(e.toJSON(),!0);for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t)&&ot(e[t]))return!0;return!1}function st(e){let t=[],n=e.data,r=e;return r.data=ct(n,t),r.attachments=t.length,{packet:r,buffers:t}}function ct(e,t){if(!e)return e;if(at(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]=ct(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]=ct(e[r],t));return n}return e}function lt(e,t){return e.data=ut(e.data,t),delete e.attachments,e}function ut(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]=ut(e[n],t);else if(typeof e==`object`)for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(e[n]=ut(e[n],t));return e}var dt=t({Decoder:()=>mt,Encoder:()=>pt,PacketType:()=>b,isPacketValid:()=>xt,protocol:()=>5}),ft=[`connect`,`connect_error`,`disconnect`,`disconnecting`,`newListener`,`removeListener`],b;(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`})(b||={});var pt=class{constructor(e){this.replacer=e}encode(e){return(e.type===b.EVENT||e.type===b.ACK)&&ot(e)?this.encodeAsBinary({type:e.type===b.EVENT?b.BINARY_EVENT:b.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let t=``+e.type;return(e.type===b.BINARY_EVENT||e.type===b.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=st(e),n=this.encodeAsString(t.packet),r=t.buffers;return r.unshift(n),r}},mt=class e extends v{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===b.BINARY_EVENT;n||t.type===b.BINARY_ACK?(t.type=n?b.EVENT:b.ACK,this.reconstructor=new ht(t),t.attachments===0&&super.emitReserved(`decoded`,t)):super.emitReserved(`decoded`,t)}else if(at(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(b[r.type]===void 0)throw Error(`unknown packet type `+r.type);if(r.type===b.BINARY_EVENT||r.type===b.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(!_t(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 b.CONNECT:return yt(t);case b.DISCONNECT:return t===void 0;case b.CONNECT_ERROR:return typeof t==`string`||yt(t);case b.EVENT:case b.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]==`number`||typeof t[0]==`string`&&ft.indexOf(t[0])===-1);case b.ACK:case b.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&=(this.reconstructor.finishedReconstruction(),null)}},ht=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=lt(this.reconPack,this.buffers);return this.finishedReconstruction(),e}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};function gt(e){return typeof e==`string`}var _t=Number.isInteger||function(e){return typeof e==`number`&&isFinite(e)&&Math.floor(e)===e};function vt(e){return e===void 0||_t(e)}function yt(e){return Object.prototype.toString.call(e)===`[object Object]`}function bt(e,t){switch(e){case b.CONNECT:return t===void 0||yt(t);case b.DISCONNECT:return t===void 0;case b.EVENT:return Array.isArray(t)&&(typeof t[0]==`number`||typeof t[0]==`string`&&ft.indexOf(t[0])===-1);case b.ACK:return Array.isArray(t);case b.CONNECT_ERROR:return typeof t==`string`||yt(t);default:return!1}}function xt(e){return gt(e.nsp)&&vt(e.id)&&bt(e.type,e.data)}function x(e,t,n){return e.on(t,n),function(){e.off(t,n)}}var St=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),Ct=class extends v{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=[x(e,`open`,this.onopen.bind(this)),x(e,`packet`,this.onpacket.bind(this)),x(e,`error`,this.onerror.bind(this)),x(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(St.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:b.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:b.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 b.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 b.EVENT:case b.BINARY_EVENT:this.onevent(e);break;case b.ACK:case b.BINARY_ACK:this.onack(e);break;case b.DISCONNECT:this.ondisconnect();break;case b.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:b.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:b.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 wt(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}wt.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},wt.prototype.reset=function(){this.attempts=0},wt.prototype.setMin=function(e){this.ms=e},wt.prototype.setMax=function(e){this.max=e},wt.prototype.setJitter=function(e){this.jitter=e};var Tt=class extends v{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,be(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 wt({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||dt;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 Qe(this.uri,this.opts);let t=this.engine,n=this;this._readyState=`opening`,this.skipReconnect=!1;let r=x(t,`open`,function(){n.onopen(),e&&e()}),i=t=>{this.cleanup(),this._readyState=`closed`,this.emitReserved(`error`,t),e?e(t):this.maybeReconnectOnOpen()},a=x(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(x(e,`ping`,this.onping.bind(this)),x(e,`data`,this.ondata.bind(this)),x(e,`error`,this.onerror.bind(this)),x(e,`close`,this.onclose.bind(this)),x(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){he(()=>{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 Ct(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)}},Et={};function Dt(e,t){typeof e==`object`&&(t=e,e=void 0),t||={};let n=$e(e,t.path||`/socket.io`),r=n.source,i=n.id,a=n.path,o=Et[i]&&a in Et[i].nsps,s=t.forceNew||t[`force new connection`]||!1===t.multiplex||o,c;return s?c=new Tt(r,t):(Et[i]||(Et[i]=new Tt(r,t)),c=Et[i]),n.query&&!t.query&&(t.query=n.queryKey),c.socket(n.path,t)}Object.assign(Dt,{Manager:Tt,Socket:Ct,io:Dt,connect:Dt});var Ot=`deluxInstallDeviceId`;function kt(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`d-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,14)}`}function At(){try{let e=localStorage.getItem(Ot);return(!e||String(e).trim()===``)&&(e=kt(),localStorage.setItem(Ot,e)),String(e).trim().slice(0,64)}catch{return kt().slice(0,64)}}var jt=`[delux_socket_client]`,S=null;function Mt(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(Mt);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]=Mt(r):t[n]=r;return t}function C(e,t,n){let r=Mt(n),i=r===void 0?``:` ${JSON.stringify(r)}`;console.log(`${jt} ${e} evt=${t}${i}`)}function Nt(e){if(e)try{e.disconnect()}catch{}}function Pt(e){e.onAny((e,...t)=>{C(`IN`,e,t.length===0?void 0:t.length===1?t[0]:t)}),e.on(`connect`,()=>{C(`CONN`,`socket_connect`,{id:e.id})}),e.on(`disconnect`,e=>{C(`DISC`,`socket_disconnect`,{reason:e})}),e.on(`connect_error`,e=>{C(`ERR`,`socket_connect_error`,{message:e?.message})})}function Ft(){return`http://68.178.166.16:5677`}function It(){return Ft()}async function Lt(){let e=Ft();return S?.connected?S:(S&&=(Nt(S),null),C(`OPEN`,`io`,{url:e}),S=Dt(e,{transports:[`websocket`,`polling`],reconnection:!0,reconnectionAttempts:10,reconnectionDelay:1e3}),Pt(S),new Promise((e,t)=>{let n=setTimeout(()=>{t(Error(`CONNECT_TIMEOUT`))},15e3);S.once(`connect`,()=>{clearTimeout(n),e(S)}),S.once(`connect_error`,e=>{clearTimeout(n),Nt(S),S=null,t(e)})}))}function Rt(){S&&=(C(`CLOSE`,`disconnectDeluxSocket`,{}),Nt(S),null)}async function zt(e,t){if(!S?.connected)return C(`SKIP`,`delux_login`,{ok:!1,error:`NOT_CONNECTED`}),{ok:!1,error:`NOT_CONNECTED`};let n=At();return C(`OUT`,`delux_login`,{userCode:e,password:t,deviceId:n}),new Promise(r=>{let i=setTimeout(()=>{S.off(`delux_login_response`,a),C(`ERR`,`delux_login_timeout`,{error:`TIMEOUT`}),r({ok:!1,error:`TIMEOUT`})},15e3);function a(e){clearTimeout(i),r(e)}S.once(`delux_login_response`,a),S.emit(`delux_login`,{userCode:e,password:t,deviceId:n})})}async function Bt(e,t,n){return S?.connected?(C(`OUT`,`delux_place_bet`,{userCode:e,drawTime:t,betListArray:n}),new Promise(r=>{let i=setTimeout(()=>{S.off(`delux_place_bet_response`,a),C(`ERR`,`delux_place_bet_timeout`,{error:`TIMEOUT`}),r({ok:!1,error:`TIMEOUT`})},15e3);function a(e){clearTimeout(i),r(e)}S.once(`delux_place_bet_response`,a),S.emit(`delux_place_bet`,{userCode:e,drawTime:t,mainbetarray:n})})):(C(`SKIP`,`delux_place_bet`,{ok:!1,error:`NOT_CONNECTED`}),{ok:!1,error:`NOT_CONNECTED`})}async function Vt(e){return S?.connected?(C(`OUT`,`delux_get_balance`,{userCode:e}),new Promise(t=>{let n=setTimeout(()=>{S.off(`delux_get_balance_response`,r),C(`ERR`,`delux_get_balance_timeout`,{error:`TIMEOUT`}),t({ok:!1,error:`TIMEOUT`})},15e3);function r(e){clearTimeout(n),t(e)}S.once(`delux_get_balance_response`,r),S.emit(`delux_get_balance`,{userCode:e})})):(C(`SKIP`,`delux_get_balance`,{ok:!1,error:`NOT_CONNECTED`}),{ok:!1,error:`NOT_CONNECTED`})}async function Ht(e,t){if(!S?.connected)return C(`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()),C(`OUT`,`delux_get_result_history`,n),new Promise(e=>{let t=setTimeout(()=>{S.off(`delux_get_result_history_response`,r),C(`ERR`,`delux_get_result_history_timeout`,{error:`TIMEOUT`}),e({ok:!1,error:`TIMEOUT`})},15e3);function r(n){clearTimeout(t),e(n)}S.once(`delux_get_result_history_response`,r),S.emit(`delux_get_result_history`,n)})}async function Ut(){return S?.connected?(C(`OUT`,`delux_get_winning_number`,{}),new Promise(e=>{let t=setTimeout(()=>{S.off(`delux_get_winning_number_response`,n),C(`ERR`,`delux_get_winning_number_timeout`,{error:`TIMEOUT`}),e({ok:!1,error:`TIMEOUT`})},15e3);function n(n){clearTimeout(t),e(n)}S.once(`delux_get_winning_number_response`,n),S.emit(`delux_get_winning_number`,{})})):(C(`SKIP`,`delux_get_winning_number`,{ok:!1,error:`NOT_CONNECTED`}),{ok:!1,error:`NOT_CONNECTED`})}async function Wt(e){if(!S?.connected)return C(`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?(C(`OUT`,`delux_get_last_bet_receipt`,{userCode:t}),new Promise(e=>{let n=setTimeout(()=>{S.off(`delux_get_last_bet_receipt_response`,r),C(`ERR`,`delux_get_last_bet_receipt_timeout`,{error:`TIMEOUT`}),e({ok:!1,error:`TIMEOUT`})},15e3);function r(t){clearTimeout(n),e(t)}S.once(`delux_get_last_bet_receipt_response`,r),S.emit(`delux_get_last_bet_receipt`,{userCode:t})})):(C(`SKIP`,`delux_get_last_bet_receipt`,{ok:!1,error:`MISSING_FIELDS`}),{ok:!1,error:`MISSING_FIELDS`})}async function Gt(e,t={}){if(!S?.connected)return C(`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 C(`SKIP`,`delux_get_user_tickets`,{ok:!1,error:`MISSING_FIELDS`}),{ok:!1,error:`MISSING_FIELDS`};let i=n;return C(`OUT`,`delux_get_user_tickets`,i),new Promise(e=>{let t=setTimeout(()=>{S.off(`delux_get_user_tickets_response`,n),C(`ERR`,`delux_get_user_tickets_timeout`,{error:`TIMEOUT`}),e({ok:!1,error:`TIMEOUT`})},3e4);function n(n){clearTimeout(t),e(n)}S.once(`delux_get_user_tickets_response`,n),S.emit(`delux_get_user_tickets`,i)})}async function Kt(e,t){let n=It();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 qt(e,t){let n=It();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 Jt(e,t,n){if(!S?.connected)return C(`SKIP`,`lottery_ws_getCounterSale`,{ok:!1,error:`NOT_CONNECTED`}),{ok:!1,error:`NOT_CONNECTED`};let r=e==null?``:String(e).trim(),i=t==null?``:String(t).trim(),a=n==null?``:String(n).trim();return!r||!i||!a?(C(`SKIP`,`lottery_ws_getCounterSale`,{ok:!1,error:`MISSING_FIELDS`}),{ok:!1,error:`MISSING_FIELDS`}):(C(`OUT`,`lottery_ws_getCounterSale`,{userCode:r,fromDate:i,toDate:a}),new Promise(e=>{let t=setTimeout(()=>{S.off(`lottery_ws_getCounterSale_response`,n),C(`ERR`,`lottery_ws_getCounterSale_timeout`,{error:`TIMEOUT`}),e({ok:!1,error:`TIMEOUT`})},3e4);function n(n){clearTimeout(t),e(n)}S.once(`lottery_ws_getCounterSale_response`,n),S.emit(`lottery_ws_getCounterSale`,r,i,a)}))}async function Yt(e,t){return S?.connected?(C(`OUT`,`delux_check_user_winning`,{userCode:e,lottime:t}),new Promise(n=>{let r=setTimeout(()=>{S.off(`delux_check_user_winning_response`,i),C(`ERR`,`delux_check_user_winning_timeout`,{error:`TIMEOUT`}),n({ok:!1,error:`TIMEOUT`})},15e3);function i(e){clearTimeout(r),n(e)}S.once(`delux_check_user_winning_response`,i),S.emit(`delux_check_user_winning`,{userCode:e,lottime:t})})):(C(`SKIP`,`delux_check_user_winning`,{ok:!1,error:`NOT_CONNECTED`}),{ok:!1,error:`NOT_CONNECTED`})}function Xt(){return{exists:!!S,connected:S?.connected||!1,id:S?.id||null}}var w=`Asia/Kolkata`,Zt=[`JAN`,`FEB`,`MAR`,`APR`,`MAY`,`JUN`,`JUL`,`AUG`,`SEP`,`OCT`,`NOV`,`DEC`],Qt=null;function $t(e){return e&&e.utcMs!=null&&Number.isFinite(Number(e.utcMs))?(Qt=Number(e.utcMs),!0):!1}function en(){return Qt}function tn(){return Qt==null?null:new Date(Qt)}function nn(){let e=tn();return e?new Date(e.getTime()):new Date(0)}function T(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 rn(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 an(e){let t=T(e,w);return{date:`${Zt[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 on(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 sn=null;function cn(){sn&&=(clearInterval(sn),null)}function ln({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 un(e,{onAction:t,onPinInput:n,onPasswordInput:r}){let i=It(),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&&$t(t),a&&t.date&&(a.textContent=t.date),o&&t.time&&(o.textContent=t.time)}catch{a&&(a.textContent=`—`),o&&(o.textContent=`—:—:—`)}}s(),sn=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 dn=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 E(e){return e==null?``:String(e).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/"/g,`&quot;`)}var fn=[`Barcode`,`Game ID`,`Start Point`,`Play`,`Win`,`End Point`,`Claim`,`Result`,`Draw Time`,`Ticket Time`],pn=[{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 mn({onAction:e}){return`
    <div class="sh_wrapper">
      <div class="sh_table_section">
        <table class="sh_table">
          <thead class="sh_table_head">
            <tr>${fn.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">
          ${pn.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 hn(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 gn(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">${E(t)}</td></tr>`}}function _n(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="${E(e.ticketId)}" data-barcode="${E(e.barcode)}">
      <td class="sh_table_cell">${E(e.barcode)}</td>
      <td class="sh_table_cell">${E(e.gameId)}</td>
      <td class="sh_table_cell">${E(e.startPoint)}</td>
      <td class="sh_table_cell">${E(e.play)}</td>
      <td class="sh_table_cell">${E(e.win)}</td>
      <td class="sh_table_cell">${E(e.endPoint)}</td>
      <td class="sh_table_cell">${E(e.claim)}</td>
      <td class="sh_table_cell">${E(e.result)}</td>
      <td class="sh_table_cell">${E(e.drawTime)}</td>
      <td class="sh_table_cell">${E(e.ticketTime)}</td>
    </tr>
  `).join(``))}var vn=class{constructor(){let e=nn();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)||nn(),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=tn(),o=a?T(a,w):null;if(o){let e=T(t,w);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)}};function yn(e){return`${String(e.getDate()).padStart(2,`0`)}/${String(e.getMonth()+1).padStart(2,`0`)}/${e.getFullYear()}`}function bn(e){if(!e)return null;let t=String(e).trim().split(`/`);if(t.length!==3)return null;let n=parseInt(t[0],10),r=parseInt(t[1],10),i=parseInt(t[2],10);return!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)||r<1||r>12||n<1||n>31?null:`${i}-${String(r).padStart(2,`0`)}-${String(n).padStart(2,`0`)}`}function xn(e){if(!e)return``;let t=String(e).trim().split(`-`);if(t.length!==3)return String(e);let[n,r,i]=t;return!n||!r||!i?String(e):`${i.padStart(2,`0`)}/${r.padStart(2,`0`)}/${n}`}var D=null,Sn=[`From Date`,`To Date`,`Sale Point`,`Win Point`,`Commission Point`,`NTP Point`,`Operator Point`];function Cn(){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="" 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="" 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>${Sn.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 wn(e,{onAction:t}){D||=new vn,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&&D.show(t)}else if(r===`calendar-to`){let t=e.querySelector(`#rf_to_date`);t&&D.show(t)}else t&&(r===`show`||r===`print`||r===`close`)&&t(r)})}),document.addEventListener(`click`,e=>{D&&D.isVisible&&!D.calendarElement.contains(e.target)&&!e.target.classList.contains(`rf_calendar_btn`)&&D.hide()})}function Tn(e){if(e==null||e===``)return``;let t=Number(e);return Number.isFinite(t)?t.toFixed(2):String(e)}function En(e){!e||e._rfPurchaseRowBound||(e._rfPurchaseRowBound=!0,e.addEventListener(`click`,t=>{let n=t.target.closest(`#rf_table_body tr.rf_table_row`);if(!n||!e.contains(n))return;let r=e.querySelector(`#rf_table_body`);if(!r)return;r.querySelectorAll(`tr.rf_table_row--selected`).forEach(e=>{e.classList.remove(`rf_table_row--selected`)}),n.classList.add(`rf_table_row--selected`);let i=Number(n.dataset.rfRow);e._rfSelectedPurchaseRowIndex=Number.isFinite(i)?i:null}))}function Dn(e,t){let n=e.querySelector(`#rf_table_body`);if(!n)return;En(e);let r=Array.isArray(t)?t:[];e._purchaseDetailRows=r.map(e=>({...e})),e._rfSelectedPurchaseRowIndex=null,n.innerHTML=r.map((e,t)=>`
    <tr class="rf_table_row${e.rowKind===`total`?` rf_table_row--total`:``}" data-rf-row="${t}" role="button" tabindex="0">
      <td class="rf_table_cell">${e.fromDate||``}</td>
      <td class="rf_table_cell">${e.toDate||``}</td>
      <td class="rf_table_cell">${Tn(e.salePoint)}</td>
      <td class="rf_table_cell">${Tn(e.winPoint)}</td>
      <td class="rf_table_cell">${Tn(e.commissionPoint)}</td>
      <td class="rf_table_cell">${Tn(e.ntpPoint)}</td>
      <td class="rf_table_cell">${Tn(e.operatorPoint)}</td>
    </tr>`).join(``)}function On(){D&&=(D.destroy(),null)}var kn=new URL(``+new URL(`btn2-TQ6WoDI6.wav`,import.meta.url).href,``+import.meta.url).href,An=new URL(``+new URL(`numberspinner-CA5xOemr.mp3`,import.meta.url).href,``+import.meta.url).href,jn=new URL(``+new URL(`nomorebetplease-C12XxtAo.wav`,import.meta.url).href,``+import.meta.url).href,Mn=null,Nn=!1;function Pn(){new Audio(kn).play().catch(()=>{})}function Fn(e){e?(Mn||=new Audio(An),Mn.loop=!0,Mn.currentTime=0,Mn.play().catch(()=>{})):Mn&&(Mn.pause(),Mn.currentTime=0)}function In(){new Audio(jn).play().catch(()=>{})}function Ln(e){e===`BETTING_LOCKED`&&In()}function Rn(){Nn||(Nn=!0,document.addEventListener(`click`,e=>{let t=e.target;t instanceof Element&&t.closest(`button`)&&Pn()},!0))}function zn(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 Bn(e){return`${zn(e)} 00`}function Vn({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?Bn(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 Hn(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=zn(i);Fn(!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,Fn(!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 Un(e){e&&(Fn(!1),e._lpRevealInterval&&=(clearInterval(e._lpRevealInterval),null),e._lpRevealTimer&&=(clearTimeout(e._lpRevealTimer),null))}function Wn(e,{onAction:t}){let n=e.querySelector(`[data-action="close"]`);n&&n.addEventListener(`click`,()=>{Un(e),t&&t(`close`)});let r=n=>{n.key===`Escape`&&(Un(e),t&&t(`close`),document.removeEventListener(`keydown`,r))};document.addEventListener(`keydown`,r)}function Gn(e){return e==null?``:String(e).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/"/g,`&quot;`)}var O=null;function Kn(e,t,n,r){if(O){let e=O.element.querySelector(`.popup_body`);e&&(e.innerHTML=qn(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)}}),Jn(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=qn(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 dn({onClose:()=>{console.log(`Upcoming draw popup closed`)}}),O.create(e),Jn(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 qn(e,{onAction:t}){return`
    <div class="upcoming_modal">
      <div class="upcoming_grid">
        ${e.map(e=>`<div class="upcoming_cell upcoming_cell--active" data-time="${Gn(e)}">
      <span class="upcoming_time">${Gn(e)}</span>
      <input type="checkbox" class="upcoming_checkbox" value="${Gn(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 Jn(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 Yn(){if(O)try{O.hide()}catch{}}function Xn(){O&&=(O.destroy(),null)}var A=null;function Zn(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>
  `,nr(A,n),document.body.appendChild(A),A.style.display=`flex`}function Qn(){A&&(A.style.display=`none`,A.querySelectorAll(`.cp_input`).forEach(e=>e.value=``))}function $n(){A&&=(document.body.removeChild(A),null)}function er(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 tr(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){er(e,`Please fill all fields`,!0);return}if(r!==i){er(e,`New password and confirm password do not match`,!0);return}if(r.length<4){er(e,`Password must be at least 4 characters long`,!0);return}let a=e.dataset.userCode,o=e.dataset.apiBaseUrl;if(!a||!o){er(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?(er(e,`Password changed successfully!`),e.querySelectorAll(`.cp_input`).forEach(e=>e.value=``),t&&t(`success`,{message:`Password changed successfully`}),setTimeout(()=>{Qn()},1500)):(er(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),er(e,`Network error. Please try again.`,!0),t&&t(`error`,{message:`Network error`})}finally{s.textContent=c,s.disabled=!1}}function nr(e,t){e.addEventListener(`click`,n=>{let r=n.target.dataset.action;r===`close`?(Qn(),t&&t(`close`)):r===`update`&&tr(e,t)}),e.addEventListener(`click`,n=>{n.target===e&&(Qn(),t&&t(`close`))});let n=e=>{e.key===`Escape`&&(Qn(),t&&t(`close`),document.removeEventListener(`keydown`,n))};document.addEventListener(`keydown`,n)}var rr=null;function ir(){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 ar(e,{onAction:t,onShow:n}){rr||=new vn;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`,()=>{rr.show(o)}),document.addEventListener(`click`,e=>{rr&&rr.isVisible&&!rr.calendarElement.contains(e.target)&&!e.target.closest(`#result_calendar_btn`)&&rr.hide()})}function or(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 sr(){let e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:null;return e&&typeof e.JsBarcode==`function`?e.JsBarcode:null}function j(e){return e==null?``:String(e).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/"/g,`&quot;`)}function cr(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 lr(e){let t=sr();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 ur(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 dr=`
    body{font-family:monospace;width:50mm;max-width:50mm;margin:0;padding:0;font-weight:bold;text-align:center;box-sizing:border-box}
    .ticket{width:50mm;max-width:50mm;background:#fff;text-align:left;padding:4px 3px;box-sizing:border-box}
    .ticket,.ticket *{box-sizing:border-box}
    .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;max-width:100%}
    .footer{font-weight:bold;margin-top:6px;font-size:9px;text-align:center}
    .items-table{width:100%;max-width:100%;table-layout:fixed;text-align:center;margin-top:5px;border-collapse:collapse;font-size:7px}
    .items-table th,.items-table td{padding:1px;border:1px solid #000;overflow:hidden;word-break:break-all;line-height:1.15}
    .items-table th:nth-child(1),.items-table td:nth-child(1){width:24%}
    .items-table th:nth-child(2),.items-table td:nth-child(2){width:26%}
    .items-table th:nth-child(3),.items-table td:nth-child(3){width:24%}
    .items-table th:nth-child(4),.items-table td:nth-child(4){width:26%}
    .items-table th{background:#ddd}
    .meta{font-size:9px}
    @media print{body{margin:0;padding:0;max-width:50mm}.ticket{width:50mm;max-width:50mm}}
`;function fr(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 pr(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>${j(cr(r.cellID))}</td><td>${j(r.cv)}</td>
      <td>${i?j(cr(i.cellID)):``}</td><td>${i?j(i.cv):``}</td>
    </tr>`}return t}function mr({terminal:e,barcode:t,lotdate:n,drawTimeHms:r,ticketTime:i,ticketStatus:a,lines:o,heading:s,footNote:c}){let l=fr(o);if(l.length===0)return;let u=String(t??``).trim(),d=u?lr(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):`—`,h=n&&r?`${j(n)} ${j(r)}`:j(r||n||`—`),g=s?j(s):`BET RECEIPT`,ee=c?`<div class="footer">${j(c)}</div>`:``;ur(`<!DOCTYPE html><html><head><meta charset="utf-8"><title>Delux</title><style>${dr}</style></head><body>
  <div class="ticket">
    <h3>For Amusement Only</h3>
    <h2>NORTHERN DELUX</h2>
    <p class="meta"><strong>${g}</strong></p>
    <p><strong>Terminal:</strong> ${j(e||`—`)}</p>
    <p><strong>Barcode:</strong> ${j(u||`—`)}</p>
    <p><strong>Draw:</strong> ${h}</p>
    <p><strong>Ticket time:</strong> ${j(i||`—`)}</p>
    <p><strong>Status:</strong> ${j(a==null?`—`:String(a))}</p>
    <p><strong>Total points:</strong> ${j(m)}</p>
    <table class="items-table"><thead><tr><th>#</th><th>Pt</th><th>#</th><th>Pt</th></tr></thead><tbody>${pr(l)}</tbody></table>
    ${d?`<div class="barcode-container"><img class="barcodeImage" src="${d}" alt="" /></div>`:``}
    <div class="footer">**Ticket not for sale**</div>
    ${ee}
  </div></body></html>`)}function hr(e){mr({...e,heading:e.heading||`ADVANCE BET`})}function gr(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 _r(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>${j(cr(r.cellID))}</td><td>${j(r.cv)}</td>
      <td>${i?j(cr(i.cellID)):``}</td><td>${i?j(i.cv):``}</td>
    </tr>`}return t}function vr(e,t,n={}){if(!e||e.ok!==!0)return null;let r=n&&typeof n==`object`?n:{},i=r.hidePlacedBets===!0,a=Array.isArray(e.cells)?e.cells:[];if(a.length===0)return null;let o=Array.isArray(e.tickets)&&e.tickets.length?e.tickets[0]:null,s=o&&o.drawTime!=null?String(o.drawTime).trim():``,c=``,l=``,u=/^(\d{4}-\d{2}-\d{2})\s+(\d{1,2}:\d{2}(?::\d{2})?)/.exec(s);u&&(c=u[1],l=u[2].split(`:`).length===2?`${u[2]}:00`:u[2]);let d=o&&o.ticketTime!=null?String(o.ticketTime).trim():``,f=`Duplicate / reprint`;if(`footerLine2`in r){let e=r.footerLine2;f=e===!1||e===null||e===``?``:String(e)}let p=a[0]||{},m=null;if(p.ticketTot!=null&&p.ticketTot!==``){let e=Number(p.ticketTot);Number.isFinite(e)&&(m=e)}if(m==null){let e=a.reduce((e,t)=>{let n=Number(t.cv);return e+(Number.isFinite(n)&&n>0?n:0)},0);e>0&&(m=e)}return{heading:r.heading==null?`STONE REPRINT`:String(r.heading),footerLine2:f,terminal:t||`—`,barcode:String(e.barcode??``).trim(),lotdate:c,lotTime:l,placedAt:d,ticketStatus:`ticketStatus`in r?r.ticketStatus:null,cells:i?[]:a,hidePlacedBets:i,totalAmount:m,operatorLabel:r.operatorLabel==null?``:String(r.operatorLabel).trim()}}function yr({heading:e,footerLine2:t,terminal:n,barcode:r,lotdate:i,lotTime:a,placedAt:o,ticketStatus:s,cells:c,hidePlacedBets:l,totalAmount:u,operatorLabel:d}){let f=l===!0,p=f?[]:gr(c);if(!f&&p.length===0)return;let m=String(r??``).trim(),h=m?lr(m):``,g=i==null?``:String(i),ee=a==null?``:String(a),_=o==null?``:String(o),te=g&&ee?`${j(g)} ${j(ee)}`:j(ee||g||`—`),ne=j(n||`—`),re=j(e||`RECEIPT`),ie=j((d==null?``:String(d).trim())||`Terminal`),ae=Array.isArray(c)&&c[0]?c[0]:{},oe;if(f){let e=u!=null&&u!==``?Number(u):NaN;oe=Number.isFinite(e)?e:NaN}else oe=ae.ticketTot!=null&&ae.ticketTot!==``?Number(ae.ticketTot):p.reduce((e,t)=>e+t.cv,0);let se=Number.isFinite(oe)?String(oe):`—`,ce=s!=null&&String(s)!==``?`<p><strong>Status:</strong> ${j(String(s))}</p>`:``,le=t!=null&&String(t).trim()!==``?`<div class="footer">${j(String(t))}</div>`:``,ue=f?`<p><strong>Date:</strong> ${te}</p>`:`<p><strong>Draw:</strong> ${te}</p>
    <p><strong>Placed:</strong> ${j(_||`—`)}</p>`,de=f?`Total amount`:`Total points`,fe=f?``:`<table class="items-table"><thead><tr><th>#</th><th>Pt</th><th>#</th><th>Pt</th></tr></thead><tbody>${_r(p)}</tbody></table>`;ur(`<!DOCTYPE html><html><head><meta charset="utf-8"><title>Delux</title><style>${dr}</style></head><body>
  <div class="ticket">
    <h3>For Amusement Only</h3>
    <h2>NORTHERN DELUX</h2>
    <p class="meta"><strong>${re}</strong></p>
    <p><strong>${ie}:</strong> ${ne}</p>
    <p><strong>Barcode:</strong> ${j(m||`—`)}</p>
    ${ue}
    ${ce}
    <p><strong>${de}:</strong> ${j(se)}</p>
    ${fe}
    ${h?`<div class="barcode-container"><img class="barcodeImage" src="${h}" alt="" /></div>`:``}
    <div class="footer">**Ticket not for sale**</div>
    ${le}
  </div></body></html>`)}function br(e,{terminal:t}={}){if(!e||e.ok!==!0||e.hasReceipt!==!0)return;let n=Array.isArray(e.cells)?e.cells:[];yr({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})}function xr(e){return e==null?``:String(e).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/"/g,`&quot;`)}function Sr(e){if(e==null||e===``)return`—`;let t=Number(e);return xr(Number.isFinite(t)?t.toFixed(2):String(e))}function M(e,t){return`<tr><th>${xr(e)}</th><td>${t}</td></tr>`}function Cr(e){if(!e)return!1;let t=`<!DOCTYPE html><html><head><meta charset="utf-8"><title>Purchase details</title>
<style>
body{font-family:Arial,Tahoma,sans-serif;margin:16px;color:#111}
h1{font-size:20px;margin:0 0 16px;font-weight:700}
table{border-collapse:collapse;width:100%;max-width:520px}
th,td{border:1px solid #333;padding:10px 12px;font-size:14px}
th{background:#e8e8e8;text-align:left;width:42%;font-weight:700}
td{text-align:right;font-weight:600}
.caption{margin-top:18px;font-size:12px;color:#444}
@media print{body{margin:10mm}h1{font-size:16px}}
</style></head><body>
<h1>Purchase details</h1>
<table>
${M(`From date`,xr(e.fromDate))}
${M(`To date`,xr(e.toDate))}
${M(`Sale point`,Sr(e.salePoint))}
${M(`Win point`,Sr(e.winPoint))}
${M(`Commission point`,Sr(e.commissionPoint))}
${M(`NTP point`,Sr(e.ntpPoint))}
${M(`Operator point`,Sr(e.operatorPoint))}
</table>
<p class="caption">Northern Delux — counter purchase line</p>
</body></html>`,n=document.createElement(`iframe`);n.setAttribute(`title`,`purchase-details-print`),n.style.cssText=`position:fixed;right:0;bottom:0;width:0;height:0;border:0;opacity:0;pointer-events:none`,document.body.appendChild(n);let r=n.contentDocument||n.contentWindow.document;r.open(),r.write(t),r.close();let i=n.contentWindow,a=()=>{try{i.focus(),i.print()}finally{setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n)},2e3)}};return r.readyState===`complete`?setTimeout(a,50):i.addEventListener(`load`,()=>setTimeout(a,50)),!0}var wr=t({default:()=>Tr}),Tr=``+new URL(`4161854560_c48b3bbcbe-iJHQIlrj.jpg`,import.meta.url).href,Er=t({default:()=>Dr}),Dr=``+new URL(`Durga-Yantra-6x6-Front_1200_klein-CjkmTqLQ.jpg`,import.meta.url).href,Or=t({default:()=>kr}),kr=``+new URL(`Ganesha_Yantra-CrRaf6Zg.jpg`,import.meta.url).href,Ar=t({default:()=>jr}),jr=``+new URL(`Tripura-bhairavi_yantra_color-DS4ciZRR.jpg`,import.meta.url).href,Mr=t({default:()=>Nr}),Nr=``+new URL(`bagalamukhi-yantra-cOlD-yPl.jpg`,import.meta.url).href,Pr=t({default:()=>Fr}),Fr=``+new URL(`il_fullxfull.1598885277_esyt-Cw0wiXt6.jpg`,import.meta.url).href,Ir=t({default:()=>Lr}),Lr=``+new URL(`venkatesh-yantra-CBa8UIzd.png`,import.meta.url).href,Rr=1e3,zr=Object.assign({"../media/slideshow/4161854560_c48b3bbcbe.jpg":wr,"../media/slideshow/Durga-Yantra-6x6-Front_1200_klein.jpg":Er,"../media/slideshow/Ganesha_Yantra.jpg":Or,"../media/slideshow/Tripura-bhairavi_yantra_color.jpg":Ar,"../media/slideshow/bagalamukhi-yantra.jpg":Mr,"../media/slideshow/il_fullxfull.1598885277_esyt.jpg":Pr,"../media/slideshow/venkatesh-yantra.png":Ir});function Br(e){if(typeof e==`string`)return e;let t=e&&e.default;return typeof t==`function`?t():typeof t==`string`?t:e}function Vr(){return Object.keys(zr).sort().map(e=>Br(zr[e]))}function Hr(e){if(!e)return()=>{};let t=Vr();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()},Rr),()=>{s!=null&&(clearInterval(s),s=null),e.textContent=``,e.classList.remove(`gamescreen_slideshow`)}}function N(e){return e==null?``:String(e).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/"/g,`&quot;`)}function Ur(e){if(!e||typeof e!=`object`)return``;let t=[e.userCode,e.username,e.userName,e.login,e.pin,e.id];for(let e of t){if(e==null)continue;let t=String(e).trim();if(t)return t}return``}function Wr(e){let t=Ur(e);return t?`P.No.${t}`:`P.No.—`}var P={startHour:0,startMinute:10,endHour:23,endMinute:55,interval:5};function Gr(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 Kr(e,t){let n=T(t,w),r=n.hour*60+n.minute,i=P.startHour*60+P.startMinute,a;if(r<i)a=i;else{let e=r-i;a=i+(Math.floor(e/P.interval)+1)*P.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 qr(){let e=Gr(P),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 Jr=qr();function F(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 Yr=2,Xr=2200,Zr=2400;function Qr(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;)F(e,e._advanceChipsMsgQueue.shift(),Xr),await new Promise(e=>setTimeout(e,Zr));e._advanceChipsMsgDrainRunning=!1})()))}function $r(){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 ei(){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 ti(){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 ni(){return Jr.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`}">${N(t)}</div>`:`<div class="gamescreen_time_cell gamescreen_time_cell--code" data-lot-time="${N(n===1?e[0]:n===3?e[2]:``)}"></div>`).join(``)}
      </div>`).join(``)}function ri(e){if(!e)return``;let t=String(e).trim();return t?t.length>=5?t.slice(0,5):t:``}function ii(e){if(e==null)return``;let t=String(e).replace(/\D/g,``);return t?t.slice(-2).padStart(2,`0`):``}function ai(e){let t=ri(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 oi(e){if(!e)return;let t=J?U(J):null,n=`PR`;if(t){let e=T(t,w);n=ai(`${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 si(e){let t=ri(e);return t?on(`${t}:00`):``}async function ci(e){if(!e)return;let t=await Ht(``);if(!t||!t.ok)return;let n=Array.isArray(t.results)?t.results:[];n[0],oi(e);let r=J||tn(),i=r?U(r):null,a=Gr(P),o=1440;if(i){let e=T(i,w);o=e.hour*60+e.minute}console.log(`Next draw time:`,i?T(i,w):`none`),console.log(`Next draw minutes:`,o);let s=new Map;n.forEach(e=>{let t=ri(e.lotTime??e.lottime),n=ai(t);s.set(t,{lotTime:t,cellID:`${n}${ii(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 li({sessionUser:e}={}){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">${N(Wr(e))}</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">${ni()}</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">${$r()}</div>
                <div class="gamescreen_allb_row">${ei()}</div>
                <div class="gamescreen_allc_row">${ti()}</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 ui=null,di=null,fi=null;function pi(){ui&&=(window.removeEventListener(`resize`,ui),null)}function mi(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 I=null,hi=null,L=null,R=null,z=null,B=null,V=null,H={timeLeftSeconds:0,isBettingAllowed:!0,isPopupShowing:!1,popupTimeoutId:null,currentDrawTime:null,winningRequestedForDrawTs:null,winningFetchPending:!1,prevCountdownSeconds:null,autoBetSubmittedForDrawTs:null,prevNextDrawTs:null,afterLuckyPickDismiss:null},gi={startHour:P.startHour,startMinute:P.startMinute,endHour:P.endHour,endMinute:P.endMinute,intervalMinutes:P.interval};function U(e){let t=T(e,w),n=t.hour*60+t.minute,r=(Math.floor(n/gi.intervalMinutes)+1)*gi.intervalMinutes;if(r>=1440){let e=rn(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 rn(t.year,t.month,t.day,i,a,0)}function _i(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function vi(e){B||(B=document.createElement(`div`),B.className=`gs_spinner_overlay`,B.innerHTML=`<div class="gs_spinner" aria-hidden="true"></div>`,document.body.appendChild(B)),e?(Fn(!0),B.classList.remove(`gs_spinner_overlay--visible`),B.offsetHeight,requestAnimationFrame(()=>{B&&B.classList.add(`gs_spinner_overlay--visible`)})):(B.classList.remove(`gs_spinner_overlay--visible`),Fn(!1))}function yi(e){let t=T(new Date(e),w);return`${String(t.hour).padStart(2,`0`)}:${String(t.minute).padStart(2,`0`)}:00`}function bi(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 xi(){V&&V.classList.remove(`gs_winning_modal_overlay--visible`)}function Si(e){V||(V=document.createElement(`div`),V.className=`gs_winning_modal_overlay`,document.body.appendChild(V),V.addEventListener(`click`,e=>{(e.target===V||e.target&&e.target.classList&&e.target.classList.contains(`gs_winning_modal_ok`))&&xi()})),V.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">${N(e)}</div>
    <button type="button" class="gs_winning_modal_ok">OK</button>
  </div>`,V.classList.remove(`gs_winning_modal_overlay--visible`),V.offsetHeight,requestAnimationFrame(()=>{V&&V.classList.add(`gs_winning_modal_overlay--visible`)})}function Ci(){let e=H.afterLuckyPickDismiss;if(H.afterLuckyPickDismiss=null,typeof e==`function`)try{e()}catch{}}function wi(e=3e3){H.popupTimeoutId&&clearTimeout(H.popupTimeoutId),H.popupTimeoutId=setTimeout(()=>{R&&(Un(R),R.classList.remove(`lp_overlay--visible`),document.body.style.overflow=``),H.isPopupShowing=!1,H.popupTimeoutId=null,Ci()},e)}function Ti(e){return!0}function Ei(e){let t=parseFloat(e.value);return isNaN(t)?0:t}function Di(e,t){e.value=t>0?t:``}function Oi(e){let t=e.replace(/[^0-9.]/g,``),n=t.split(`.`);return n.length>2&&(t=n[0]+`.`+n.slice(1).join(``)),t}var W={baseValues:Array(100).fill(0),allA:Array(10).fill(0),allB:Array(10).fill(0),allC:Array(10).fill(0)};function ki(){W.baseValues.fill(0),W.allA.fill(0),W.allB.fill(0),W.allC.fill(0)}function Ai(){return{baseValues:W.baseValues.slice(),allA:W.allA.slice(),allB:W.allB.slice(),allC:W.allC.slice()}}function ji(e){W.baseValues.splice(0,e.baseValues.length,...e.baseValues),W.allA.splice(0,e.allA.length,...e.allA),W.allB.splice(0,e.allB.length,...e.allB),W.allC.splice(0,e.allC.length,...e.allC)}function Mi(e){let t=parseFloat(String(e).replace(/[^0-9.-]/g,``));return Number.isFinite(t)?t:0}function Ni(){if(I)try{I.hide()}catch{}if(L)try{L.hide()}catch{}if(z)try{z.hide()}catch{}Yn(),Qn(),R&&R.classList.contains(`lp_overlay--visible`)&&(Un(R),R.classList.remove(`lp_overlay--visible`)),H.afterLuckyPickDismiss=null,Y(),xi(),document.body.style.overflow=``}function Pi(e,t){e&&e.querySelectorAll(`.gamescreen_pr_input, .gamescreen_all_input`).forEach(e=>{e.readOnly=t})}function Fi(e){let t=e&&e.querySelector(`.gamescreen_amount`);if(!t)return;let n=Vi(e);t.textContent=Math.max(0,Zi-n).toFixed(2)}function Ii(e,t){return e*10+t}function Li(e,t,n){return(t-n+10)%10==9-e}function Ri(e,t){let n=0;for(let r=0;r<10;r++)Li(e,t,r)&&(n+=W.allC[r]||0);return n}function zi(e,t){let n=Ii(e,t),r=W.baseValues[n],i=W.allA[e]||0,a=W.allB[t]||0,o=Ri(e,t);return r+i+a+o}function Bi(e){e.querySelectorAll(`.gamescreen_pr_row`).forEach((e,t)=>{e.querySelectorAll(`.gamescreen_pr_input`).forEach((e,n)=>{Di(e,zi(t,n))})}),Vi(e),Fi(e)}function Vi(e){let t=0;for(let e=0;e<10;e++)for(let n=0;n<10;n++)t+=zi(e,n);let n=e.querySelector(`.gamescreen_stat--w`);return n&&(n.textContent=t.toFixed(2)),t}function Hi(e){ki(),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`),Fi(e)}function Ui(e){if(q()){F(e,`Lucky pick is not available in advance bet mode.`);return}let t=ma();if(t){Ln(t),F(e,ha(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{F(e,`Enter value between 0-99`);return}}let a=Ii(Math.floor(n/10),n%10),o=Ai();if(W.baseValues[a]=(W.baseValues[a]||0)+i,Bi(e),Vi(e)>Zi+1e-9){ji(o),Bi(e),F(e,`Insufficient balance to place this bet.`);return}F(e,`Lucky pick: ${String(n).padStart(2,`0`)} (+${i})`)}function Wi(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 Gi(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 Ki(e,t,n){let r=Wi(e,t);if(!r)return;let i=null;switch(r.type){case`pr`:i=qi(r,n);break;case`alla`:i=Ji(r,n);break;case`allb`:i=Yi(r,n);break;case`allc`:i=Xi(r,n);break}i&&Gi(e,i)}function qi(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 Ji(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 Yi(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 Xi(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 Zi=0;async function Qi(e,t){if(t&&e.querySelector(`.gamescreen_amount`))try{let n=await Vt(t);n&&n.ok&&n.balance!==void 0&&(Zi=parseFloat(n.balance)||0,Fi(e))}catch(e){console.error(`Error getting balance:`,e)}}function $i(){let e=en();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 ea(){let e=en();return`TXN${String(e??Math.floor(Math.random()*0xe8d4a51000))}${Math.floor(Math.random()*1e3).toString().padStart(3,`0`)}`}var G={date:``,time:``},K=[],ta=`current`;function q(){return ta===`advance`}function na(){return H.isBettingAllowed||q()}function ra(e,t){ta=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&&oa(e)}function ia(e){let t=ri(e?.lotTime??e?.lottime),n=ai(t),r=ii(e?.cellID),i=r?`${n} ${r}`:n,a=G.date||`—`,o=G.time||`—`;return{date:a,time:o,drawTime:si(t)||o,result:i,drawType:`${n} ${t||``}`.trim()}}async function aa(e,t,n){H.winningFetchPending=!1,vi(!1);let r=t&&t.ok&&t.result?t.result:null,i=null,a=e._deluxUserCode;a&&n!=null&&(i=await Yt(a,yi(n))),ci(e),a&&await Qi(e,a);let o=i&&i.ok&&i.hasWinning?bi(i.wins):0,s=o>0?()=>Si(o.toFixed(2)):null;H.isPopupShowing=!0,Ua(e,r?ia(r):null,{reveal:!0,onAfterDismiss:s})}var J=null;function oa(e){if(!J)return;let t=e.querySelector(`.gamescreen_val_timeleft`);if(!t)return;let n=e.querySelector(`.gamescreen_val_time`);if(!Ti(J)){t.textContent=`Closed`,n&&(n.textContent=`--:--`),H.timeLeftSeconds=0,H.isBettingAllowed=!1,H.currentDrawTime=null,q()?Pi(e,!1):Pi(e,!0);let r=e.querySelector(`.gamescreen_fbtn--buy`);r&&(r.disabled=!0);return}let r=U(J);if(!r){t.textContent=`Closed`,n&&(n.textContent=`--:--`),H.timeLeftSeconds=0,H.isBettingAllowed=!1,H.currentDrawTime=null,q()?Pi(e,!1):Pi(e,!0);let r=e.querySelector(`.gamescreen_fbtn--buy`);r&&(r.disabled=!0);return}H.currentDrawTime=r;let i=r.getTime()-J.getTime(),a=Math.max(0,Math.ceil(i/1e3));if(t.textContent=_i(a),n){let e=T(r,w);n.textContent=`${String(e.hour).padStart(2,`0`)}:${String(e.minute).padStart(2,`0`)}`}H.timeLeftSeconds=a,H.isBettingAllowed=a>10,oi(e);let o=r.getTime(),s=H.prevCountdownSeconds;if(s!=null&&s>10&&a<=10){Ni();let t=e._deluxUserCode;t&&pa(e,t,o)}H.prevCountdownSeconds=a,q()?Pi(e,!1):Pi(e,a<=10);let c=e.querySelector(`.gamescreen_fbtn--buy`);c&&(q()?c.disabled=!0:c.disabled=a<=10),I?.isVisible&&Pa();let l=H.prevNextDrawTs,u=l!=null&&l!==o,d=u?l:null;u&&d!=null&&d!==H.winningRequestedForDrawTs&&!H.winningFetchPending&&(H.winningRequestedForDrawTs=d,H.winningFetchPending=!0,vi(!0),Ut().then(t=>aa(e,t,d)).catch(()=>aa(e,null,d))),H.prevNextDrawTs=o}function sa(){H.popupTimeoutId&&(clearTimeout(H.popupTimeoutId),H.popupTimeoutId=null),H={timeLeftSeconds:0,isBettingAllowed:!0,isPopupShowing:!1,popupTimeoutId:null,currentDrawTime:null,winningRequestedForDrawTs:null,winningFetchPending:!1,prevCountdownSeconds:null,autoBetSubmittedForDrawTs:null,prevNextDrawTs:null,afterLuckyPickDismiss:null}}async function ca(){try{let e=It(),t=await fetch(`${e}/api/time`,{cache:`no-store`});if(t.ok){let e=await t.json();if(e.utcMs!=null){$t(e);let t=e.date&&e.time?{date:e.date,time:e.time}:an(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=tn();if(e){let t=an(e);return G.date=t.date,G.time=t.time,{date:t.date,time:t.time,utcMs:en()}}return{date:G.date,time:G.time,utcMs:en()}}function la(){if(G.date&&G.time)return{date:G.date,time:G.time};let e=tn();return e?an(e):{date:``,time:``}}function ua(){let e=J?new Date(J.getTime()):tn();if(!e)return la();let t=U(e);if(!t)return la();let n=T(t,w),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 da(e,t,n={}){let r=n.advanceOnly===!0,i=[],a=ua(),o=$i(),s=ea(),c=e&&e.querySelector?Vi(e):0;function l(e,n,r){let l=r??c,u=n?fa(e):a;for(let e=0;e<10;e++)for(let r=0;r<10;r++){let c=zi(e,r);if(c>0){let d=Ii(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 fa(e){let[t,n]=e.split(`:`).map(Number),r=J?new Date(J):tn();if(!r)return{date:``,time:`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}:00`};let i=T(r,w),a=rn(i.year,i.month,i.day,t,n,0);a<=r&&(a=new Date(a.getTime()+1440*60*1e3));let o=T(a,w);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 pa(e,t,n){!e||!t||q()||H.autoBetSubmittedForDrawTs!==n&&(Vi(e)<=0||(H.autoBetSubmittedForDrawTs=n,await ba(e,t,{allowWhenLocked:!0,silentReceipt:!0})))}function ma(){return H.isBettingAllowed?null:H.currentDrawTime!=null&&H.timeLeftSeconds>=1&&H.timeLeftSeconds<=10?`BETTING_LOCKED`:`BETTING_CLOSED`}function ha(e){return e===`BETTING_LOCKED`?`Bet locked.`:`Betting is closed.`}function ga(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 _a(e){let t=localStorage.getItem(`username`);return t!=null&&String(t).trim()!==``?String(t).trim():e||`—`}function va(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 ya(e,t,n,r){if(!t?.ok||!Array.isArray(n)||n.length===0)return;let i=_a(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:va(t),ticketStatus:t.ticketStatus,lines:n};r?hr(s):mr({...s,heading:`BET RECEIPT`})}async function ba(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=Vi(e)*K.length;if(t<=0)return{ok:!1,error:`NO_BETS`};if(t>Zi)return{ok:!1,error:`INSUFFICIENT_BALANCE`}}else{if(!i){let e=ma();if(e)return Ln(e),{ok:!1,error:e}}let t=Vi(e);if(t<=0)return{ok:!1,error:`NO_BETS`};if(t>Zi)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=da(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=fa(r);console.log(`Parsed draw time for slot`,r,`:`,o);let s=await Bt(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():`—`;Qr(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&&ya(t,s,i,!0),{ok:!0,response:s}}for(let e=0;e<r.length;e+=Yr){let t=r.slice(e,e+Yr);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 Hi(e),K=[],i||{ok:!1,error:`UNKNOWN_ERROR`}}let i=da(e,n,{advanceOnly:!1});if(i.length===0)return{ok:!1,error:`NO_BETS_CREATED`};let o=ua().time,s=await Bt(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&&ya(t,s,i,!1),Hi(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 Qi(e,t)}catch{}}}function xa(e){e.addEventListener(`focus`,()=>{e.style.backgroundColor=`#0066ff`,e.style.color=`#ffffff`}),e.addEventListener(`blur`,()=>{e.style.backgroundColor=``,e.style.color=``})}function Sa(e){if(pi(),e&&e._slideshowTeardown&&(e._slideshowTeardown(),e._slideshowTeardown=null),di&&=(clearInterval(di),null),fi&&=(clearInterval(fi),null),sa(),J=null,ta=`current`,K=[],Y(),I&&=(I.destroy(),null),L&&=(L.destroy(),null),On(),Xn(),$n(),R&&=(Un(R),document.body.removeChild(R),null),B&&=(Fn(!1),document.body.removeChild(B),null),V&&=(document.body.removeChild(V),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)}function Ca(){let e=T(nn(),w);return{ymd:`${e.year}-${String(e.month).padStart(2,`0`)}-${String(e.day).padStart(2,`0`)}`,ddMm:yn(new Date(e.year,e.month-1,e.day))}}async function wa(e,t,n,r,i,a={}){let o=a.showErrors!==!1;if(!Xt().connected)return Dn(e,[]),o&&t&&F(t,`Not connected to server.`),!1;let s=await Jt(n,r,i);if(!s||s.ok!==!0)return Dn(e,[]),o&&t&&F(t,s&&s.error===`TIMEOUT`?`Purchase details request timed out.`:`Could not load purchase details.`),!1;let c=s.summary,l=Array.isArray(s.data)?s.data:[],u=l.map(e=>{let t=xn(e.lotdate);return{rowKind:`day`,fromDate:t,toDate:t,salePoint:e.play,winPoint:e.win,commissionPoint:e.commissionPoint,ntpPoint:e.ntpPoint,operatorPoint:e.operatorPoint}});return c&&(l.length>1||l.length===0)&&u.push({rowKind:`total`,fromDate:xn(c.fromDate),toDate:xn(c.toDate),salePoint:c.salePoint,winPoint:c.winPoint,commissionPoint:c.commissionPoint,ntpPoint:c.ntpPoint,operatorPoint:c.operatorPoint}),Dn(e,u),!0}async function Ta(e,t){if(!H.isBettingAllowed)return;if(!L){let n=Cn();L=new dn({onClose:()=>{}}),L.create(n);let r=L.element.querySelector(`.popup_body`);wn(r,{onAction:async n=>{if(n===`close`){L.hide();return}if(n===`print`){let t=r._rfSelectedPurchaseRowIndex,n=r._purchaseDetailRows;if(t==null||!Array.isArray(n)||n[t]==null){F(e,`Select a row in the table, then click Print.`);return}Cr(n[t])||F(e,`Could not open print window. Check pop-up settings.`);return}if(n===`show`){let n=r.querySelector(`#rf_from_date`),i=r.querySelector(`#rf_to_date`),a=bn(n&&n.value),o=bn(i&&i.value);if(!a||!o){F(e,`Choose valid Report From and To dates.`);return}if(a>o){F(e,`Report From must be on or before To.`);return}await wa(r,e,t,a,o,{showErrors:!0})}}}),document.body.appendChild(L.element)}L.show();let n=L.element.querySelector(`.popup_body`);if(n){let{ymd:r,ddMm:i}=Ca(),a=n.querySelector(`#rf_from_date`),o=n.querySelector(`#rf_to_date`);a&&(a.value=i),o&&(o.value=i),await wa(n,e,t,r,r,{showErrors:!0})}}function Y(){hi&&hi.parentNode&&hi.parentNode.removeChild(hi),hi=null}function Ea(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>${N(r?.cellID)}</td><td>${N(r?.cv)}</td>
      <td>${i?N(i.cellID):``}</td><td>${i?N(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),hi=i}function Da(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?rn(Number(t[1]),Number(t[2]),Number(t[3]),Number(t[4]),Number(t[5]),t[6]==null?0:Number(t[6])):null}function Oa(e,t){if(!e||!t)return!1;let n=Da(e);if(!n)return!1;let r=T(n,w),i=T(t,w);return r.year===i.year&&r.month===i.month&&r.day===i.day&&r.hour===i.hour&&r.minute===i.minute}function ka(e,t){if(!e||!t)return!1;let n=Da(e);return n?n.getTime()<t.getTime():!1}function Aa(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 ja(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?U(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?Oa(e.drawTime,t)?`Pending`:ka(e.drawTime,t)?`Completed`:`Pending`:e._result||`Pending`,{...e,win:i,claim:a,result:o}})}function Na(){let e=Fa();if(!e)return;let t=e.querySelector(`[data-action="cancel"]`);if(!t)return;if(!H.isBettingAllowed){t.disabled=!0;return}let n=I?._session?.selectedBarcode;if(!n){t.disabled=!0;return}let r=(I._allTickets||[]).find(e=>String(e.barcode)===String(n));if(!r){t.disabled=!0;return}let i=J?U(J):null;t.disabled=!(r._result!==`Cancelled`&&i!=null&&Oa(r.drawTime,i))}function Pa(){let e=Fa();if(!e)return;let t=!H.isBettingAllowed;e.querySelectorAll(`[data-action]`).forEach(e=>{let n=e.dataset.action;n===`close`?e.disabled=!1:n===`reprint`?e.disabled=!I?._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),Na()}function Fa(){return I?.element?I.element.querySelector(`.popup_body`)||I.element:null}function Ia(){if(!I)return;let e=Fa();if(!e)return;let t=e.querySelector(`#sh_show_all`)?.checked??!1,n=e.querySelector(`#sh_winning_only`)?.checked??!1,r=I._allTickets||[];r=Array.isArray(r)?[...r]:[],n&&(r=r.filter(e=>e._result===`Win`));let i=J?U(J):null;!t&&i&&(r=r.filter(e=>Oa(e.drawTime,i))),_n(e,Ma(r)),Pa()}async function La(){let e=Fa();if(!I||!e||!I._session?.userCode)return;let t=I._session.userCode;if(gn(e,`Loading…`),!Xt().connected){I._allTickets=[],gn(e,`Not connected. Log in and wait for connection.`);return}let n=await Gt(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 Gt(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){I._allTickets=[],gn(e,n?.error===`TIMEOUT`?`Request timed out.`:n?.error===`MISSING_FIELDS`?`Missing user.`:`Could not load tickets.`);return}I._allTickets=ja(r.map(Aa)),I._session&&(I._session.selectedBarcode=``),gn(e,``),Ia()}function Ra(e,t){let n=I?._session?.root,r=I?._session?.userCode;if(I&&!(e!==`close`&&e!==`reprint`&&!H.isBettingAllowed)){if(e===`close`){Y(),I.hide();return}if(e===`select`){I._session&&(I._session.selectedBarcode=t?.barcode||``),Pa();return}if(e===`filter`){Ia();return}if(!(!n||!r)){if(e===`result`){Y(),Ba();return}if(e===`allclaim`||e===`claim`){F(n,`Not available.`);return}if(e===`reprint`){(async()=>{let e=I._session?.selectedBarcode||``;if(!e){F(n,`Select a ticket row.`);return}let t=await Kt(r,e);if(!t||!t.ok){F(n,t?.error===`NOT_FOUND`?`Ticket not found.`:`Reprint could not load ticket.`);return}let i=vr(t,_a(r));if(!i){F(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?yr(i):F(n,`Printing disabled - reprint not printed.`)})();return}if(e===`details`){(async()=>{let e=I._session?.selectedBarcode||``;if(!e){F(n,`Select a ticket row.`);return}let t=await Kt(r,e);if(!t||!t.ok){F(n,t?.error===`NOT_FOUND`?`Ticket not found.`:`Details request failed.`);return}Ea(t)})();return}if(e===`cancel`){if(!H.isBettingAllowed||Fa()?.querySelector(`[data-action="cancel"]`)?.disabled)return;(async()=>{let e=I._session?.selectedBarcode||``;if(!e){F(n,`Select a ticket row.`);return}let t=await Kt(r,e);if(!t||!t.ok){F(n,t?.error===`NOT_FOUND`?`Ticket not found.`:`Could not load ticket for cancel.`);return}let i=await qt(r,e);if(F(n,i?.str||(i?.ok?`Done.`:`Cancellation failed.`)),i&&i.ok){let e=vr(t,_a(r),{heading:`TICKET CANCELLED`,ticketStatus:`Cancelled`,footerLine2:`** Ticket cancelled **`,hidePlacedBets:!0,operatorLabel:`Username`});if(e){let t=n.querySelector(`#gs_cb_print`),r=t?t.checked:!0;console.log(`Cancel receipt - Print checkbox checked:`,r),r?yr(e):F(n,`Printing disabled - cancel receipt not printed.`)}await La(),await Qi(n,r)}})();return}}}}async function za(e,t){if(!I){let e=mn({onAction:()=>{}});I=new dn({onClose:()=>{Y()}}),I.create(e),hn(I.element.querySelector(`.popup_body`),{onAction:(e,t)=>Ra(e,t),isBetLocked:()=>!H.isBettingAllowed}),document.body.appendChild(I.element)}I._session={userCode:t,root:e,selectedBarcode:``},I.show(),await La(),Pa()}async function Ba(){if(!z){let e=ir();z=new dn({onClose:()=>{console.log(`Result popup closed`);let e=document.querySelector(`.result_calendar_picker`);e&&e.remove()}}),z.create(e),ar(z.element.querySelector(`.popup_body`),{onAction:e=>{e===`close`&&z.hide()},onShow:async({date:e,stone:t})=>{await Va(e,t)}}),document.body.appendChild(z.element)}z.show(),await Va(``,`PR`)}async function Va(e,t){if(!z)return;let n=await Ht(``);if(!n||!n.ok){or(z.element,[]);return}let r=(Array.isArray(n.results)?n.results:[]).filter(e=>ai(ri(e.lotTime??e.lottime))===t).map(e=>{let t=ri(e.lotTime??e.lottime);return{drawTime:t,result:`${ai(t)} ${ii(e.cellID)}`.trim()}});or(z.element,r)}function Ha(e,t={}){if(!t.skipBettingCheck&&!H.isBettingAllowed)return;let n=t.userCode||e?._deluxUserCode||``,r=()=>{let e=Gr(P);return J?Kr(e,J):e};Kn(e,r(),J,t=>{let r=Array.isArray(t)?t:[];if(K=r,console.log(`Selected future draw times:`,K),r.length===0){F(e,`Select at least one draw time, then Confirm.`);return}(async()=>{let t=await ba(e,n,{advanceOnly:!0});if(!t||!t.ok){let n=t?.error||`UNKNOWN_ERROR`;n===`BETTING_LOCKED`&&In(),F(e,ga(n))}})()}),e._upcomingDrawRefresh=()=>{let t=r();upcomingDrawPopup&&upcomingDrawPopup.element&&Kn(e,t,J,t=>{let r=Array.isArray(t)?t:[];if(K=r,r.length===0){F(e,`Select at least one draw time, then Confirm.`);return}(async()=>{let t=await ba(e,n,{advanceOnly:!0});if(!t||!t.ok){let n=t?.error||`UNKNOWN_ERROR`;n===`BETTING_LOCKED`&&In(),F(e,ga(n))}})()})}}function Ua(e,t,n={}){let r=n.reveal===!0;if(!r&&!H.isBettingAllowed)return;H.popupTimeoutId&&(clearTimeout(H.popupTimeoutId),H.popupTimeoutId=null),H.afterLuckyPickDismiss=typeof n.onAfterDismiss==`function`?n.onAfterDismiss:null;let i=la(),a=t||{date:i.date||`—`,time:on(i.time)||i.time||`—`,drawTime:on(i.time)||i.time||`—`,result:`—`,drawType:`Result`};R&&Un(R);let o=Vn({data:a,reveal:r});if(R||(R=document.createElement(`div`),R.className=`lp_overlay`,document.body.appendChild(R)),R.innerHTML=o,Wn(R,{onAction:e=>{console.log(`Lucky pick action:`,e),e===`close`&&(Un(R),H.popupTimeoutId&&(clearTimeout(H.popupTimeoutId),H.popupTimeoutId=null),R.classList.remove(`lp_overlay--visible`),document.body.style.overflow=``,H.isPopupShowing=!1,Ci())}}),R.classList.add(`lp_overlay--visible`),document.body.style.overflow=`hidden`,r){let e=a.result||`—`,t=a.drawTime||null;Hn(R,e,2800,()=>{wi(3200)},t)}else wi(3e3)}function Wa(e,{onAction:t,sessionUser:n}){pi(),mi(e),ui=()=>mi(e),window.addEventListener(`resize`,ui),ki(),ta=`current`,K=[];let r=n?.userCode||n?.id||`dev`;e._deluxUserCode=r;let i=e.querySelector(`.gamescreen_pno`);i&&(i.textContent=Wr(n)),Qi(e,r),ci(e),oi(e);let a=e.querySelector(`.gamescreen_slideshow_host`);a&&(e._slideshowTeardown&&=(e._slideshowTeardown(),null),e._slideshowTeardown=Hr(a));let o=e.querySelector(`#gs_cb_print`),s=e.querySelector(`#gs_cb_ac`);o&&(o.disabled=!1,o.checked=!0),s&&(s.disabled=!1,s.checked=!0,s.addEventListener(`change`,e=>{console.log(`AC checkbox changed:`,e.target.checked)}));async function c(){let t=await ca(),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))),oa(e)}c(),fi=setInterval(c,1e3);let l=e.querySelectorAll(`.gamescreen_pr_row`);l.forEach((t,n)=>{t.querySelectorAll(`.gamescreen_pr_input`).forEach((t,r)=>{xa(t),t.addEventListener(`input`,t=>{if(!na())return;let i=Oi(t.target.value),a=Ii(n,r);W.baseValues[a]=Mi(i),t.target.value=i,Bi(e)}),t.addEventListener(`keydown`,n=>{switch(n.key){case`ArrowUp`:n.preventDefault(),Ki(e,t,`up`);break;case`ArrowDown`:n.preventDefault(),Ki(e,t,`down`);break;case`ArrowLeft`:n.preventDefault(),Ki(e,t,`left`);break;case`ArrowRight`:n.preventDefault(),Ki(e,t,`right`);break}})})}),l.forEach((t,n)=>{let r=t.querySelector(`.gamescreen_all_input`);r&&(xa(r),r.addEventListener(`input`,t=>{if(!na())return;let i=Oi(t.target.value);t.target.value=i,W.allA[n]=Ei(r),Bi(e)}),r.addEventListener(`keydown`,t=>{switch(t.key){case`ArrowUp`:case`ArrowDown`:case`ArrowLeft`:case`ArrowRight`:t.preventDefault(),Ki(e,r,t.key.replace(`Arrow`,``).toLowerCase());break}}))});let u=e.querySelector(`.gamescreen_allb_row`);u&&u.querySelectorAll(`.gamescreen_all_input`).forEach((t,n)=>{xa(t),t.addEventListener(`input`,r=>{if(!na())return;let i=Oi(r.target.value);r.target.value=i,W.allB[n]=Ei(t),Bi(e)}),t.addEventListener(`keydown`,n=>{switch(n.key){case`ArrowUp`:case`ArrowDown`:case`ArrowLeft`:case`ArrowRight`:n.preventDefault(),Ki(e,t,n.key.replace(`Arrow`,``).toLowerCase());break}})});let d=e.querySelector(`.gamescreen_allc_row`);d&&d.querySelectorAll(`.gamescreen_all_input`).forEach((t,n)=>{xa(t),t.addEventListener(`input`,r=>{if(!na())return;let i=Oi(r.target.value);r.target.value=i,W.allC[n]=Ei(t),Bi(e)}),t.addEventListener(`keydown`,n=>{switch(n.key){case`ArrowUp`:case`ArrowDown`:case`ArrowLeft`:case`ArrowRight`:n.preventDefault(),Ki(e,t,n.key.replace(`Arrow`,``).toLowerCase());break}})});let f=e.querySelector(`.gamescreen_fbtn--cyan`);f&&f.textContent.includes(`F5-Clear`)&&f.addEventListener(`click`,()=>{Hi(e)});let p=t=>{t.key===`F5`&&(t.preventDefault(),Hi(e))};document.addEventListener(`keydown`,p),e._f5Handler=p;let m=e.querySelector(`.gamescreen_lucky_input`);m&&(xa(m),m.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}),m.addEventListener(`keypress`,e=>{!/\d/.test(e.key)&&![`Backspace`,`Delete`,`Tab`,`Enter`,`ArrowLeft`,`ArrowRight`].includes(e.key)&&e.preventDefault()}),m.addEventListener(`paste`,e=>{e.preventDefault();let t=(e.clipboardData||window.clipboardData).getData(`text`).replace(/\D/g,``).slice(0,2);e.target.value=t}));let h=e.querySelector(`.gamescreen_fbtn--buy`);h&&h.addEventListener(`click`,async()=>{if(q()){F(e,`Upcoming bets: choose chips, tap Upcoming, pick draw times, then Confirm.`);return}let t=ma();if(t){Ln(t),F(e,ha(t));return}let n=h.textContent;h.textContent=`Placing Bet...`,h.disabled=!0;try{let t=K.length,n=await ba(e,r);if(n&&n.ok)F(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`&&In(),F(e,ga(t))}}catch(t){console.error(`Error in bet placement:`,t),F(e,`An error occurred while placing the bet.`)}finally{h.textContent=n,q()?h.disabled=!0:h.disabled=!1}});let g=t=>{if(t.key===`F6`){if(t.preventDefault(),q()){F(e,`Upcoming bets: choose chips, tap Upcoming, pick draw times, then Confirm.`);return}let n=ma();if(n){Ln(n),F(e,ha(n));return}h&&h.click()}};document.addEventListener(`keydown`,g),e._f6Handler=g,e.querySelectorAll(`[data-gamescreen-action]`).forEach(n=>{n.addEventListener(`click`,()=>{let i=n.dataset.gamescreenAction;i===`purchase-details`?Ta(e,r):i===`stone-report`?za(e,r):i===`lucky-pick`?Ui(e):i===`change-password`?Zn(r,It(),(t,n)=>{t===`success`?F(e,`Password changed successfully!`):t===`error`&&F(e,n?.message||`Failed to change password`)}):i===`last-receipt`?(async()=>{if(!Xt().connected){F(e,`Not connected to server.`);return}let t=await Wt(r);if(!t||t.ok!==!0){F(e,t?.error===`TIMEOUT`?`Last receipt request timed out.`:`Could not load last receipt.`);return}if(!t.hasReceipt){F(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?br(t,{terminal:_a(r)}):F(e,`Printing disabled - receipt not printed.`)})():t(i)})});let ee=e.querySelector(`#gs_toggle_current`),_=e.querySelector(`#gs_toggle_upcoming`),te=e.querySelector(`#gamescreen_pr_block`),ne=e.querySelector(`#gamescreen_draw_closed`);ee&&_&&te&&ne&&(ee.addEventListener(`click`,()=>{ra(e,`current`),te.style.display=`flex`,ne.style.display=`none`}),_.addEventListener(`click`,()=>{ra(e,`advance`),te.style.display=`flex`,ne.style.display=`none`,Ha(e,{skipBettingCheck:!0,userCode:r})}))}async function Ga(){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 Ka=document.querySelector(`#app`),qa=``,Ja=``,Ya=`deluxAuth`;function Xa(){try{let e=localStorage.getItem(Ya);if(!e)return null;let t=JSON.parse(e);return t&&typeof t==`object`?t:null}catch{return null}}function Za(e,t,n){try{localStorage.setItem(Ya,JSON.stringify({pin:e||``,password:t||``,sessionUser:n||null}))}catch{}}function Qa(){Q=null,Za(Z,eo,null);try{localStorage.removeItem(`userID`)}catch{}}var $a=Xa(),X=`offline`,Z=$a?.pin||qa,eo=$a?.password||Ja,to=``,no=``,Q=null;function ro(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.`,MISSING_DEVICE:`This device did not send a valid install ID. Reinstall the app or contact support.`,DEVICE_PENDING_APPROVAL:`This device is not approved yet. Ask an administrator to approve the new device for your account.`}[e]||`Login failed.`}function io(e){return e&&e.message===`CONNECT_TIMEOUT`?`Connection timed out.`:`Could not reach server.`}function $(){cn();let e=Ka.querySelector(`.app_shell`);e?.querySelector(`.gamescreen_wrap`)&&Sa(e),Ka.innerHTML=`<div class="app_shell">${X===`offline`?n({connectError:to}):X===`online`?i():X===`login`?ln({pin:Z,password:eo,loginError:no}):li({sessionUser:Q})}</div>`,ao()}function ao(){let e=Ka.querySelector(`.app_shell`);e&&(X!==`game`&&pi(),X===`offline`&&r(e,{async onAction(e){if(e===`connect`){to=``,$();try{await Lt(),X=`online`}catch{to=io()}$()}e===`power-off`&&await Ga()}}),X===`online`&&a(e,{async onAction(e){e===`disconnect`&&(Rt(),X=`offline`,$()),e===`login-screen`&&(no=``,X=`login`,$()),e===`power-off`&&await Ga()}}),X===`login`&&un(e,{async onAction(e){if(e===`enter-dashboard`){no=``;let e=await zt(Z,eo);e&&e.ok?(Q=e.user||null,Q&&localStorage.setItem(`userID`,Q.id||Q.userCode||Z),Za(Z,eo,Q),X=`game`):no=ro(e&&e.error),$()}e===`back-to-connect`&&(no=``,X=`online`,$())},onPinInput(e){Z=e,Za(Z,eo,Q)},onPasswordInput(e){eo=e,Za(Z,eo,Q)}}),X===`game`&&Wa(e,{sessionUser:Q,onAction(e){e===`exit-offline`&&(Qa(),no=``,to=``,Rt(),X=`offline`,$())}}))}async function oo(){Rn(),$()}oo();