import * as React from "react";
const emptyRefError = new Error("Dialog function called on an invalid dialog, are you sure you've added the ref to the Armstrong <Dialog> component?");
const useDialog = (forwardRef) => {
  const dialogRef = React.useRef(null);
  const [isOpen, setIsOpen] = React.useState(false);
  React.useImperativeHandle(forwardRef, () => dialogRef.current);
  const open = React.useCallback(() => {
    if (!dialogRef.current) {
      throw emptyRefError;
    }
    return dialogRef.current.open();
  }, []);
  const cancel = React.useCallback(() => {
    if (!dialogRef.current) {
      throw emptyRefError;
    }
    return dialogRef.current.cancel();
  }, []);
  const close = React.useCallback(() => {
    if (!dialogRef.current) {
      throw emptyRefError;
    }
    return dialogRef.current.close();
  }, []);
  const ok = React.useCallback(() => {
    if (!dialogRef.current) {
      throw emptyRefError;
    }
    return dialogRef.current.ok();
  }, []);
  React.useEffect(() => {
    if (dialogRef.current) {
      return dialogRef.current.addOpenChangeListener(setIsOpen);
    }
    return void 0;
  }, []);
  return [dialogRef, { open, cancel, close, ok, isOpen }];
};
export {
  useDialog
};
//# sourceMappingURL=dialog.hooks.js.map
