import {w as s, g as c} from "./DM27xdW2.js"; const v = s({ message: "", show: !1, x: 0, y: 0 }); function O(n, e, t=2500) { let a, o; e ? {clientX: a, clientY: o} = e : typeof window < "u" && (a = window.innerWidth / 2, o = window.innerHeight / 2), v.set({ message: n, show: !0, x: a, y: o }), setTimeout(()=>{ v.set({ message: "", show: !1, x: 0, y: 0 }) } , t) } const T = "https://api.prod.cloudmoonapp.com"; async function r(n, e={}) { const t = new URL(T + n) , a = new Headers(e.headers); t.searchParams.set("device_type", "web"); const o = typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : E(); t.searchParams.set("query_uuid", o); let d = o; { const g = localStorage.getItem("device_id"); g ? d = g : localStorage.setItem("device_id", o); const i = navigator.language.split("-")[1] ?? ""; a.set("X-User-Locale", i) } t.searchParams.set("device_id", d); const p = c(l); if (p != null && p.token && a.set("X-User-Token", p.token), !a.get("X-User-Language")) { const g = c(k) ?? "en"; a.set("X-User-Language", g) } a.set("Content-Type", "application/json"); const u = await fetch(t.toString(), { ...e, headers: a }); if (!u.ok) throw new Error(`fetch error: ${u.status} - ${u.statusText}`); if ((await u.clone().json()).code == "40001") throw N(), new Error("Unauthorized"); return u } function E() { return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(n) { const e = Math.random() * 16 | 0; return (n === "x" ? e : e & 3 | 8).toString(16) }) } const P = s({ android_id: null, package_name: null, expired_at: null, level: null, is_paid: !1, time_left_set: null, use_time_type: 0, time_left_sec: 0, is_subscription: !1, subscription_channel: null, subscription_product_id: null, backup_time: null, locale: null, isUnlimitLocale: !1 }); async function S() { var n, e; try { const a = await (await r("/phone/list")).json(); if (a.code === 0 && ((e = (n = a.data) == null ? void 0 : n.list) == null ? void 0 : e.length) > 0) { const o = a.data.list[0]; P.set({ android_id: o.android_id, package_name: o.package_name, expired_at: o.expired_at, level: o.level, is_paid: o.is_paid, time_left_set: o.time_left_set, time_left_sec: o.time_left_sec, use_time_type: o.use_time_type, is_subscription: o.is_subscription, subscription_channel: o.subscription_channel, subscription_product_id: o.subscription_product_id, backup_time: o.backup_time, locale: o.locale, isUnlimitLocale: o.is_unlimit_locale }) } } catch (t) { console.error("Failed to fetch phone data:", t) } } async function q() { try { const e = await (await r("/phone/sub_manage_url")).json(); if (e.code === 0) return e.data.url } catch (n) { console.error("Failed to fetch phone data:", n) } return "" } let f; async function R() { x(), await S(), f = setInterval(()=>{ S() } , 5e3) } function x() { f && (clearInterval(f), f = null) } async function X(n, e) { const t = c(P); let a = 0; try { let o = localStorage.getItem("selectedServer") || 0; if (a = parseInt(o), a === 0) { O("Please select a server", null); return } const d = c(k) || "en" , u = (navigator.language || navigator.userLanguage).split("-")[1] || ""; let h = { language: d, locale: u.toLowerCase() }; new URLSearchParams(window.location.search).forEach((y,_)=>{ if (_.startsWith("test_")) { const w = _.replace(/^test_/, ""); h[w] = y } } ); const g = { method: "POST", body: JSON.stringify({ android_id: t.android_id, game_name: e, screen_res: "720x1280", server_id: a, params: JSON.stringify(h) }) } , i = await (await r("/phone/connect", g)).json(); if (i.code === 0) { const {android_instance_id: y, coordinator_host: _, position: w, waiting_time: L, priority_queue_length: U, priority_waiting_time: C, in_queue_time: j} = i.data; return { android_instance_id: y, coordinator_host: _, position: w, waiting_time: L, err_code: i.code, priority_queue_length: U, priority_waiting_time: C, in_queue_time: j, message: i.message } } else return { android_instance_id: null, coordinator_host: null, position: null, waiting_time: null, priority_queue_length: 0, priority_waiting_time: 0, err_code: i.code, message: i.message } } catch (o) { throw console.error("Error connecting phone:", o), o } } const F = s({ selectedGameFilter: "" }) , $ = s(!1) , z = s(!1) , H = s(-1) , W = s(!1) , G = s([]); async function K() { try { return await (await r("/game/reset_all", { method: "POST" })).json() } catch (n) { return console.error("Failed to clear all game cache:", n), null } } async function M() { var n, e; try { const a = await (await r("/game/category")).json(); a.code === 0 && ((e = (n = a.data) == null ? void 0 : n.list) == null ? void 0 : e.length) > 0 && G.set(a.data.list) } catch (t) { console.error("Failed to fetch category data:", t) } } const m = s({ picture: null, user_id: null, name: null, email: null, is_set_pwd: !1, video_level: [], is_test: !1, is_new: !1 }) , V = s({ memberCount: 0 }) , Y = s(!1) , Q = s(null) , Z = s(!1); async function A() { try { const e = await (await r("/user/info")).json(); e.code === 0 && m.set({ picture: e.data.picture, user_id: e.data.user_id, name: e.data.name, email: e.data.email, is_set_pwd: e.data.is_set_pwd, video_level: e.data.video_level, is_test: e.data.is_test, is_new: e.data.is_new }) } catch (n) { console.error("Failed to fetch user data:", n) } } async function ee(n) { try { const t = await (await r("/user/set_pwd", { method: "POST", body: JSON.stringify({ password: n }) })).json(); return t.code === 0 && await A(), t } catch (e) { return console.error("Failed to set Pwd:", e), null } } function te(n, e) { var a, o; const t = new URL("https://shop.cloudmoonapp.com"); n ? t.pathname = `/${n}/${e}` : t.pathname = `/${e}`, (a = c(m)) != null && a.email && t.searchParams.set("email", c(m).email), (o = c(l)) != null && o.token && t.searchParams.set("token", c(l).token), window.open(t.toString(), "_blank") } function ae() { return new Promise(n=>{ let e = !1; const t = document.createElement("div"); t.setAttribute("class", "pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links ad-banner adsbox"), t.style.setProperty("position", "absolute", "important"), t.style.setProperty("top", "-9999px", "important"), t.style.setProperty("left", "-9999px", "important"), t.style.setProperty("width", "1px", "important"), t.style.setProperty("height", "1px", "important"), document.body.appendChild(t); const a = document.createElement("script"); a.src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?time=" + new Date().getTime(), a.type = "text/javascript", a.async = !0, a.onerror = function() { e = !0, o() } , a.onload = function() { e = !1, o() } , document.head.appendChild(a); function o() { setTimeout(()=>{ const d = window.getComputedStyle(t); (d.getPropertyValue("display") === "none" || d.getPropertyValue("visibility") === "hidden" || t.offsetParent === null || t.offsetHeight === 0) && (e = !0); try { document.body.removeChild(t), document.head.removeChild(a) } catch {} n(e) } , 100) } } ) } function b(n, e={}) { let t; m.subscribe(o=>{ t = o == null ? void 0 : o.user_id } )(); const a = t ? { user_id: t, ...e } : { ...e }; gtag("event", n, a) } const l = s({ userId: null, token: null, init: !1 }) , k = s("en"); function ne(n) { const e = document.createElement("script"); return e.src = "https://accounts.google.com/gsi/client", e.async = !0, e.defer = !0, document.head.appendChild(e), new Promise(t=>{ e.onload = ()=>{ google.accounts.id.initialize({ client_id: n, callback: J, auto_select: !1, cancel_on_tap_outside: !1 }), t() } } ) } function oe() { var e; const n = document.createElement("div"); document.body.appendChild(n), google.accounts.id.renderButton(n, { theme: "outline", size: "large", type: "standard" }), (e = n.querySelector('[role="button"]')) == null || e.click(), n.style = "display: none" } async function J(n) { const e = n.credential; try { const a = await (await r("/login/google", { method: "POST", body: JSON.stringify({ google_id_token: e }) })).json(); if (a.code === 0) { const o = { userId: a.data.user_id, token: a.data.token, init: !0 }; return b("sign_in"), l.set(o), localStorage.setItem("userData", JSON.stringify(o)), !0 } else return console.error("Login failed:", a), !1 } catch (t) { return console.error("Login error:", t), !1 } } async function se(n, e) { try { const a = await (await r("/login/pwd", { method: "POST", body: JSON.stringify({ email: n, password: e }) })).json(); if (a.code === 0) { const o = { userId: a.data.user_id, token: a.data.token, init: !0 }; return b("sign_in_by_pwd"), l.set(o), localStorage.setItem("userData", JSON.stringify(o)), a } else return console.error("Login failed:", a), a } catch (t) { return console.error("Login error:", t), null } } function N() { b("sign_out"), l.set({ userId: null, token: null, init: !0 }), m.set({ picture: null, user_id: null, name: null }), x(), F.set({ selectedGameFilter: "all" }), localStorage.removeItem("userData") } function re() { { const n = localStorage.getItem("userData"); if (n) { const e = localStorage.getItem("selectedServer"); if (!e || parseInt(e) === 0) { x(), localStorage.removeItem("userData"); return } l.set(JSON.parse(n)) } l.update(e=>({ ...e, init: !0 })) } } export {V as A, F as B, z as C, H as D, G as E, $ as F, M as G, l as a, N as b, oe as c, b as d, re as e, Q as f, te as g, ae as h, ne as i, Y as j, A as k, se as l, R as m, Z as n, x as o, m as p, r as q, P as r, O as s, v as t, k as u, X as v, W as w, K as x, ee as y, q as z};