"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("../../../../../vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js");
const index = require("../../../../../@css-render_vue3-ssr@0.15.12_vue@3.3.4/node_modules/@css-render/vue3-ssr/esm/index.js");
const index_cssr = require("../_styles/global/index.cssr.js");
const context = require("../config-provider/src/context.js");
const common = require("./common.js");
const merge = require("../../../../../lodash-es@4.17.21/node_modules/lodash-es/merge.js");
const runtimeCore_esmBundler = require("../../../../../@vue_runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js");
function useTheme(resolveId, mountId, style, defaultTheme, props, clsPrefixRef) {
  const ssrAdapter = index.useSsrAdapter();
  const NConfigProvider = runtimeCore_esmBundler.inject(context.configProviderInjectionKey, null);
  if (style) {
    const mountStyle = () => {
      const clsPrefix = clsPrefixRef === null || clsPrefixRef === void 0 ? void 0 : clsPrefixRef.value;
      style.mount({
        id: clsPrefix === void 0 ? mountId : clsPrefix + mountId,
        head: true,
        props: {
          bPrefix: clsPrefix ? `.${clsPrefix}-` : void 0
        },
        anchorMetaName: common.cssrAnchorMetaName,
        ssr: ssrAdapter
      });
      if (!(NConfigProvider === null || NConfigProvider === void 0 ? void 0 : NConfigProvider.preflightStyleDisabled)) {
        index_cssr.default.mount({
          id: "n-global",
          head: true,
          anchorMetaName: common.cssrAnchorMetaName,
          ssr: ssrAdapter
        });
      }
    };
    if (ssrAdapter) {
      mountStyle();
    } else {
      runtimeCore_esmBundler.onBeforeMount(mountStyle);
    }
  }
  const mergedThemeRef = runtimeCore_esmBundler.computed(() => {
    var _a;
    const { theme: { common: selfCommon, self, peers = {} } = {}, themeOverrides: selfOverrides = {}, builtinThemeOverrides: builtinOverrides = {} } = props;
    const { common: selfCommonOverrides, peers: peersOverrides } = selfOverrides;
    const { common: globalCommon = void 0, [resolveId]: { common: globalSelfCommon = void 0, self: globalSelf = void 0, peers: globalPeers = {} } = {} } = (NConfigProvider === null || NConfigProvider === void 0 ? void 0 : NConfigProvider.mergedThemeRef.value) || {};
    const { common: globalCommonOverrides = void 0, [resolveId]: globalSelfOverrides = {} } = (NConfigProvider === null || NConfigProvider === void 0 ? void 0 : NConfigProvider.mergedThemeOverridesRef.value) || {};
    const { common: globalSelfCommonOverrides, peers: globalPeersOverrides = {} } = globalSelfOverrides;
    const mergedCommon = merge.default({}, selfCommon || globalSelfCommon || globalCommon || defaultTheme.common, globalCommonOverrides, globalSelfCommonOverrides, selfCommonOverrides);
    const mergedSelf = merge.default(
      // {}, executed every time, no need for empty obj
      (_a = self || globalSelf || defaultTheme.self) === null || _a === void 0 ? void 0 : _a(mergedCommon),
      builtinOverrides,
      globalSelfOverrides,
      selfOverrides
    );
    return {
      common: mergedCommon,
      self: mergedSelf,
      peers: merge.default({}, defaultTheme.peers, globalPeers, peers),
      peerOverrides: merge.default({}, builtinOverrides.peers, globalPeersOverrides, peersOverrides)
    };
  });
  return mergedThemeRef;
}
useTheme.props = {
  theme: Object,
  themeOverrides: Object,
  builtinThemeOverrides: Object
};
exports.default = useTheme;
