import { jsx } from 'react/jsx-runtime';
import { useRef, useCallback } from 'react';
import { useDisclosure, Stack } from '@chakra-ui/react';
import 'chakra-react-select';
import 'react-icons/fa';
import '../../styles/theme.js';
import 'react-icons/md';
import 'react-router-dom';
import BaseModal from './Modal.js';
import '@chakra-ui/icons';
import '../Button/Button.js';
import '../Form/FormProvider.js';
import 'react-hook-form';
import '@hookform/devtools';
import '@hookform/resolvers/yup';
import 'yup';
import '../Inputs/Slider/chakra/ChakraTooltip.js';
import 'react-icons/io';
import '../CodeBlock/CodeBlock.js';
import '../DataTable/DataTable.js';
import '../../styles/colors.js';
import 'date-fns/locale/en-US';
import 'date-fns-tz/zonedTimeToUtc';
import 'react-datepicker';
import 'date-fns';
import 'date-fns-tz';
import '../Inputs/DateTimeInput/Calendar.js';
import '../Popover/PopoverContent.js';
import '../Popover/Popover.js';
import '../Badge/Badge.js';
import 'react-icons/io5';
import '@textea/json-viewer';
import 'react-markdown';
import 'remark-gfm';
import 'remark-emoji';

const DEFAULT_VALUES = {
  LABEL_HEADING: "Delete",
  MODAL_SIZE: "lg"
};
const useConfirmModal = ({
  heading = DEFAULT_VALUES.LABEL_HEADING,
  size = DEFAULT_VALUES.MODAL_SIZE,
  render,
  initialFocusRef
}) => {
  const { isOpen, onOpen, onClose } = useDisclosure();
  const promiseRef = useRef({
    resolve: (value) => {
    },
    reject: (error) => {
    },
    params: {}
  });
  const renderModal = useCallback(() => {
    const cancel = (error) => {
      promiseRef.current.reject(error);
      onClose();
    };
    const confirm = (result) => {
      promiseRef.current.resolve(result);
      onClose();
    };
    return /* @__PURE__ */ jsx(
      BaseModal,
      {
        heading,
        isOpen,
        onClose: cancel,
        size,
        initialFocusRef,
        children: /* @__PURE__ */ jsx(Stack, { spacing: 4, children: render({
          // current visibility state of modal
          isOpen,
          // called by user when ready to dismiss the modal after confirmation
          // (allows for async operation to occur before dismissing the modal)
          // optionally accepts a result to relay back to caller
          confirm,
          // called to close modal; optionally accepts an error to relay
          // back to caller
          cancel,
          params: promiseRef.current.params
        }) })
      }
    );
  }, [isOpen, heading, render, initialFocusRef]);
  const showModal = useCallback((params) => {
    return new Promise((resolve, reject) => {
      promiseRef.current = {
        resolve,
        reject,
        params
      };
      onOpen();
    });
  }, []);
  return {
    // method to call that renders modal in the DOM
    renderModal,
    // called to open the modal; visibility of modal is
    // is managed by us, not by the user. Easy peezy!
    showModal
  };
};

export { useConfirmModal as default };
//# sourceMappingURL=useConfirmModal.js.map
