"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useMutationObserver = void 0;
var _react = require("react");
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

const useMutationObserver = _ref => {
  let {
    ref,
    onMutate,
    options
  } = _ref;
  const onMutateRef = (0, _react.useRef)(undefined);
  onMutateRef.current = onMutate;
  (0, _react.useEffect)(() => {
    if (!ref.current) return undefined;
    if (typeof window === 'undefined' || !('MutationObserver' in window)) return undefined;
    const observer = new MutationObserver(() => {
      onMutateRef.current?.();
    });
    observer.observe(ref.current, options);
    return () => {
      observer.disconnect();
    };
  }, [ref, options]);
};
exports.useMutationObserver = useMutationObserver;