"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.prompt = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var React = _interopRequireWildcard(require("react"));

var _dom = require("../utils/dom");

var _Picker = _interopRequireDefault(require("./Picker"));

var prompt = function prompt(props) {
  return new Promise(function (resolve) {
    var _renderImperatively = (0, _dom.renderImperatively)( /*#__PURE__*/React.createElement(_Picker.default, (0, _extends2.default)({}, props, {
      onConfirm: function onConfirm(value, items) {
        var _props$onConfirm;

        (_props$onConfirm = props.onConfirm) === null || _props$onConfirm === void 0 ? void 0 : _props$onConfirm.call(props, value, items);
        close();
        resolve({
          value: value,
          items: items
        });
      },
      onCancel: function onCancel() {
        var _props$onCancel;

        (_props$onCancel = props.onCancel) === null || _props$onCancel === void 0 ? void 0 : _props$onCancel.call(props);
        close();
        resolve({
          value: null,
          items: []
        });
      }
    }))),
        close = _renderImperatively.close;
  });
};

exports.prompt = prompt;