"use strict";
"use client";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var root_style_registry_exports = {};
__export(root_style_registry_exports, {
  RootStyleRegistry: () => RootStyleRegistry,
  StyleTagSSR: () => StyleTagSSR,
  createRootStyleCache: () => createRootStyleCache,
  styleTagHtml: () => styleTagHtml,
  useCSSResetEnabled: () => useCSSResetEnabled,
  useCache: () => useCache
});
module.exports = __toCommonJS(root_style_registry_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_cache = __toESM(require("@emotion/cache"));
var import_css = require("@emotion/css");
var import_react = require("react");
const CacheContext = (0, import_react.createContext)(import_css.cache);
const DEFAULT_CSS_RESET_ENABLED = true;
const CSSResetEnabledContext = (0, import_react.createContext)(DEFAULT_CSS_RESET_ENABLED);
const createRootStyleCache = ({ key } = {}) => {
  const cache2 = (0, import_cache.default)({ key: key ?? "mswft" });
  cache2.compat = true;
  let inserted = [];
  return {
    ...cache2,
    // override the `insert` method to track inserted names
    insert(...args) {
      const serialized = args[1];
      if (cache2.inserted[serialized.name] === void 0) {
        inserted.push(serialized.name);
      }
      return cache2.insert(...args);
    },
    flush() {
      const classNames = inserted;
      inserted = [];
      return {
        classNames,
        css: classNames.reduce((css, name) => {
          return css + cache2.inserted[name];
        }, "")
      };
    }
  };
};
const StyleTagSSR = ({ cacheKey, classNames, css }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
  "style",
  {
    "data-emotion": `${cacheKey} ${classNames.join(" ")}`,
    dangerouslySetInnerHTML: {
      __html: css
    }
  }
);
const styleTagHtml = ({ cacheKey, classNames, css }) => `<style data-emotion="${cacheKey} ${classNames.join(" ")}">${css}</style>`;
function RootStyleRegistry({
  children,
  cache: cache2,
  enableCssReset
}) {
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CacheContext.Provider, { value: cache2, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CSSResetEnabledContext.Provider, { value: enableCssReset ?? DEFAULT_CSS_RESET_ENABLED, children }) });
}
function useCache() {
  return (0, import_react.useContext)(CacheContext);
}
function useCSSResetEnabled() {
  return (0, import_react.useContext)(CSSResetEnabledContext);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  RootStyleRegistry,
  StyleTagSSR,
  createRootStyleCache,
  styleTagHtml,
  useCSSResetEnabled,
  useCache
});
//# sourceMappingURL=root-style-registry.js.map