import { ref as h, computed as b } from "vue";
const d = h("light"), i = h({
  light: {},
  dark: {}
}), u = h({
  light: {},
  dark: {}
}), v = "dasTheme", r = "das-theme", y = (t) => {
  let e = {
    light: {},
    dark: {}
  };
  if (!t) return e;
  const { light: l = {}, dark: n = {}, base: a = {}, ...s } = t || {};
  e.light = { ...l, ...a }, e.dark = n || {};
  for (const o in s) {
    const c = s[o];
    if (typeof c == "string" && (e.light[o] = c), typeof c == "object")
      for (const m in c)
        e[m] || (e[m] = {}), e[m][o] || (e[m][o] = {}), e[m][o] = c[m];
  }
  return e;
};
function T(t) {
  const e = "das-global-theme", l = "das-custom-theme";
  if (!document.getElementById(l)) {
    const a = document.createElement("style");
    a.appendChild(document.createTextNode("")), a.setAttribute("id", l), document.head.appendChild(a);
  }
  if (!document.getElementById(e)) {
    const a = document.createElement("style");
    a.appendChild(document.createTextNode("")), a.setAttribute("id", e), document.head.appendChild(a);
  }
  t || (t = "custom");
  let n = document.getElementById(l);
  return t === "global" && (n = document.getElementById(e)), n.sheet;
}
const g = (t, e) => {
  e || (e = "custom");
  const l = T(e), n = y(t);
  for (const s in n) {
    const o = n[s];
    for (const c in o) {
      const m = o[c], f = `${r}-${s}`;
      l.insertRule(`.${f} { ${c}:${m} } `, l.cssRules.length);
    }
    e === "global" && (u.value[s] || (u.value[s] = {}), u.value[s] = { ...u.value[s], ...o }), e === "custom" && (i.value[s] || (i.value[s] = {}), i.value[s] = { ...i.value[s], ...o });
  }
  const a = `${r}-${d.value}`;
  document.body.classList.contains(a) || document.body.classList.add(a);
}, D = async (t) => {
  var n, a;
  const e = window[v];
  e && g(e, "global");
  let l = Object.assign(((n = t == null ? void 0 : t.theme) == null ? void 0 : n.glob) || {});
  (a = t == null ? void 0 : t.microApps) == null || a.map((s) => {
    var o;
    l = Object.assign(l, ((o = s.theme) == null ? void 0 : o.glob) || {});
  }), Object.values(l).filter((s) => !!s).flat().map((s) => g(s));
}, C = (t) => {
  document.body.classList.add(`${r}-light`), t === "light" && document.body.classList.remove(`${r}-${d.value}`), d.value = t, document.body.classList.add(`${r}-${d.value}`);
}, $ = (t) => b(() => {
  var e, l, n, a;
  return ((l = (e = u.value) == null ? void 0 : e[d.value]) == null ? void 0 : l[t]) || ((a = (n = i.value) == null ? void 0 : n[d.value]) == null ? void 0 : a[t]) || t;
}), E = (t) => `var(${t})`, R = $, x = {};
export {
  d as currentTheme,
  x as default,
  $ as getThemeRule,
  E as getVar,
  R as getVarValue,
  D as initTheme,
  C as setTheme,
  g as setThemeRule
};
