{"version":3,"file":"useLayerOrder.mjs","sources":["../../../../../../../../../node_modules/@mui/system/esm/ThemeProvider/useLayerOrder.js"],"sourcesContent":["import * as React from 'react';\nimport useEnhancedEffect from '@mui/utils/useEnhancedEffect';\nimport useId from '@mui/utils/useId';\nimport GlobalStyles from \"../GlobalStyles/index.js\";\nimport useThemeWithoutDefault from \"../useThemeWithoutDefault/index.js\";\n\n/**\n * This hook returns a `GlobalStyles` component that sets the CSS layer order (for server-side rendering).\n * Then on client-side, it injects the CSS layer order into the document head to ensure that the layer order is always present first before other Emotion styles.\n */\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nexport default function useLayerOrder(theme) {\n  const upperTheme = useThemeWithoutDefault();\n  const id = useId() || '';\n  const {\n    modularCssLayers\n  } = theme;\n  let layerOrder = 'mui.global, mui.components, mui.theme, mui.custom, mui.sx';\n  if (!modularCssLayers || upperTheme !== null) {\n    // skip this hook if upper theme exists.\n    layerOrder = '';\n  } else if (typeof modularCssLayers === 'string') {\n    layerOrder = modularCssLayers.replace(/mui(?!\\.)/g, layerOrder);\n  } else {\n    layerOrder = `@layer ${layerOrder};`;\n  }\n  useEnhancedEffect(() => {\n    const head = document.querySelector('head');\n    if (!head) {\n      return;\n    }\n    const firstChild = head.firstChild;\n    if (layerOrder) {\n      // Only insert if first child doesn't have data-mui-layer-order attribute\n      if (firstChild && firstChild.hasAttribute?.('data-mui-layer-order') && firstChild.getAttribute('data-mui-layer-order') === id) {\n        return;\n      }\n      const styleElement = document.createElement('style');\n      styleElement.setAttribute('data-mui-layer-order', id);\n      styleElement.textContent = layerOrder;\n      head.prepend(styleElement);\n    } else {\n      head.querySelector(`style[data-mui-layer-order=\"${id}\"]`)?.remove();\n    }\n  }, [layerOrder, id]);\n  if (!layerOrder) {\n    return null;\n  }\n  return /*#__PURE__*/_jsx(GlobalStyles, {\n    styles: layerOrder\n  });\n}"],"names":["useThemeWithoutDefault","_jsx"],"mappings":";;;;;;;AAWe,SAAS,aAAa,CAAC,KAAK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