"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const React = require("react");
function _interopNamespaceDefault(e) {
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
  if (e) {
    for (const k in e) {
      if (k !== "default") {
        const d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: () => e[k]
        });
      }
    }
  }
  n.default = e;
  return Object.freeze(n);
}
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(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__namespace.useRef(null);
  const [isOpen, setIsOpen] = React__namespace.useState(false);
  React__namespace.useImperativeHandle(forwardRef, () => dialogRef.current);
  const open = React__namespace.useCallback(() => {
    if (!dialogRef.current) {
      throw emptyRefError;
    }
    return dialogRef.current.open();
  }, []);
  const cancel = React__namespace.useCallback(() => {
    if (!dialogRef.current) {
      throw emptyRefError;
    }
    return dialogRef.current.cancel();
  }, []);
  const close = React__namespace.useCallback(() => {
    if (!dialogRef.current) {
      throw emptyRefError;
    }
    return dialogRef.current.close();
  }, []);
  const ok = React__namespace.useCallback(() => {
    if (!dialogRef.current) {
      throw emptyRefError;
    }
    return dialogRef.current.ok();
  }, []);
  React__namespace.useEffect(() => {
    if (dialogRef.current) {
      return dialogRef.current.addOpenChangeListener(setIsOpen);
    }
    return void 0;
  }, []);
  return [dialogRef, { open, cancel, close, ok, isOpen }];
};
exports.useDialog = useDialog;
//# sourceMappingURL=dialog.hooks.cjs.map
