import { useEffect } from 'react';

const ATTRIBUTE_NAME_LIST = "data-anv-dialogs";
const ATTRIBUTE_NAME_BOOL = "data-anv-dialogs-open";
const useDialogScrollLock = ({
  open,
  id,
  enableScrollChaining,
  elementRef
}) => {
  useEffect(() => {
    if (enableScrollChaining) return () => {
    };
    const root = elementRef.current?.getRootNode();
    if (!(root instanceof ShadowRoot)) return () => {
    };
    const updateDialogAttributes = (shouldAdd) => {
      const currentDialogs = root.host.getAttribute(ATTRIBUTE_NAME_LIST)?.split(" ").filter(Boolean) ?? [];
      const newDialogs = new Set(currentDialogs);
      if (shouldAdd) {
        newDialogs.add(id);
      } else {
        newDialogs.delete(id);
      }
      const dialogList = Array.from(newDialogs);
      root.host.setAttribute(ATTRIBUTE_NAME_LIST, dialogList.join(" "));
      if (dialogList.length > 0) {
        root.host.setAttribute(ATTRIBUTE_NAME_BOOL, "true");
      } else {
        root.host.removeAttribute(ATTRIBUTE_NAME_BOOL);
      }
    };
    updateDialogAttributes(open);
    return () => {
      updateDialogAttributes(false);
    };
  }, [open, id, enableScrollChaining, elementRef]);
};

export { useDialogScrollLock as u };
//# sourceMappingURL=useDialogScrollLock-BW-aVboo.js.map
