"use client";
'use strict';

var ABQUS43J = require('./ABQUS43J.cjs');
var DTR5TSDJ = require('../../../../../../@ariakit_core@0.4.15/node_modules/@ariakit/core/esm/__chunks/DTR5TSDJ.cjs');
var React = require('react');
var ReactDOM = require('react-dom');

function useRootDialog({
  attribute,
  contentId,
  contentElement,
  enabled
}) {
  const [updated, retry] = ABQUS43J.useForceUpdate();
  const isRootDialog = React.useCallback(() => {
    if (!enabled) return false;
    if (!contentElement) return false;
    const { body } = DTR5TSDJ.getDocument(contentElement);
    const id = body.getAttribute(attribute);
    return !id || id === contentId;
  }, [updated, enabled, contentElement, attribute, contentId]);
  React.useEffect(() => {
    if (!enabled) return;
    if (!contentId) return;
    if (!contentElement) return;
    const { body } = DTR5TSDJ.getDocument(contentElement);
    if (isRootDialog()) {
      body.setAttribute(attribute, contentId);
      return () => body.removeAttribute(attribute);
    }
    const observer = new MutationObserver(() => ReactDOM.flushSync(retry));
    observer.observe(body, { attributeFilter: [attribute] });
    return () => observer.disconnect();
  }, [updated, enabled, contentId, contentElement, isRootDialog, attribute]);
  return isRootDialog;
}

exports.useRootDialog = useRootDialog;
//# sourceMappingURL=YKJECYU7.cjs.map
