"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Context = void 0;
exports.useDialogContext = useDialogContext;
exports.useDialogControl = useDialogControl;
var _react = require("react");
const Context = exports.Context = /*#__PURE__*/(0, _react.createContext)({
  close: () => {},
  isWithinDialog: false
});
Context.displayName = 'BloomDialogContext';
function useDialogContext() {
  return (0, _react.useContext)(Context);
}

/**
 * Return a stable handle that can imperatively `open()` and `close()` a
 * `<Dialog>` mounted with the same control.
 *
 * The handle survives across re-renders; mounting a different `<Dialog>`
 * with the same control attaches the new instance via the internal ref.
 */
function useDialogControl() {
  const id = (0, _react.useId)();
  const control = (0, _react.useRef)({
    open: () => {},
    close: () => {}
  });
  return (0, _react.useMemo)(() => ({
    id,
    ref: control,
    open: () => {
      control.current?.open();
    },
    close: cb => {
      control.current?.close(cb);
    }
  }), [id]);
}
//# sourceMappingURL=context.js.map