"use strict";

import { createContext, useContext, useId, useMemo, useRef } from 'react';
export const Context = /*#__PURE__*/createContext({
  close: () => {},
  isWithinDialog: false
});
Context.displayName = 'BloomDialogContext';
export function useDialogContext() {
  return 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.
 */
export function useDialogControl() {
  const id = useId();
  const control = useRef({
    open: () => {},
    close: () => {}
  });
  return useMemo(() => ({
    id,
    ref: control,
    open: () => {
      control.current?.open();
    },
    close: cb => {
      control.current?.close(cb);
    }
  }), [id]);
}
//# sourceMappingURL=context.js.map