var _excluded = ["portal", "content", "animation", "style", "maskProps", "visible", "maskClosable", "onVisibleChange", "children"];
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 _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, { forwardRef } from 'react';
import { createPortal } from 'react-dom';
import getDataAnimation from "./api/getDataAnimation";

// 内库使用-start
import getClassNameByAnimation from "./../Modal/api/getClassNameByAnimation";
// 内库使用-end

/* 测试使用-start
import { Modal } from 'seedsui-react'
const getClassNameByAnimation = Modal.getClassNameByAnimation
测试使用-end */

var Popup = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var portal = _ref.portal,
    content = _ref.content,
    animation = _ref.animation,
    style = _ref.style,
    _ref$maskProps = _ref.maskProps,
    maskProps = _ref$maskProps === void 0 ? {} : _ref$maskProps,
    visible = _ref.visible,
    _ref$maskClosable = _ref.maskClosable,
    maskClosable = _ref$maskClosable === void 0 ? true : _ref$maskClosable,
    onVisibleChange = _ref.onVisibleChange,
    children = _ref.children,
    props = _objectWithoutProperties(_ref, _excluded);
  // 构建动画
  var position = getClassNameByAnimation(animation);
  var dataAnimation = getDataAnimation(animation);

  // 点击遮罩
  function handleMaskClick(e) {
    if (maskProps.onClick) maskProps.onClick(e);
    if (maskClosable && onVisibleChange) onVisibleChange(false);
    e.stopPropagation();
  }

  // 箭头颜色: 根据style中的backgroundColor和borderColor
  var arrowStyle = null;
  var arrowOuterStyle = null;
  var backgroundColor = style === null || style === void 0 ? void 0 : style.backgroundColor;
  var borderColor = style === null || style === void 0 ? void 0 : style.borderColor;
  // 从下往上弹
  if (position.indexOf('bottom') === 0) {
    arrowStyle = backgroundColor ? {
      borderTopColor: backgroundColor
    } : null;
    arrowOuterStyle = borderColor ? {
      borderTopColor: borderColor
    } : null;
  }
  // 从上往下弹
  else {
    arrowStyle = backgroundColor ? {
      borderBottomColor: backgroundColor
    } : null;
    arrowOuterStyle = borderColor ? {
      borderBottomColor: borderColor
    } : null;
  }
  return /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement("div", _extends({}, maskProps, {
    className: "mask tooltip-mask".concat(maskProps.className ? ' ' + maskProps.className : '').concat(visible ? ' active' : ''),
    onClick: handleMaskClick,
    ref: ref
  }), /*#__PURE__*/React.createElement("div", {
    className: "modal-animation tooltip tooltip-bottom".concat(position ? ' ' + position : '').concat(props.className ? ' ' + props.className : '').concat(visible ? ' active' : ''),
    style: style,
    "data-animation": dataAnimation
  }, /*#__PURE__*/React.createElement("div", {
    className: "tooltip-content"
  }, content), /*#__PURE__*/React.createElement("div", {
    className: "tooltip-arrow-outer",
    style: arrowOuterStyle
  }), /*#__PURE__*/React.createElement("div", {
    className: "tooltip-arrow",
    style: arrowStyle
  }))), portal || document.getElementById('root') || document.body);
});
export default Popup;