"use strict";

exports.__esModule = true;
exports.default = _default;
var _tslib = require("tslib");
var _react = _interopRequireWildcard(require("react"));
var _render = require("../utils/render");
var _utils = require("../utils");
var _actionSheet = _interopRequireDefault(require("./action-sheet"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
var ActionSheetWrapper = /*#__PURE__*/function (_Component) {
  _inheritsLoose(ActionSheetWrapper, _Component);
  function ActionSheetWrapper(props) {
    var _this = _Component.call(this, props) || this;
    _this.handleClick = function (option, index, e) {
      if (_this.props.onClick) {
        _this.props.onClick(option, index, e);
      }
    };
    _this.handleClose = function (reason) {
      _this.setState({
        visible: false
      });
      if (_this.props.onClose) {
        _this.props.onClose(reason);
      }
    };
    _this.state = {
      visible: true
    };
    return _this;
  }
  var _proto = ActionSheetWrapper.prototype;
  _proto.render = function render() {
    var _a = this.props,
      message = _a.message,
      options = _a.options,
      others = (0, _tslib.__rest)(_a, ["message", "options"]);
    var visible = this.state.visible;
    return /*#__PURE__*/(0, _react.createElement)(_actionSheet.default, _extends({
      visible: visible
    }, others, {
      disablePortal: true,
      message: message,
      options: options,
      onClose: this.handleClose,
      onClick: this.handleClick
    }));
  };
  return ActionSheetWrapper;
}(_react.Component);
ActionSheetWrapper.defaultProps = {
  message: '',
  options: [],
  onClick: function onClick() {},
  onClose: function onClose() {}
};
function _default(options) {
  var onClose = options.onClose,
    others = (0, _tslib.__rest)(options, ["onClose"]);
  var hide = null;
  hide = (0, _render.renderToRoot)( /*#__PURE__*/(0, _react.createElement)(ActionSheetWrapper, _extends({}, others, {
    onClose: function handleClose(v) {
      if ((0, _utils.isFunction)(onClose)) {
        onClose(v);
      }
      setTimeout(function () {
        hide();
      }, 300);
    }
  })));
  return {
    close: function close() {
      return hide();
    }
  };
}