import { _ as _asyncToGenerator, r as regenerator } from '../../index-81a9bdac.js';
import React__default from 'react';
import { cleanup, render, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import confirm from '../confirm.js';
import '../../typeof-6c6d8d7a.js';
import 'react-dom';
import '../confirm-modal.js';
import '../../extends-e61fd370.js';
import '../../objectWithoutProperties-72d23964.js';
import 'prop-types';
import 'classnames';
import '../../index-4e01772f.js';
import '../../defineProperty-18999f8e.js';
import '../../slicedToArray-5b664d46.js';
import '../../toConsumableArray-f2f53597.js';
import '../../icon/assets/icon-map/index.js';
import '../../social-icon/index.js';
import '@fortawesome/react-fontawesome';
import '../../social-icon/icons.js';
import '../../social-icon/library.js';
import '@fortawesome/fontawesome-svg-core';
import '@fortawesome/free-solid-svg-icons';
import '@fortawesome/free-brands-svg-icons';
import '../../tooltip/index.js';
import '../../auto-id.esm-2b54f757.js';
import '../../utils.esm-514fad91.js';
import '../../warning-ed2bf294.js';
import '../../portal.esm-613949dc.js';
import '@reach/visually-hidden';
import '../../portal/index.js';
import '../../use-rerender-once/index.js';
import '../../use-force-update/index.js';
import '../../button/button-group.js';
import '../../dialog.esm-cde5d438.js';
import '../../setPrototypeOf-38804714.js';
import 'framer-motion';
import '../action.js';

function TestConfirm(_ref) {
  var message = _ref.message,
      callback = _ref.callback;

  var handleClick = /*#__PURE__*/function () {
    var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
      var result;
      return regenerator.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.next = 2;
              return confirm(message, {
                confirm: "Yep",
                cancel: "Nope"
              });

            case 2:
              result = _context.sent;
              callback(result);

            case 4:
            case "end":
              return _context.stop();
          }
        }
      }, _callee);
    }));

    return function handleClick() {
      return _ref2.apply(this, arguments);
    };
  }();

  return /*#__PURE__*/React__default.createElement("button", {
    onClick: handleClick
  }, "Delete");
}

afterEach(cleanup);
describe("confirm", function () {
  it("should return true when confirmed", function () {
    return new Promise(function (done) {
      var callback = function callback(result) {
        expect(result).toBe(true);
        done();
      };

      var _render = render( /*#__PURE__*/React__default.createElement(TestConfirm, {
        message: "Are you sure?",
        confirm: "Yep",
        cancel: "nope",
        callback: callback
      })),
          getByText = _render.getByText;

      var deleteButton = getByText("Delete");
      fireEvent.click(deleteButton);
      var confirmButton = getByText("Yep");
      fireEvent.click(confirmButton);
    });
  });
  it("should return false when cancelled", function () {
    return new Promise(function (done) {
      var callback = function callback(result) {
        expect(result).toBe(false);
        done();
      };

      var _render2 = render( /*#__PURE__*/React__default.createElement(TestConfirm, {
        message: "Are you sure?",
        confirm: "Yep",
        cancel: "nope",
        callback: callback
      })),
          getByText = _render2.getByText;

      var deleteButton = getByText("Delete");
      fireEvent.click(deleteButton);
      var cancelButton = getByText("Nope");
      fireEvent.click(cancelButton);
    });
  });
});
