"use client";
'use strict';

var AOUGVQZ3 = require('./AOUGVQZ3.cjs');
var K2ZF5NU7 = require('./K2ZF5NU7.cjs');
var _63XF7ACK = require('./63XF7ACK.cjs');
var PBFD2E7P = require('../../../../../../@ariakit_core@0.4.15/node_modules/@ariakit/core/esm/__chunks/PBFD2E7P.cjs');

function getPropertyName(id = "", ancestor = false) {
  return `__ariakit-dialog-${ancestor ? "ancestor" : "outside"}${id ? `-${id}` : ""}`;
}
function markElement(element, id = "") {
  return PBFD2E7P.chain(
    K2ZF5NU7.setProperty(element, getPropertyName(), true),
    K2ZF5NU7.setProperty(element, getPropertyName(id), true)
  );
}
function markAncestor(element, id = "") {
  return PBFD2E7P.chain(
    K2ZF5NU7.setProperty(element, getPropertyName("", true), true),
    K2ZF5NU7.setProperty(element, getPropertyName(id, true), true)
  );
}
function isElementMarked(element, id) {
  const ancestorProperty = getPropertyName(id, true);
  if (element[ancestorProperty]) return true;
  const elementProperty = getPropertyName(id);
  do {
    if (element[elementProperty]) return true;
    if (!element.parentElement) return false;
    element = element.parentElement;
  } while (true);
}
function markTreeOutside(id, elements) {
  const cleanups = [];
  const ids = elements.map((el) => el == null ? void 0 : el.id);
  AOUGVQZ3.walkTreeOutside(
    id,
    elements,
    (element) => {
      if (_63XF7ACK.isBackdrop(element, ...ids)) return;
      cleanups.unshift(markElement(element, id));
    },
    (ancestor, element) => {
      const isAnotherDialogAncestor = element.hasAttribute("data-dialog") && element.id !== id;
      if (isAnotherDialogAncestor) return;
      cleanups.unshift(markAncestor(ancestor, id));
    }
  );
  const restoreAccessibilityTree = () => {
    for (const cleanup of cleanups) {
      cleanup();
    }
  };
  return restoreAccessibilityTree;
}

exports.isElementMarked = isElementMarked;
exports.markAncestor = markAncestor;
exports.markElement = markElement;
exports.markTreeOutside = markTreeOutside;
//# sourceMappingURL=3NDVDEB4.cjs.map
