"use strict";

require("core-js/modules/es.array.iterator.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _raven = _interopRequireDefault(require("@wii/raven"));
var _classnames = _interopRequireDefault(require("classnames"));
var _modal = _interopRequireDefault(require("../modal"));
var _wauConfigProvider = require("../wau-config-provider");
require("./style");
var _confirm = _interopRequireWildcard(require("./confirm"));
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (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; }
/* stylelint-disable custom-property-no-missing-var-function */

const raven = new _raven.default();
const OriginModal = ({
  visible,
  open = visible,
  className,
  style,
  ...restProps
}) => {
  const {
    getPrefixCls
  } = (0, _react.useContext)(_wauConfigProvider.ConfigContext);
  const prefixCls = getPrefixCls();

  // 来自于父应用
  const layout = (0, _react.useMemo)(() => {
    if (raven.isChild) {
      return raven.layout;
    }
  }, []);
  (0, _react.useEffect)(() => {
    WauModal.raven.send(WauModal.RAVEN_MESSAGE_NAME, {
      visible: open
    });
  }, [open]);
  (0, _react.useEffect)(() => {
    return () => {
      WauModal.raven.send(WauModal.RAVEN_MESSAGE_NAME, {
        visible: false
      });
    };
  }, []);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_modal.default, {
    open: open,
    centered: true,
    className: (0, _classnames.default)([{
      [`${prefixCls}-modal`]: WauModal.raven.isChild
    }, className]),
    style: {
      top: layout ? -(layout.top || 0) / 2 : undefined,
      left: layout ? -(layout.left || 0) / 2 : undefined,
      ...style
    },
    ...restProps
  });
};
const WauModal = OriginModal;
WauModal.raven = raven;
WauModal.RAVEN_MESSAGE_NAME = 'modal';
WauModal.useModal = _modal.default.useModal;
const staticFunctions = ['info', 'success', 'error', 'warn', 'warning', 'confirm'];
const staticFunctionsMap = {
  info: _confirm.withInfo,
  success: _confirm.withSuccess,
  error: _confirm.withError,
  warn: _confirm.withWarn,
  warning: _confirm.withWarn,
  confirm: _confirm.withConfirm
};
staticFunctions.forEach(func => {
  WauModal[func] = props => {
    const withFunction = staticFunctionsMap[func];
    return (0, _confirm.default)(withFunction(props));
  };
});
WauModal.config = _confirm.modalGlobalConfig;
WauModal.destroyAll = _modal.default.destroyAll;
var _default = WauModal;
exports.default = _default;