"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useTreeViewInstanceEvents = void 0;
var React = _interopRequireWildcard(require("react"));
var _EventManager = require("@mui/x-internals/EventManager");
const isSyntheticEvent = event => {
  return event.isPropagationStopped !== undefined;
};
const useTreeViewInstanceEvents = () => {
  const [eventManager] = React.useState(() => new _EventManager.EventManager());
  const publishEvent = React.useCallback((...args) => {
    const [name, params, event = {}] = args;
    event.defaultMuiPrevented = false;
    if (isSyntheticEvent(event) && event.isPropagationStopped()) {
      return;
    }
    eventManager.emit(name, params, event);
  }, [eventManager]);
  const subscribeEvent = React.useCallback((event, handler) => {
    eventManager.on(event, handler);
    return () => {
      eventManager.removeListener(event, handler);
    };
  }, [eventManager]);
  return {
    instance: {
      $$publishEvent: publishEvent,
      $$subscribeEvent: subscribeEvent
    }
  };
};
exports.useTreeViewInstanceEvents = useTreeViewInstanceEvents;
useTreeViewInstanceEvents.params = {};