import { M as q, g as D, s as z } from "./vendor.js";
import { a as je, m as Ue, b as Be, c as Ne, p as Fe, u as We } from "./vendor.js";
import H from "axios";
const G = "lang", Se = (e, t) => {
  var i, a;
  const n = typeof window < "u", r = () => {
    var p;
    if (!n)
      return { innerWidth: 1920, innerHeight: 1080 };
    const o = window, l = typeof navigator < "u" ? o.navigator : {}, u = o.screen || {}, m = o.visualViewport, c = {
      innerWidth: o.innerWidth,
      innerHeight: o.innerHeight,
      outerWidth: o.outerWidth,
      outerHeight: o.outerHeight,
      screenWidth: u.width ?? o.innerWidth,
      screenHeight: u.height ?? o.innerHeight,
      availWidth: u.availWidth ?? o.innerWidth,
      availHeight: u.availHeight ?? o.innerHeight,
      devicePixelRatio: o.devicePixelRatio || 1,
      bodyHeight: o.innerHeight - ((p = t.pinia) != null && p.useTab ? 36 : 0) - 64 - 32,
      drawerHeight: parseInt(o.innerHeight * 0.9),
      pageHeight: o.innerHeight - 64 - 32,
      pageWidth: o.innerWidth
    };
    m && (c.visualViewportWidth = m.width, c.visualViewportHeight = m.height, c.visualViewportScale = m.scale);
    const f = l.userAgent || "";
    return c.env = {
      userAgent: f,
      language: l.language || "",
      languages: l.languages ? [...l.languages] : [],
      platform: l.platform || "",
      cookieEnabled: !!l.cookieEnabled,
      onLine: l.onLine !== !1,
      maxTouchPoints: l.maxTouchPoints || 0,
      isTouch: "ontouchstart" in o || (l.maxTouchPoints || 0) > 0,
      isMobile: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobile/i.test(
        f
      )
    }, console.info(c), c;
  }, s = () => {
    var l;
    const o = r();
    globalThis.$config = globalThis.$config || {}, globalThis.$config.options = {
      ...globalThis.$config.options || {},
      ...o
    }, (l = e == null ? void 0 : e.config) != null && l.globalProperties && (e.config.globalProperties.$config = globalThis.$config);
  };
  s(), n && (window.addEventListener("resize", s, { passive: !0 }), (a = (i = window.visualViewport) == null ? void 0 : i.addEventListener) == null || a.call(i, "resize", s, {
    passive: !0
  }));
}, Ae = (e, t) => {
  var l, u, m;
  const n = t || {}, r = Array.isArray(n.use) && n.use.length > 0 ? n.use : q;
  globalThis.$config = globalThis.$config || {}, globalThis.$config.langUse = r.filter(
    (c) => c && c.use !== !1 && c.value
  ), (l = e == null ? void 0 : e.config) != null && l.globalProperties && (e.config.globalProperties.$config = globalThis.$config);
  const i = (typeof localStorage < "u" ? localStorage.getItem(G) : null) || ((u = globalThis.$config) == null ? void 0 : u.lang) || "en_us", a = Object.assign(
    {},
    D(i),
    ((m = globalThis.$config) == null ? void 0 : m.langMaps) || {},
    n.langMaps || {}
  ), o = (c, f) => {
    if (c)
      if (f && globalThis.$getType(f) === "Object") {
        let p = a[c] || c;
        return Object.keys(f).forEach((d) => {
          p[`{${d}}`] = f[d];
        }), p;
      } else
        return a[c] || c;
    else
      return c ?? "";
  };
  globalThis.$patchLangMaps = (c) => {
    c && globalThis.$getType(c) === "Object" && Object.assign(a, c);
  }, globalThis.$l = o, e.config.globalProperties.$l = o, e.config.globalProperties.$patchLangMaps = globalThis.$patchLangMaps, String.prototype.$l = function() {
    return $l(this);
  };
}, $e = (e, t) => {
  if (!e || !t) return !1;
  const n = e.getBoundingClientRect(), r = t.getBoundingClientRect(), s = r.right > n.left && r.left < n.right, i = r.bottom > n.top && r.top < n.bottom;
  return s && i;
}, Y = (e, t) => {
  if (e === t) return !0;
  if (e == null || t == null || typeof e != "object" || typeof t != "object")
    return JSON.stringify(e) === JSON.stringify(t);
  const n = Object.keys(e), r = Object.keys(t);
  if (n.length !== r.length) return !1;
  for (const s of n)
    if (!r.includes(s) || !Y(e[s], t[s])) return !1;
  return !0;
}, x = "download", K = 150, X = (e, t = x) => {
  const n = t || x, r = String(e ?? "").trim();
  if (!r) return n;
  const i = r.replace(/[/\\?%*:|"<>]/g, "_").replace(/\.\./g, "_").split(/[/\\]/).pop() || n, a = 200;
  return i.length > a ? i.slice(0, a) : i;
}, J = (e) => {
  const t = ((e == null ? void 0 : e.type) || "").toLowerCase();
  return t ? t.includes("spreadsheet") || t.includes("ms-excel") || t.includes("excel") && t.includes("application") : !1;
}, S = (e, t) => {
  const n = URL.createObjectURL(e), r = X(t), s = document.createElement("a");
  s.href = n, s.download = r, s.style.display = "none", document.body.appendChild(s);
  try {
    s.click();
  } finally {
    document.body.removeChild(s), setTimeout(() => URL.revokeObjectURL(n), K);
  }
}, Q = (e) => {
  if (!e || e.source !== void 0 || e.type === void 0)
    return e;
  const { type: t, data: n, url: r, headers: s, name: i, filename: a, init: o, ...l } = e, u = a ?? i;
  return t === "csv" ? {
    ...l,
    source: "inline",
    content: n,
    filename: u,
    bom: e.bom
  } : t === "excel" ? {
    ...l,
    source: "fetch",
    url: r,
    init: { ...o || {}, headers: s ?? (o == null ? void 0 : o.headers) },
    response: "blob",
    expectExcel: !0,
    filename: u
  } : e;
}, Le = async (e = {}) => {
  const t = Q(e), {
    source: n = "inline",
    content: r,
    blob: s,
    bom: i = !0,
    mime: a,
    url: o,
    init: l,
    response: u = "blob",
    openIn: m = "self",
    expectExcel: c,
    filename: f,
    name: p,
    error: d = () => {
    },
    // 避免 legacy 字段渗入后续逻辑
    type: _e,
    data: Te,
    headers: we,
    ...Me
  } = t, M = f ?? p;
  try {
    if (n === "inline") {
      if (s instanceof Blob) {
        S(s, M);
        return;
      }
      if (r == null) {
        d(new Error("content or blob is required for inline"));
        return;
      }
      const h = typeof r == "string" ? r : String(r), v = i ? "\uFEFF" + h : h, R = a || (i ? "text/csv;charset=utf-8" : "text/plain;charset=utf-8");
      S(new Blob([v], { type: R }), M);
      return;
    }
    if (n === "fetch") {
      if (!o) {
        d(new Error("url is required for fetch"));
        return;
      }
      const h = await fetch(o, l);
      if (!h.ok) {
        d(new Error(`fetch failed: ${h.status}`));
        return;
      }
      if (u === "text") {
        const R = await h.text(), F = i ? "\uFEFF" + R : R, W = a || (i ? "text/csv;charset=utf-8" : "text/plain;charset=utf-8");
        S(new Blob([F], { type: W }), M);
        return;
      }
      const v = await h.blob();
      if (c && !J(v)) {
        d(new Error("excel does not exist"));
        return;
      }
      S(v, M);
      return;
    }
    if (n === "open") {
      if (!o) {
        d(new Error("url is required for open"));
        return;
      }
      m === "blank" ? window.open(o, "_blank", "noopener,noreferrer") : window.location.href = o;
      return;
    }
    d(new Error(`unknown source: ${n}`));
  } catch (h) {
    d(h instanceof Error ? h : new Error(String(h)));
  }
};
function Z(e, t, n) {
  if (t === "" || t === void 0 || t === null)
    return "";
  const r = globalThis.$fa, s = globalThis.$fu, i = (n == null ? void 0 : n.precision) ?? 2, a = n == null ? void 0 : n.unit;
  if ((a === "currency" || a === "%") && s) {
    const o = {
      [e]: {
        unit: a === "currency" ? "currency" : "%",
        precision: i
      }
    };
    try {
      return s({
        prop: e,
        currency: n == null ? void 0 : n.currency,
        value: t,
        obj: o
      });
    } catch {
    }
  }
  if (r)
    try {
      return r(t, i);
    } catch {
      return String(t);
    }
  return String(t);
}
function Pe(e, t, n = {}) {
  const { columns: r = [] } = e || {}, { resolveMetric: s } = n;
  return !r.length || !t || typeof t != "object" ? [] : r.map((i) => {
    const a = i.property ?? i.prop ?? "";
    if (!a)
      return "";
    let o = t[a];
    if (o === void 0 && (o = ""), o === "")
      return "";
    const l = typeof s == "function" ? s(a) : void 0;
    try {
      return Z(a, o, l);
    } catch {
      return String(o);
    }
  });
}
const C = "mvframe_primary", V = "mvframe_theme", I = "mvframe_theme_name", ee = "dark", A = "main", $ = "mv-theme-", T = { r: 255, g: 255, b: 255 }, te = { r: 0, g: 0, b: 0 }, j = [1, 3, 5, 7, 9], ne = [
  "--el-color-primary-light-3",
  "--el-color-primary-light-5",
  "--el-color-primary-light-7",
  "--el-color-primary-light-8",
  "--el-color-primary-light-9",
  "--el-color-primary-dark-2"
], re = j.map(
  (e) => `--color-primary${e}`
);
function L(e) {
  let t = String(e).trim().replace(/^#/, "");
  if (t.length === 3 && (t = t.split("").map((r) => r + r).join("")), t.length >= 8 && (t = t.slice(0, 6)), t.length !== 6 || Number.isNaN(parseInt(t, 16)))
    return null;
  const n = parseInt(t, 16);
  return {
    r: n >> 16 & 255,
    g: n >> 8 & 255,
    b: n & 255
  };
}
function y(e, t, n) {
  const r = (s) => Math.max(0, Math.min(255, Math.round(s)));
  return `#${[r(e), r(t), r(n)].map((s) => s.toString(16).padStart(2, "0")).join("")}`;
}
function U(e, t, n, r) {
  const s = (a) => Math.max(0, Math.min(255, Math.round(a))), i = Math.max(0, Math.min(1, r));
  return `rgba(${s(e)}, ${s(t)}, ${s(n)}, ${i})`;
}
function se(e) {
  const t = [e.r, e.g, e.b].map((n) => (n /= 255, n <= 0.03928 ? n / 12.92 : ((n + 0.055) / 1.055) ** 2.4));
  return 0.2126 * t[0] + 0.7152 * t[1] + 0.0722 * t[2];
}
function B(e) {
  return se(e) > 0.5 ? "#1a1a1a" : "#ffffff";
}
function b(e, t, n) {
  const r = n / 100, s = 1 - r;
  return {
    r: e.r * r + t.r * s,
    g: e.g * r + t.g * s,
    b: e.b * r + t.b * s
  };
}
function oe(e, t = "light") {
  const n = L(e);
  if (!n)
    return null;
  const r = b(T, n, 30), s = b(T, n, 50), i = b(T, n, 70), a = b(T, n, 80), o = b(T, n, 90), l = b(te, n, 20);
  return {
    "--el-color-primary-light-3": y(r.r, r.g, r.b),
    "--el-color-primary-light-5": y(s.r, s.g, s.b),
    "--el-color-primary-light-7": t === "dark" ? U(n.r, n.g, n.b, 0.7) : y(i.r, i.g, i.b),
    "--el-color-primary-light-8": y(a.r, a.g, a.b),
    "--el-color-primary-light-9": y(o.r, o.g, o.b),
    "--el-color-primary-dark-2": y(l.r, l.g, l.b)
  };
}
function ie(e) {
  const t = L(e);
  return t ? Object.fromEntries(
    j.map((n) => [
      `--color-primary${n}`,
      U(t.r, t.g, t.b, n / 10)
    ])
  ) : null;
}
function ae(e) {
  e.style.removeProperty("--el-color-primary"), e.style.removeProperty("--color-on-primary-text");
  for (const t of re)
    e.style.removeProperty(t);
  for (const t of ne)
    e.style.removeProperty(t);
}
function N(e) {
  const t = String(e ?? "").trim().toLowerCase();
  return t && t.replace(/[^a-z0-9_-]/g, "-").replace(/-+/g, "-") || A;
}
function le(e) {
  const t = [...e.classList].find(
    (n) => n.startsWith($)
  );
  return t ? t.slice($.length) : A;
}
function ce(e) {
  [...e.classList].filter((t) => t.startsWith($)).forEach((t) => e.classList.remove(t));
}
function ue(e) {
  return e.classList.contains("light") ? "light" : e.classList.contains("dark") ? "dark" : ee;
}
function he(e, t) {
  const n = N(t);
  return ce(e), e.classList.add(`${$}${n}`), n;
}
function de(e, t, n = "light") {
  const r = L(t.startsWith("#") ? t : `#${t}`);
  if (!r)
    return !1;
  const s = y(r.r, r.g, r.b);
  e.style.setProperty("--color-primary", s), e.style.setProperty("--el-color-primary", s), e.style.setProperty("--color-on-primary-text", B(r));
  const i = ie(s);
  i && Object.entries(i).forEach(([o, l]) => e.style.setProperty(o, l));
  const a = oe(s, n);
  return a && Object.entries(a).forEach(([o, l]) => e.style.setProperty(o, l)), !0;
}
function me(e = {}) {
  const t = document.documentElement, n = (e.mode ?? ue(t)) === "light" ? "light" : "dark", r = e.theme ?? le(t);
  if (he(t, r), e.primary != null && e.primary !== "") {
    const s = String(e.primary).trim();
    if (!de(t, s, n)) {
      t.style.setProperty("--color-primary", s), t.style.setProperty("--el-color-primary", s);
      const i = L(s.startsWith("#") ? s : `#${s}`);
      i && t.style.setProperty("--color-on-primary-text", B(i));
    }
  } else (e.primary === null || e.primary === "") && (t.style.removeProperty("--color-primary"), ae(t));
  t.classList.toggle("light", n === "light"), t.classList.toggle("dark", n === "dark");
}
function Ce(e) {
  e.primary !== void 0 && (e.primary == null || e.primary === "" ? localStorage.removeItem(C) : localStorage.setItem(C, String(e.primary))), e.mode !== void 0 && localStorage.setItem(V, e.mode), e.theme !== void 0 && (e.theme == null || e.theme === "" ? localStorage.removeItem(I) : localStorage.setItem(
    I,
    N(e.theme)
  ));
}
function Ie() {
  var s;
  const e = localStorage.getItem(C), t = localStorage.getItem(V), n = localStorage.getItem(I) || ((s = globalThis.$config) == null ? void 0 : s.theme) || A, r = t === "light" ? "light" : "dark";
  me({
    primary: e != null && e !== "" ? e : null,
    mode: r,
    theme: n
  });
}
const fe = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 };
let w = null;
function O(e) {
  z("error", e);
}
function ke(e) {
  w = e && typeof e == "object" ? e : null;
}
function P(e) {
  if (w && w[e] != null && w[e] !== "")
    return String(w[e]);
  const t = typeof globalThis < "u" ? globalThis.__MVFRAME_ENV__ : null;
  if (t && t[e] != null && t[e] !== "")
    return String(t[e]);
  const n = typeof import.meta < "u" ? fe : null;
  return n && n[e] != null && n[e] !== "" ? String(n[e]) : "";
}
const _ = H.create({
  timeout: 0,
  withCredentials: !1
});
let g = [];
const ge = H.CancelToken, pe = (e) => {
  const t = e.url + "_" + e.headers["Content-HI"] + "_" + e.ex, n = [];
  if (g.length)
    for (let r in g)
      g[r].v === t && n.push(r);
  n.length > 0 && (g[n[0]].cb(), g.splice(n[0], 1));
}, E = (e) => {
  if (e != null && e.url) {
    const t = e.url + "_" + e.headers["Content-HI"] + "_" + e.ex;
    for (let n in g)
      if (g[n].v === t) {
        g.splice(n, 1);
        break;
      }
  }
};
_.interceptors.request.use(
  (e) => {
    e.headers = e.headers || {};
    const { login: t, accountInfo: n = {} } = window.$store.launch(), { access_token: r } = t.info, s = e.noaccount === !0 || e.noAccount === !0;
    return r && e.headers["Content-HI"] && (e.headers.Authorization = `Bearer ${r}`), n.partner_org_id && !s && (e.data ? e.method.toLowerCase() === "get" ? e.params.accountId = n.partner_org_id : e.data.accountId = n.partner_org_id : e.method.toLowerCase() === "get" ? e.params = { accountId: n.partner_org_id } : e.data = { accountId: n.partner_org_id }), pe(e), e.cancelToken = new ge((i) => {
      g.push({
        v: e.url + "_" + e.headers["Content-HI"] + "_" + e.ex,
        cb: i
      });
    }), e;
  },
  (e) => Promise.reject(e)
);
_.interceptors.response.use(
  ({ data: e, config: t }) => {
    var i;
    if (e == null || typeof e != "object" || Array.isArray(e))
      return E(t), e;
    let { code: n, message: r, msg: s } = e;
    if (s = s || r, n === 200)
      E(t);
    else if (n === 500) {
      if (t.showMsg !== !1) {
        const a = (i = t == null ? void 0 : t.headers) != null && i.CONTACT_CUSTOMER_SERVICE ? window.$l("CONTACT_CUSTOMER_SERVICE") : "";
        O({
          grouping: !0,
          showClose: !0,
          duration: 0,
          message: [s, a].filter(Boolean).join(" ")
        });
      }
      E(t);
    } else n === 403 && window.location.replace("/"), E(t);
    return e;
  },
  (e) => {
    var n, r, s, i, a;
    let t = !1;
    if (e && e.response)
      switch (e.response.status) {
        case 403:
          e.message = "403 Token Expired", window.location.replace("/");
          break;
        case 502:
          e.message = "502 Error";
          break;
        case 503:
          e.message = "503 Error";
          break;
        case 504:
          e.message = "504 Error", e.response = {};
          break;
        default:
          e.message = `Connection Error-${e.response.status}`;
      }
    else
      (n = e.stack) != null && n.includes("timeout") ? e.message = window.$l("Timeout, Please Refresh") : (e.message = window.$l("Connect Failed"), t = !0);
    return t || ((r = e == null ? void 0 : e.response) == null ? void 0 : r.status) !== 403 && O({
      grouping: !0,
      message: `${e.message} ${(i = (s = e.config) == null ? void 0 : s.headers) == null ? void 0 : i["Content-HI"]}`
    }), E(e.config), e.code === "ERR_CANCELED" ? Promise.resolve({ code: e.code, msg: e.message }) : Promise.resolve({
      code: (a = e.response) == null ? void 0 : a.status,
      msg: e.message
    });
  }
);
function ye(e) {
  return e.baseURL = P("VITE_APP_BASEURL"), e.method = "get", e.headers = { "Content-Type": "application/x-www-form-urlencoded" }, e.data && (e.params = e.data), _(e);
}
function be(e) {
  return e.baseURL = P("VITE_APP_BASEURL"), e.method = "get", e.headers = {
    ...e.headers,
    "Content-HI": e.url
  }, e.url = e.ver ? `api/${e.ver}/ads` : "api/v3/ads", e.data && (e.params = e.data), _(e);
}
function Ee(e) {
  if (e.baseURL = P("VITE_APP_BASEURL"), e.method = "post", e.headers = {
    ...e.headers,
    "Content-HI": e.url
  }, e.data && window.$getType(e.data) === "Object") {
    const n = {};
    Object.keys(e.data).forEach((r) => {
      const s = e.data[r];
      [null, "", void 0].includes(s) || (n[r] = s);
    }), e.data = n;
  }
  return e.url = e.ver ? `api/${e.ver}/ads` : "api/v3/ads", _(e);
}
function k({
  data: e,
  url: t,
  ex: n,
  method: r = "post",
  emptyString: s = !1
}) {
  const i = {}, a = [void 0, null];
  s === !1 && a.push("");
  for (let u in e)
    a.indexOf(e[u]) === -1 && (i[u] = e[u]);
  const { login: o } = window.$store.launch(), { access_token: l } = o.info || {};
  return _({
    headers: {
      "Content-Type": "application/json",
      token: l != null ? String(l) : ""
    },
    baseURL: P("VITE_APP_AIURL"),
    url: t,
    method: r,
    data: i,
    ex: n
  });
}
const xe = k;
function Oe(e) {
  globalThis.$login = ye, globalThis.$get = be, globalThis.$post = Ee, globalThis.$form = k, globalThis.$xform = k;
}
export {
  ee as MVFRAME_DEFAULT_THEME_MODE,
  A as MVFRAME_DEFAULT_THEME_NAME,
  G as MVFRAME_STORAGE_LANG,
  C as MVFRAME_STORAGE_PRIMARY,
  V as MVFRAME_STORAGE_THEME,
  I as MVFRAME_STORAGE_THEME_NAME,
  $ as MVFRAME_THEME_CLASS_PREFIX,
  me as applyMvframeTheme,
  Y as deepEqual,
  Le as download,
  Z as formatSummaryCell,
  je as getMaps,
  Oe as installRq,
  $e as isInView,
  Ie as loadMvframeTheme,
  Ue as mapLang,
  Be as mapLangPath,
  Ne as mergeMaps,
  Fe as patchMaps,
  Ce as persistMvframeTheme,
  X as sanitizeDownloadFileName,
  ke as setMvframeRqEnv,
  k as useForm,
  be as useGet,
  Ae as useLang,
  ye as useLogin,
  We as useMap,
  Se as useOptions,
  Ee as usePost,
  Pe as useRemoteSummary,
  xe as useXform
};
