import { markAncestor } from './3NDVDEB4.js';
import { useDisclosureContent } from './KFH4SEIX.js';
import { useDisclosureStore } from './WYCIER3C.js';
import { Role } from './XL7CSKGW.js';
import { useStoreState } from './YV4JVR4I.js';
import { useSafeLayoutEffect } from './ABQUS43J.js';
import { __spreadProps, __spreadValues } from './3YLGPPWQ.js';
import { useRef, useEffect, isValidElement } from 'react';
import { j as jsxRuntimeExports } from '../../../../../../react@18.2.0/node_modules/react/jsx-runtime.js';

function DialogBackdrop({
  store,
  backdrop,
  alwaysVisible,
  hidden
}) {
  const ref = useRef(null);
  const disclosure = useDisclosureStore({ disclosure: store });
  const contentElement = useStoreState(store, "contentElement");
  useEffect(() => {
    const backdrop2 = ref.current;
    const dialog = contentElement;
    if (!backdrop2) return;
    if (!dialog) return;
    backdrop2.style.zIndex = getComputedStyle(dialog).zIndex;
  }, [contentElement]);
  useSafeLayoutEffect(() => {
    const id = contentElement == null ? void 0 : contentElement.id;
    if (!id) return;
    const backdrop2 = ref.current;
    if (!backdrop2) return;
    return markAncestor(backdrop2, id);
  }, [contentElement]);
  const props = useDisclosureContent({
    ref,
    store: disclosure,
    role: "presentation",
    "data-backdrop": (contentElement == null ? void 0 : contentElement.id) || "",
    alwaysVisible,
    hidden: hidden != null ? hidden : void 0,
    style: {
      position: "fixed",
      top: 0,
      right: 0,
      bottom: 0,
      left: 0
    }
  });
  if (!backdrop) return null;
  if (isValidElement(backdrop)) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx(Role, __spreadProps(__spreadValues({}, props), { render: backdrop }));
  }
  const Component = typeof backdrop !== "boolean" ? backdrop : "div";
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Role, __spreadProps(__spreadValues({}, props), { render: /* @__PURE__ */ jsxRuntimeExports.jsx(Component, {}) }));
}

export { DialogBackdrop };
//# sourceMappingURL=JEWPFJH2.js.map
