import { _ as _asyncToGenerator, r as regenerator } from '../index-qSfOyGhk.js';
import React__default from 'react';
import ReactDOM__default from 'react-dom';
import ConfirmModal from './confirm-modal.js';
import Action from './action.js';
import '../typeof-CgC7Bq6K.js';
import '../extends-C4cduGrv.js';
import '../objectWithoutProperties-TXwlfNxG.js';
import 'prop-types';
import 'classnames';
import '../button/index.js';
import '../defineProperty-CEd-kZQW.js';
import '@reach/visually-hidden';
import '../ck-icon/index.js';
import '../ck-icon/assets/icon-map/index.js';
import '../icon/index.js';
import '@fortawesome/react-fontawesome';
import '../icon/icons.js';
import '../icon/library.js';
import '@fortawesome/fontawesome-svg-core';
import '@fortawesome/pro-solid-svg-icons';
import '@fortawesome/pro-light-svg-icons';
import '@fortawesome/free-brands-svg-icons';
import '../slicedToArray-BB-AwwkK.js';
import '../floating-ui.react-cWPyyUrN.js';
import '../toConsumableArray-dKQYsfpV.js';
import '../button/button-group.js';
import '../portal/index.js';
import '../use-rerender-once/index.js';
import '../use-force-update/index.js';
import '../dialog.esm-C1hoFD2p.js';
import '../portal.esm-CuKGPwhL.js';
import '../utils.esm-CKyxlHOy.js';
import '../warning-s9zGJbnw.js';
import '../setPrototypeOf-Bchah3-D.js';
import '../auto-id.esm-Cly76abB.js';
import 'framer-motion';

/**
 * == Example
 *
 * const result = await confirm("Are you sure?", { confirm: "Yes", cancel: "No"})
 *
 * @param {string} label message to display in the body of the modal.
 * @param options
 * @param {string} options.message longer message for the body of the modal
 * @param {string} options.confirm text in the confirm button
 * @param {string} options.cancel text in the cancel button
 * @param {boolean} options.dismissable close when background is clicked
 */

function confirm(_x) {
  return _confirm.apply(this, arguments);
}

function _confirm() {
  _confirm = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(label) {
    var _ref,
        _ref$confirm,
        confirm,
        _ref$cancel,
        cancel,
        message,
        _ref$dismissable,
        dismissable,
        _args = arguments;

    return regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _ref = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, _ref$confirm = _ref.confirm, confirm = _ref$confirm === void 0 ? "Yes" : _ref$confirm, _ref$cancel = _ref.cancel, cancel = _ref$cancel === void 0 ? "No" : _ref$cancel, message = _ref.message, _ref$dismissable = _ref.dismissable, dismissable = _ref$dismissable === void 0 ? true : _ref$dismissable;
            return _context.abrupt("return", new Promise(function (resolve) {
              var container = document.createElement("div");

              var close = function close(result) {
                ReactDOM__default.unmountComponentAtNode(container);
                container.remove();
                resolve(result);
              };

              var handleCancel = function handleCancel() {
                close(false);
              };

              var handleConfirm = function handleConfirm() {
                close(true);
              };

              var dialog = /*#__PURE__*/React__default.createElement(ConfirmModal, {
                onClose: handleCancel,
                label: label,
                dismissable: dismissable
              }, message, /*#__PURE__*/React__default.createElement(Action, {
                is: "primary",
                onClick: handleConfirm
              }, confirm), /*#__PURE__*/React__default.createElement(Action, {
                is: "secondary",
                onClick: handleCancel
              }, cancel));
              ReactDOM__default.render(dialog, container);
              document.body.appendChild(container);
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _confirm.apply(this, arguments);
}

export { confirm as default };
