import { _ as _asyncToGenerator, r as regenerator } from '../../index-qSfOyGhk.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-CgC7Bq6K.js';
import 'react-dom';
import '../confirm-modal.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';
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);
    });
  });
});
