import { M as q, g as z, s as D } from "./vendor.js";
import { a as He, m as Ve, b as je, c as Ue, p as Be, u as Ne } from "./vendor.js";
import H from "axios";
const G = "lang", ve = (e, t) => {
  var i, a;
  const n = typeof window < "u", r = () => {
    var g;
    if (!n)
      return { innerWidth: 1920, innerHeight: 1080 };
    const s = window, l = typeof navigator < "u" ? s.navigator : {}, u = s.screen || {}, m = s.visualViewport, c = {
      innerWidth: s.innerWidth,
      innerHeight: s.innerHeight,
      outerWidth: s.outerWidth,
      outerHeight: s.outerHeight,
      screenWidth: u.width ?? s.innerWidth,
      screenHeight: u.height ?? s.innerHeight,
      availWidth: u.availWidth ?? s.innerWidth,
      availHeight: u.availHeight ?? s.innerHeight,
      devicePixelRatio: s.devicePixelRatio || 1,
      bodyHeight: s.innerHeight - ((g = t.pinia) != null && g.useTab ? 36 : 0) - 64 - 32,
      drawerHeight: parseInt(s.innerHeight * 0.9),
      pageHeight: s.innerHeight - 64 - 32,
      pageWidth: s.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 s || (l.maxTouchPoints || 0) > 0,
      isMobile: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobile/i.test(
        f
      )
    }, console.info(c), c;
  }, o = () => {
    var l;
    const s = r();
    globalThis.$config = globalThis.$config || {}, globalThis.$config.options = {
      ...globalThis.$config.options || {},
      ...s
    }, (l = e == null ? void 0 : e.config) != null && l.globalProperties && (e.config.globalProperties.$config = globalThis.$config);
  };
  o(), n && (window.addEventListener("resize", o, { passive: !0 }), (a = (i = window.visualViewport) == null ? void 0 : i.addEventListener) == null || a.call(i, "resize", o, {
    passive: !0
  }));
}, Re = (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(
    {},
    z(i),
    ((m = globalThis.$config) == null ? void 0 : m.langMaps) || {},
    n.langMaps || {}
  ), s = (c, f) => {
    if (c)
      if (f && globalThis.$getType(f) === "Object") {
        let g = a[c] || c;
        return Object.keys(f).forEach((d) => {
          g[`{${d}}`] = f[d];
        }), g;
      } else
        return a[c] || c;
    else
      return c ?? "";
  };
  globalThis.$patchLangMaps = (c) => {
    c && globalThis.$getType(c) === "Object" && Object.assign(a, c);
  }, globalThis.$l = s, e.config.globalProperties.$l = s, e.config.globalProperties.$patchLangMaps = globalThis.$patchLangMaps, String.prototype.$l = function() {
    return $l(this);
  };
}, Se = (e, t) => {
  if (!e || !t) return !1;
  const n = e.getBoundingClientRect(), r = t.getBoundingClientRect(), o = r.right > n.left && r.left < n.right, i = r.bottom > n.top && r.top < n.bottom;
  return o && 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 o of n)
    if (!r.includes(o) || !Y(e[o], t[o])) 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), o = document.createElement("a");
  o.href = n, o.download = r, o.style.display = "none", document.body.appendChild(o);
  try {
    o.click();
  } finally {
    document.body.removeChild(o), 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: o, name: i, filename: a, init: s, ...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: { ...s || {}, headers: o ?? (s == null ? void 0 : s.headers) },
    response: "blob",
    expectExcel: !0,
    filename: u
  } : e;
}, $e = async (e = {}) => {
  const t = Q(e), {
    source: n = "inline",
    content: r,
    blob: o,
    bom: i = !0,
    mime: a,
    url: s,
    init: l,
    response: u = "blob",
    openIn: m = "self",
    expectExcel: c,
    filename: f,
    name: g,
    error: d = () => {
    },
    // 避免 legacy 字段渗入后续逻辑
    type: be,
    data: Ee,
    headers: _e,
    ...Te
  } = t, M = f ?? g;
  try {
    if (n === "inline") {
      if (o instanceof Blob) {
        S(o, 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 (!s) {
        d(new Error("url is required for fetch"));
        return;
      }
      const h = await fetch(s, l);
      if (!h.ok) {
        d(new Error(`fetch failed: ${h.status}`));
        return;
      }
      if (u === "text") {
        const R = await h.text(), W = i ? "\uFEFF" + R : R, F = a || (i ? "text/csv;charset=utf-8" : "text/plain;charset=utf-8");
        S(new Blob([W], { type: F }), 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 (!s) {
        d(new Error("url is required for open"));
        return;
      }
      m === "blank" ? window.open(s, "_blank", "noopener,noreferrer") : window.location.href = s;
      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, o = globalThis.$fu, i = (n == null ? void 0 : n.precision) ?? 2, a = n == null ? void 0 : n.unit;
  if ((a === "currency" || a === "%") && o) {
    const s = {
      [e]: {
        unit: a === "currency" ? "currency" : "%",
        precision: i
      }
    };
    try {
      return o({
        prop: e,
        currency: n == null ? void 0 : n.currency,
        value: t,
        obj: s
      });
    } 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: o } = n;
  return !r.length || !t || typeof t != "object" ? [] : r.map((i) => {
    const a = i.property ?? i.prop ?? "";
    if (!a)
      return "";
    let s = t[a];
    if (s === void 0 && (s = ""), s === "")
      return "";
    const l = typeof o == "function" ? o(a) : void 0;
    try {
      return Z(a, s, l);
    } catch {
      return String(s);
    }
  });
}
const I = "mvframe_primary", V = "mvframe_theme", C = "mvframe_theme_name", $ = "main", P = "mv-theme-", T = { r: 255, g: 255, b: 255 }, ee = { r: 0, g: 0, b: 0 }, j = [1, 3, 5, 7, 9], te = [
  "--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"
], ne = 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 = (o) => Math.max(0, Math.min(255, Math.round(o)));
  return `#${[r(e), r(t), r(n)].map((o) => o.toString(16).padStart(2, "0")).join("")}`;
}
function U(e, t, n, r) {
  const o = (a) => Math.max(0, Math.min(255, Math.round(a))), i = Math.max(0, Math.min(1, r));
  return `rgba(${o(e)}, ${o(t)}, ${o(n)}, ${i})`;
}
function re(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 re(e) > 0.5 ? "#1a1a1a" : "#ffffff";
}
function b(e, t, n) {
  const r = n / 100, o = 1 - r;
  return {
    r: e.r * r + t.r * o,
    g: e.g * r + t.g * o,
    b: e.b * r + t.b * o
  };
}
function oe(e, t = "light") {
  const n = L(e);
  if (!n)
    return null;
  const r = b(T, n, 30), o = b(T, n, 50), i = b(T, n, 70), a = b(T, n, 80), s = b(T, n, 90), l = b(ee, n, 20);
  return {
    "--el-color-primary-light-3": y(r.r, r.g, r.b),
    "--el-color-primary-light-5": y(o.r, o.g, o.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(s.r, s.g, s.b),
    "--el-color-primary-dark-2": y(l.r, l.g, l.b)
  };
}
function se(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 ie(e) {
  e.style.removeProperty("--el-color-primary"), e.style.removeProperty("--color-on-primary-text");
  for (const t of ne)
    e.style.removeProperty(t);
  for (const t of te)
    e.style.removeProperty(t);
}
function N(e) {
  const t = String(e ?? "").trim().toLowerCase();
  return t && t.replace(/[^a-z0-9_-]/g, "-").replace(/-+/g, "-") || $;
}
function ae(e) {
  const t = [...e.classList].find(
    (n) => n.startsWith(P)
  );
  return t ? t.slice(P.length) : $;
}
function le(e) {
  [...e.classList].filter((t) => t.startsWith(P)).forEach((t) => e.classList.remove(t));
}
function ce(e, t) {
  const n = N(t);
  return le(e), e.classList.add(`${P}${n}`), n;
}
function ue(e, t, n = "light") {
  const r = L(t.startsWith("#") ? t : `#${t}`);
  if (!r)
    return !1;
  const o = y(r.r, r.g, r.b);
  e.style.setProperty("--color-primary", o), e.style.setProperty("--el-color-primary", o), e.style.setProperty("--color-on-primary-text", B(r));
  const i = se(o);
  i && Object.entries(i).forEach(([s, l]) => e.style.setProperty(s, l));
  const a = oe(o, n);
  return a && Object.entries(a).forEach(([s, l]) => e.style.setProperty(s, l)), !0;
}
function he(e = {}) {
  const t = document.documentElement, n = (e.mode ?? (t.classList.contains("dark") ? "dark" : "light")) === "dark" ? "dark" : "light", r = e.theme ?? ae(t);
  if (ce(t, r), e.primary != null && e.primary !== "") {
    const o = String(e.primary).trim();
    if (!ue(t, o, n)) {
      t.style.setProperty("--color-primary", o), t.style.setProperty("--el-color-primary", o);
      const i = L(o.startsWith("#") ? o : `#${o}`);
      i && t.style.setProperty("--color-on-primary-text", B(i));
    }
  } else (e.primary === null || e.primary === "") && (t.style.removeProperty("--color-primary"), ie(t));
  t.classList.toggle("light", n === "light"), t.classList.toggle("dark", n === "dark");
}
function Le(e) {
  e.primary !== void 0 && (e.primary == null || e.primary === "" ? localStorage.removeItem(I) : localStorage.setItem(I, String(e.primary))), e.mode !== void 0 && localStorage.setItem(V, e.mode), e.theme !== void 0 && (e.theme == null || e.theme === "" ? localStorage.removeItem(C) : localStorage.setItem(
    C,
    N(e.theme)
  ));
}
function Ae() {
  var o;
  const e = localStorage.getItem(I), t = localStorage.getItem(V), n = localStorage.getItem(C) || ((o = globalThis.$config) == null ? void 0 : o.theme) || $, r = t === "dark" ? "dark" : "light";
  he({
    primary: e != null && e !== "" ? e : null,
    mode: r,
    theme: n
  });
}
const de = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 };
let w = null;
function O(e) {
  D("error", e);
}
function Ie(e) {
  w = e && typeof e == "object" ? e : null;
}
function A(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" ? de : null;
  return n && n[e] != null && n[e] !== "" ? String(n[e]) : "";
}
const _ = H.create({
  timeout: 0,
  withCredentials: !1
});
let p = [];
const me = H.CancelToken, fe = (e) => {
  const t = e.url + "_" + e.headers["Content-HI"] + "_" + e.ex, n = [];
  if (p.length)
    for (let r in p)
      p[r].v === t && n.push(r);
  n.length > 0 && (p[n[0]].cb(), p.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 p)
      if (p[n].v === t) {
        p.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;
    return r && e.headers["Content-HI"] && (e.headers.Authorization = `Bearer ${r}`), n.partner_org_id && noaccount !== !0 && (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 }), fe(e), e.cancelToken = new me((o) => {
      p.push({
        v: e.url + "_" + e.headers["Content-HI"] + "_" + e.ex,
        cb: o
      });
    }), 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: o } = e;
    if (o = o || 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: [o, a].filter(Boolean).join(" ")
        });
      }
      E(t);
    } else n === 403 && window.location.replace("/"), E(t);
    return e;
  },
  (e) => {
    var n, r, o, 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 = (o = e.config) == null ? void 0 : o.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 pe(e) {
  return e.baseURL = A("VITE_APP_BASEURL"), e.method = "get", e.headers = { "Content-Type": "application/x-www-form-urlencoded" }, e.data && (e.params = e.data), _(e);
}
function ge(e) {
  return e.baseURL = A("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 ye(e) {
  if (e.baseURL = A("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 o = e.data[r];
      [null, "", void 0].includes(o) || (n[r] = o);
    }), 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: o = !1
}) {
  const i = {}, a = [void 0, null];
  o === !1 && a.push("");
  for (let u in e)
    a.indexOf(e[u]) === -1 && (i[u] = e[u]);
  const { login: s } = window.$store.launch(), { access_token: l } = s.info || {};
  return _({
    headers: {
      "Content-Type": "application/json",
      token: l != null ? String(l) : ""
    },
    baseURL: A("VITE_APP_AIURL"),
    url: t,
    method: r,
    data: i,
    ex: n
  });
}
const Ce = k;
function ke(e) {
  globalThis.$login = pe, globalThis.$get = ge, globalThis.$post = ye, globalThis.$form = k, globalThis.$xform = k;
}
export {
  $ as MVFRAME_DEFAULT_THEME_NAME,
  G as MVFRAME_STORAGE_LANG,
  I as MVFRAME_STORAGE_PRIMARY,
  V as MVFRAME_STORAGE_THEME,
  C as MVFRAME_STORAGE_THEME_NAME,
  P as MVFRAME_THEME_CLASS_PREFIX,
  he as applyMvframeTheme,
  Y as deepEqual,
  $e as download,
  Z as formatSummaryCell,
  He as getMaps,
  ke as installRq,
  Se as isInView,
  Ae as loadMvframeTheme,
  Ve as mapLang,
  je as mapLangPath,
  Ue as mergeMaps,
  Be as patchMaps,
  Le as persistMvframeTheme,
  X as sanitizeDownloadFileName,
  Ie as setMvframeRqEnv,
  k as useForm,
  ge as useGet,
  Re as useLang,
  pe as useLogin,
  Ne as useMap,
  ve as useOptions,
  ye as usePost,
  Pe as useRemoteSummary,
  Ce as useXform
};
