"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
const kit_Modal = require("./Modal.cjs");
const DEFAULT_CONFIRM_TITLE = "Confirm Action";
const DEFAULT_CONFIRM_LABEL = "Confirm";
const DEFAULT_CONTENT = "Are you sure?";
const ConfirmModal = ({
  cancelText,
  content,
  danger = false,
  size = "small",
  title,
  okText,
  onClose,
  onConfirm,
  onError
}) => {
  return /* @__PURE__ */ jsxRuntime.jsx(
    kit_Modal.Modal,
    {
      cancel: true,
      cancelText,
      danger,
      icon: "warning",
      size,
      submit: {
        handleError: onError,
        handler: onConfirm,
        text: okText ?? DEFAULT_CONFIRM_LABEL
      },
      title: title ?? DEFAULT_CONFIRM_TITLE,
      onClose,
      children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: content })
    }
  );
};
const voidFn = () => {
};
const voidPromiseFn = async () => {
};
const ConfirmationContext = React.createContext(null);
const ConfirmationProvider = ({ children }) => {
  const [modalProps, setModalProps] = React.useState();
  const Modal2 = kit_Modal.useModal(ConfirmModal);
  const contextValue = ({
    cancelText,
    content = DEFAULT_CONTENT,
    danger = false,
    okText,
    size = "small",
    title,
    onClose = voidFn,
    onConfirm = voidPromiseFn,
    onError = voidFn
  }) => {
    setModalProps({
      cancelText,
      content,
      danger,
      okText,
      onClose,
      onConfirm,
      onError,
      size,
      title
    });
    Modal2.open();
  };
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
    React.useMemo(
      () => /* @__PURE__ */ jsxRuntime.jsx(ConfirmationContext.Provider, { value: contextValue, children }),
      /* eslint-disable-next-line react-hooks/exhaustive-deps */
      [children]
    ),
    /* @__PURE__ */ jsxRuntime.jsx(
      Modal2.Component,
      {
        ...modalProps,
        onConfirm: (modalProps == null ? void 0 : modalProps.onConfirm) ?? voidPromiseFn,
        onError: (modalProps == null ? void 0 : modalProps.onError) ?? voidFn
      }
    )
  ] });
};
const useConfirm = () => {
  const context = React.useContext(ConfirmationContext);
  if (context === null) {
    throw new Error("Attempted to use confirmation modal outside of ConfirmationContext");
  }
  return context;
};
exports.ConfirmationProvider = ConfirmationProvider;
exports.DEFAULT_CONFIRM_LABEL = DEFAULT_CONFIRM_LABEL;
exports.DEFAULT_CONFIRM_TITLE = DEFAULT_CONFIRM_TITLE;
exports.DEFAULT_CONTENT = DEFAULT_CONTENT;
exports.default = useConfirm;
exports.voidFn = voidFn;
exports.voidPromiseFn = voidPromiseFn;
