"use strict";
Object.defineProperty(exports, 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 context = require("../config-provider/src/context.js");
const index$1 = require("../_utils/cssr/index.js");
const warn = require("../_utils/naive/warn.js");
const hash_browser_esm = require("../../../../../@emotion_hash@0.8.0/node_modules/@emotion/hash/dist/hash.browser.esm.js");
const runtimeCore_esmBundler = require("../../../../../@vue_runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js");
const reactivity_esmBundler = require("../../../../../@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js");
function useThemeClass(componentName, hashRef, cssVarsRef, props) {
  var _a;
  if (!cssVarsRef)
    warn.throwError("useThemeClass", "cssVarsRef is not passed");
  const mergedThemeHashRef = (_a = runtimeCore_esmBundler.inject(context.configProviderInjectionKey, null)) === null || _a === void 0 ? void 0 : _a.mergedThemeHashRef;
  const themeClassRef = reactivity_esmBundler.ref("");
  const ssrAdapter = index.useSsrAdapter();
  let renderCallback;
  const hashClassPrefix = `__${componentName}`;
  const mountStyle = () => {
    let finalThemeHash = hashClassPrefix;
    const hashValue = hashRef ? hashRef.value : void 0;
    const themeHash = mergedThemeHashRef === null || mergedThemeHashRef === void 0 ? void 0 : mergedThemeHashRef.value;
    if (themeHash)
      finalThemeHash += "-" + themeHash;
    if (hashValue)
      finalThemeHash += "-" + hashValue;
    const { themeOverrides, builtinThemeOverrides } = props;
    if (themeOverrides) {
      finalThemeHash += "-" + hash_browser_esm.default(JSON.stringify(themeOverrides));
    }
    if (builtinThemeOverrides) {
      finalThemeHash += "-" + hash_browser_esm.default(JSON.stringify(builtinThemeOverrides));
    }
    themeClassRef.value = finalThemeHash;
    renderCallback = () => {
      const cssVars = cssVarsRef.value;
      let style = "";
      for (const key in cssVars) {
        style += `${key}: ${cssVars[key]};`;
      }
      index$1.c(`.${finalThemeHash}`, style).mount({
        id: finalThemeHash,
        ssr: ssrAdapter
      });
      renderCallback = void 0;
    };
  };
  runtimeCore_esmBundler.watchEffect(() => {
    mountStyle();
  });
  return {
    themeClass: themeClassRef,
    onRender: () => {
      renderCallback === null || renderCallback === void 0 ? void 0 : renderCallback();
    }
  };
}
exports.useThemeClass = useThemeClass;
