import { MVFRAME_STORAGE_LANG as N } from "./composition.js";
import { e as P } from "./vendor.js";
import { d as f, i as j, q as R } from "./dayjs.js";
f.extend(j);
f.extend(R);
const Q = (s) => {
  globalThis.$d = f;
  const u = P();
  s.config.globalProperties.$message = u, globalThis.$message = u;
  const g = (e) => {
    if (e.startsWith("/"))
      return new URL(e, import.meta.url).href;
    if (e)
      return new URL((/* @__PURE__ */ Object.assign({}))[`/src/assets/img/${e}`], import.meta.url).href;
    throw new Error("please provide an image url with getImg");
  };
  s.config.globalProperties.$getImg = g, globalThis.$getImg = g, globalThis.$getLang = () => {
    var e;
    return localStorage.getItem(N) || ((e = globalThis.$config) == null ? void 0 : e.lang) || "en_us";
  }, globalThis.token = "WQpvrYIEnSzAxhOWrbUpGvElhGztdOjOGOdbrSlhUYlrQArOdpMhY1vYMSA7l4xMOUl9MAl1I6AvSrQ8vlE0bpChQ0UWMMlYt0hQC0M0pSz0rUhvlIllSWzMESnAMUlt";
  const y = (e) => Number(e.match(/\d+(\.\d+)?/g).join(""));
  globalThis.$md5 = (e) => y(e);
  const T = (e, r = 0) => {
    let o = parseInt(Math.random() * e);
    return o += r, o;
  };
  globalThis.$rn = T;
  const C = (e, r) => {
    let o = [];
    for (let t = 0; t < e; t++)
      o.push(r(t));
    return o;
  };
  globalThis.$fd = C;
  const p = (e, r = !1) => e.substr(0, 1).toUpperCase() + (r ? e.substr(1, e.length).toLowerCase() : e.substr(1, e.length));
  s.config.globalProperties.$toUpperCamel = p, globalThis.$toUpperCamel = p;
  const b = (e, r = 2) => {
    const o = globalThis.$getType(e);
    let t;
    o === "Number" ? (e = e.toFixed(r), t = String(e), e = String(Math.abs(e))) : o === "String" && (t = e, e = String(Math.abs(Number(e))));
    const l = e.split(".");
    let n = l[0].split("");
    n = n.reverse();
    let a = [];
    n.forEach((I, $) => {
      $ !== 0 && $ % 3 === 0 && a.push(","), a.push(I);
    });
    let i = a.reverse().join("");
    return globalThis.$getType(r) === "Number" && r > 0 && (i += ".", l[1] ? i += l[1].padEnd(r, 0).substr(0, r) : i += "0".padEnd(r, "0")), Number(t) !== Number(e) ? `-${i}` : i;
  };
  globalThis.$fa = b, s.config.globalProperties.$fa = b;
  const M = (e, r) => {
    var l, n;
    const o = r == null ? void 0 : r[e];
    if (o != null)
      return o;
    const t = (n = (l = globalThis.$config) == null ? void 0 : l.table) == null ? void 0 : n.summaryMetric;
    return t == null ? null : typeof t == "function" ? t(e) ?? null : t[e] ?? null;
  }, h = ({ prop: e, currency: r, value: o, obj: t }) => {
    const l = M(e, t);
    if (l == null || typeof l != "object")
      return globalThis.$fa(o, 2);
    if (l.unit === "currency") {
      const n = r ?? l.currency;
      return n ? `${n} ${globalThis.$fa(o, l == null ? void 0 : l.precision)}` : globalThis.$fa(o, l == null ? void 0 : l.precision);
    }
    return l.unit === "%" ? `${globalThis.$fa(o, l == null ? void 0 : l.precision)}%` : globalThis.$fa(o, l == null ? void 0 : l.precision);
  };
  globalThis.$fu = h, s.config.globalProperties.$fu = h;
  const k = (e = () => {
  }, r = 2) => {
    const o = Math.max(0, Number(r) || 2) * 100;
    return new Promise((t, l) => {
      setTimeout(() => {
        try {
          const n = e();
          n != null && typeof n.then == "function" ? Promise.resolve(n).then((a) => t(a === void 0 ? !0 : a)).catch(l) : t(n === void 0 ? !0 : n);
        } catch (n) {
          l(n);
        }
      }, o);
    });
  };
  globalThis.$pm = k;
  const x = (e = () => {
  }, r = 500) => {
    let o;
    return function(...t) {
      o && clearTimeout(o), o = setTimeout(() => {
        e.apply(this, t);
      }, r);
    };
  };
  globalThis.$db = x, Number.prototype.toFixedNumber = function(e) {
    return Number(this.toFixed(e));
  }, Array.prototype.filter1 = function(e) {
    if (!e || typeof e != "function")
      throw new Error(e + " is not a function");
    let r, o;
    for (let t = 0; t < this.length; t++)
      if (e(this[t], t, this)) {
        o = t, r = this[t];
        break;
      }
    return {
      index: o,
      data: r
    };
  }, globalThis.$getType = (e) => Object.prototype.toString.call(e).slice(8, -1);
  const m = (e) => {
    var r;
    (r = globalThis.$message) != null && r.success && globalThis.$message.success({ message: e, duration: 5e3 });
  }, d = (e, r) => {
    var l;
    if (!e) {
      console.info("No Value");
      return;
    }
    const o = ((l = globalThis.$l) == null ? void 0 : l.call(globalThis, "Copied")) || "Copied";
    let t;
    if (r ? globalThis.$getType(r) !== "Boolean" ? t = `${o} ${r}: ${e}` : t = `${o}: ${e}` : t = o, navigator.clipboard && globalThis.isSecureContext)
      navigator.clipboard.writeText(e).then(() => m(t));
    else {
      let n = document.createElement("textarea");
      n.value = e, n.style.position = "fixed", n.style.opacity = 0, document.body.appendChild(n), n.select(), document.execCommand("Copy"), n.remove(), m(t);
    }
  };
  globalThis.$copy = d, s.config.globalProperties.$copy = d;
  const F = (e) => e < 1e3 ? e : e < 1e6 ? parseInt(e / 1e3) + "k" : parseInt(e / 1e6) + "m";
  globalThis.$sc = F;
  const O = {
    cpa: "avgCPA",
    cpt: "avgCPT"
  }, w = (e, r = O) => {
    const o = r[e.name];
    o && (e.name = o);
  };
  globalThis.$nr = w;
  const A = (e, r) => (Object.keys(e).forEach((o) => {
    objMap[o] && (e[objMap[o]] = e[o], delete e[o]);
  }), e);
  globalThis.$nro = A;
  const S = (e) => {
    let r = 0;
    return Object.keys(e).forEach((o) => {
      (globalThis.$getType(e[o]) === "Array" && e[o].length !== 0 || e[o]) && r++;
    }), r;
  };
  globalThis.$pc = S;
  const c = {
    info: {
      tag: "background-color:#0085FF; color:#f1f7ff; border-radius: 2px 0 0 2px;",
      style: "background-color:#f1f7ff; color:#0085FF;"
    },
    log: {
      tag: "background-color:#FFFFFF; color:#272b41; border-radius: 2px 0 0 2px;",
      style: "background-color:#272b41; color:#FFFFFF;"
    },
    error: {
      tag: "background-color:#ff4d4f; color:#fff3f3; border-radius: 2px 0 0 2px;",
      style: "background-color:#fff3f3; color:#ff4d4f;"
    },
    warn: {
      tag: "background-color:#fa8b0c; color:#fffbf6; border-radius: 2px 0 0 2px;",
      style: "background-color:#fffbf6; color:#fa8b0c;"
    },
    success: {
      tag: "background-color:#20c997; color:#f6fffc; border-radius: 2px 0 0 2px;",
      style: "background-color:#f6fffc; color:#20c997;"
    }
  }, E = (e) => {
    let r = !1;
    for (let o in e)
      if (globalThis.$getType(e[o]) === "Object") {
        r = !0;
        break;
      }
    return r;
  }, U = ["info", "log", "warn", "error", "success"];
  globalThis.$c = {}, U.forEach((e) => {
    globalThis.$c[e] = (...r) => {
      const o = e.toUpperCase();
      E(r) ? (console.groupCollapsed(`%c ${o} `, `${c[e].tag}`), console[e](r), console.groupEnd()) : console.info(
        `%c ${o} %c┆${r}┆`,
        `${c[e].tag}`,
        `${c[e].style}`
      );
    };
  }), window.$deepClone = function(e) {
    if (e == null)
      return e;
    const r = window.$getType(e);
    if (r !== "Object" && r !== "Array")
      return e;
    let o = r === "Array" ? [] : {};
    for (let t in e)
      if (Object.prototype.hasOwnProperty.call(e, t)) {
        const l = window.$getType(e[t]);
        l === "Object" || l === "Array" ? o[t] = window.$deepClone(e[t]) : o[t] = e[t];
      }
    return o;
  };
};
export {
  Q as u
};
