import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React, { Component } from 'react';
import PropTypes from 'prop-types';

var FileDialog =
/*#__PURE__*/
function (_Component) {
  _inherits(FileDialog, _Component);

  function FileDialog() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, FileDialog);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(FileDialog)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", {
      dialogInstance: null
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "open", function (reactClass, props) {
      return new Promise(function (resolve, reject) {
        props = Object.assign({}, _this.props, props, {
          resolve: resolve,
          reject: reject,
          onRequestClose: function onRequestClose() {
            resolve();

            _this.setState({
              dialogInstance: null
            });
          }
        });
        var dialogInstance = React.createElement(reactClass, props);

        _this.setState({
          dialogInstance: dialogInstance
        });
      });
    });

    return _this;
  }

  _createClass(FileDialog, [{
    key: "render",
    value: function render() {
      return this.state.dialogInstance;
    }
  }]);

  return FileDialog;
}(Component);

_defineProperty(FileDialog, "propTypes", {
  localization: PropTypes.object.isRequired
});

export { FileDialog as default };