import { css as C } from "@emotion/css";
import { merge as k, cloneDeep as x, omit as y } from "lodash-unified";
import { ref as p, getCurrentInstance as v, inject as T, computed as u, provide as K, unref as b, watch as j } from "vue";
import { defaultToken as w } from "../../design-token/constants.mjs";
import { generateCssVar as G } from "../../utils/cssinjs/utils.mjs";
import { configProviderContextKey as d } from "../constants.mjs";
import { localeContextKey as I } from "./use-locale.mjs";
import { namespaceContextKey as O } from "./use-namespace.mjs";
import { designTokenContextKey as S } from "./use-token.mjs";
const m = (e) => Object.keys(e), a = p();
function V(e, o = void 0) {
  const n = v() ? T(d, a) : a;
  return e ? u(() => n.value?.[e] ?? o) : n;
}
const E = (e, o, n = !1) => {
  const i = !!v(), t = i ? V() : void 0, s = o?.provide ?? (i ? K : void 0);
  if (!s)
    return;
  const r = u(() => {
    const c = b(e);
    return t?.value ? h(t.value, c) : c;
  });
  s(d, r), s(
    I,
    u(() => r.value.aplusLocale)
  ), s(O, r.value.namespace);
  const f = u(() => ({
    ...k(x(w), r.value.aplusToken || {})
  })), l = p();
  return j(
    () => f.value,
    () => {
      const c = y(f.value, ["components"]), g = G(c, {
        uniqueId: !0,
        skipUnit: []
      });
      l.value = C(g);
    },
    { deep: !0, immediate: !0 }
  ), s(S, { token: f, rootCls: l }), (n || !a.value) && (a.value = r.value), r;
}, h = (e, o) => {
  const n = [.../* @__PURE__ */ new Set([...m(e), ...m(o)])], i = {};
  for (const t of n)
    i[t] = o[t] !== void 0 ? o[t] : e[t];
  return i;
};
export {
  m as keysOf,
  E as provideGlobalConfig,
  V as useGlobalConfig
};
