"use client";
'use strict';

var IGR4SXG2 = require('./IGR4SXG2.cjs');
var _677M2CI3 = require('./677M2CI3.cjs');
var S7U6BLGA = require('./S7U6BLGA.cjs');
var AOUGVQZ3 = require('./AOUGVQZ3.cjs');
var K2ZF5NU7 = require('./K2ZF5NU7.cjs');
var _63XF7ACK = require('./63XF7ACK.cjs');
var DTR5TSDJ = require('../../../../../../@ariakit_core@0.4.15/node_modules/@ariakit/core/esm/__chunks/DTR5TSDJ.cjs');
var focus = require('../../../../../../@ariakit_core@0.4.15/node_modules/@ariakit/core/esm/utils/focus.cjs');
var PBFD2E7P = require('../../../../../../@ariakit_core@0.4.15/node_modules/@ariakit/core/esm/__chunks/PBFD2E7P.cjs');

function disableTree(element, ignoredElements) {
  if (!("style" in element)) return PBFD2E7P.noop;
  if (_677M2CI3.supportsInert()) {
    return K2ZF5NU7.setProperty(element, "inert", true);
  }
  const tabbableElements = focus.getAllTabbableIn(element, true);
  const enableElements = tabbableElements.map((element2) => {
    if (ignoredElements == null ? void 0 : ignoredElements.some((el) => el && DTR5TSDJ.contains(el, element2))) return PBFD2E7P.noop;
    const restoreFocusMethod = K2ZF5NU7.orchestrate(element2, "focus", () => {
      element2.focus = PBFD2E7P.noop;
      return () => {
        delete element2.focus;
      };
    });
    return PBFD2E7P.chain(K2ZF5NU7.setAttribute(element2, "tabindex", "-1"), restoreFocusMethod);
  });
  return PBFD2E7P.chain(
    ...enableElements,
    S7U6BLGA.hideElementFromAccessibilityTree(element),
    K2ZF5NU7.assignStyle(element, {
      pointerEvents: "none",
      userSelect: "none",
      cursor: "default"
    })
  );
}
function disableTreeOutside(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;
      if (IGR4SXG2.isFocusTrap(element, ...ids)) return;
      cleanups.unshift(disableTree(element, elements));
    },
    (element) => {
      if (!element.hasAttribute("role")) return;
      if (elements.some((el) => el && DTR5TSDJ.contains(el, element))) return;
      cleanups.unshift(K2ZF5NU7.setAttribute(element, "role", "none"));
    }
  );
  const restoreTreeOutside = () => {
    for (const cleanup of cleanups) {
      cleanup();
    }
  };
  return restoreTreeOutside;
}

exports.disableTree = disableTree;
exports.disableTreeOutside = disableTreeOutside;
//# sourceMappingURL=Z5GCVBAY.cjs.map
