import { jsx } from 'react/jsx-runtime';
import { T as ThemeProvider } from './ThemeProvider-Sd8LK0A9.js';
import { t as themeStyles } from './ThemeProvider.module-_7m6Tav-.js';
import { createContext, useEffect, useState, useMemo } from 'react';
import { c as cx } from './index-De1g9FRV.js';
import { u as useBreakpoint } from './useBreakpoint-BBNRlMGZ.js';
import { a as useTranslations, L as LocalizationContext } from './LocalizationContext-UsmB5mnR.js';
import { T as TrackingProvider } from './TrackingProvider-Co4lyoI9.js';
import { u as useLayoutPropsUtil } from './useLayoutPropsUtil-DjqeAJZ9.js';

import './AnvilProvider.css';const AnvilProviderContext = createContext(
  {}
);
const TooltipLegacyGroupContext = createContext(null);

let bodyScopeRefcount = 0;
const AnvilProvider = (props) => {
  const { layoutStyles, componentProps } = useLayoutPropsUtil(props);
  const {
    themeData,
    localizationData,
    trackingIdData,
    // Deprecated, no-op: kept so existing callers still type-check. See
    // AnvilProviderProps.cssUtils for the replacement.
    cssUtils: _cssUtils,
    children,
    className,
    style,
    ...rest
  } = componentProps;
  const {
    locale = "en",
    dir = "ltr",
    translations = {}
  } = localizationData ?? {};
  const { scope = "ST", optOut } = trackingIdData ?? {};
  const classNameCombined = cx(
    className,
    "anvil2",
    [themeStyles["theme-core"]],
    {
      [themeStyles["mode-dark"]]: themeData?.mode === "dark",
      [themeStyles["mode-light"]]: themeData?.mode === "light"
    }
  );
  const styleCombined = {
    ...style,
    ...layoutStyles
  };
  const breakpoint = useBreakpoint();
  useEffect(() => {
    bodyScopeRefcount += 1;
    document.body.classList.add("anvil2");
    return () => {
      bodyScopeRefcount = Math.max(0, bodyScopeRefcount - 1);
      if (bodyScopeRefcount === 0) {
        document.body.classList.remove("anvil2");
      }
    };
  }, []);
  const [disableDelayGroup, setDisableDelayGroup] = useState(false);
  const { translations: t } = useTranslations(translations);
  const localizationContextValue = useMemo(() => ({ locale, t }), [locale, t]);
  const tooltipLegacyGroupContextValue = useMemo(
    () => ({ disableDelayGroup: setDisableDelayGroup }),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    [disableDelayGroup]
  );
  return /* @__PURE__ */ jsx(AnvilProviderContext.Provider, { value: { breakpoint }, children: /* @__PURE__ */ jsx(
    ThemeProvider,
    {
      className: classNameCombined,
      style: styleCombined,
      theme: themeData?.theme,
      mode: themeData?.mode,
      dir,
      ...rest,
      children: /* @__PURE__ */ jsx(
        TooltipLegacyGroupContext.Provider,
        {
          value: tooltipLegacyGroupContextValue,
          children: /* @__PURE__ */ jsx(LocalizationContext.Provider, { value: localizationContextValue, children: /* @__PURE__ */ jsx(TrackingProvider, { scope, optOut, children }) })
        }
      )
    }
  ) });
};

export { AnvilProvider as A, AnvilProviderContext as a };
//# sourceMappingURL=AnvilProvider-b3gvW6Md.js.map
