import "antd/es/modal/style";
import _Modal from "antd/es/modal";
var _excluded = ["prefixCls"];

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

import React, { useState, forwardRef, useImperativeHandle } from 'react';
import classNames from 'classnames';
import { isFunction } from 'lodash-es';
var InlineModal = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var customizePrefixCls = _ref.prefixCls,
      props = _objectWithoutProperties(_ref, _excluded);

  var prefixCls = "".concat(customizePrefixCls, "-modal");
  var Component = props.children || props.content;

  var _useState = useState(props.visible),
      _useState2 = _slicedToArray(_useState, 2),
      visible = _useState2[0],
      setVisible = _useState2[1];

  var _onClose = function onClose() {
    setVisible(false);
  };

  useImperativeHandle(ref, function () {
    return {
      close: _onClose
    };
  });
  return /*#__PURE__*/React.createElement(_Modal, Object.assign({
    destroyOnClose: true
  }, props, {
    footer: null,
    visible: visible,
    className: classNames(prefixCls, props.className),
    onCancel: _onClose,
    afterClose: props.afterClose
  }), React.Children.map(Component, function (child) {
    if (isFunction(child.type)) {
      return /*#__PURE__*/React.cloneElement(child, {
        onClose: function onClose() {
          var _child$props, _child$props$onClose;

          _onClose();

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

          child === null || child === void 0 ? void 0 : (_child$props = child.props) === null || _child$props === void 0 ? void 0 : (_child$props$onClose = _child$props.onClose) === null || _child$props$onClose === void 0 ? void 0 : _child$props$onClose.call.apply(_child$props$onClose, [_child$props].concat(arg));
        }
      });
    }

    return child;
  }));
});
InlineModal.defaultProps = {
  prefixCls: 'pxx'
};
export default InlineModal;