"use client";
import { jsx } from "react/jsx-runtime";
import createCache from "@emotion/cache";
import { cache } from "@emotion/css";
import { createContext, useContext } from "react";
const CacheContext = createContext(cache);
const DEFAULT_CSS_RESET_ENABLED = true;
const CSSResetEnabledContext = createContext(DEFAULT_CSS_RESET_ENABLED);
const createRootStyleCache = ({ key } = {}) => {
  const cache2 = createCache({ 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__ */ 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__ */ jsx(CacheContext.Provider, { value: cache2, children: /* @__PURE__ */ jsx(CSSResetEnabledContext.Provider, { value: enableCssReset ?? DEFAULT_CSS_RESET_ENABLED, children }) });
}
function useCache() {
  return useContext(CacheContext);
}
function useCSSResetEnabled() {
  return useContext(CSSResetEnabledContext);
}
export {
  RootStyleRegistry,
  StyleTagSSR,
  createRootStyleCache,
  styleTagHtml,
  useCSSResetEnabled,
  useCache
};
//# sourceMappingURL=root-style-registry.js.map