var _excluded = ["portal", "show", "onClick", "animation", "duration", "maskAttribute", "children"];

function _extends() { _extends = Object.assign || 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 _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, useContext } from 'react';
import { createPortal } from 'react-dom';
import Context from './../Context/instance.js';
var Dialog = forwardRef(function (_ref, ref) {
  var portal = _ref.portal,
      show = _ref.show,
      onClick = _ref.onClick,
      _ref$animation = _ref.animation,
      animation = _ref$animation === void 0 ? 'fade' : _ref$animation,
      duration = _ref.duration,
      _ref$maskAttribute = _ref.maskAttribute,
      maskAttribute = _ref$maskAttribute === void 0 ? {} : _ref$maskAttribute,
      children = _ref.children,
      others = _objectWithoutPropertiesLoose(_ref, _excluded);

  // context
  var context = useContext(Context) || {}; // const locale = context.locale || function (remark) {return remark || ''};
  // 点击dialog主体

  function click(e) {
    e.stopPropagation();
  } // 构建动画


  var animationClassName = '';

  switch (animation) {
    case 'slideLeft':
      animationClassName = 'popup-animation right-middle';
      break;

    case 'slideRight':
      animationClassName = 'popup-animation left-middle';
      break;

    case 'slideUp':
      animationClassName = 'popup-animation bottom-center';
      break;

    case 'slideDown':
      animationClassName = 'popup-animation top-center';
      break;

    case 'zoom':
      animationClassName = 'popup-animation middle';
      break;

    case 'fade':
      animationClassName = 'popup-animation middle';
      break;

    default:
      animationClassName = 'popup-animation middle';
  } // 动画时长


  var durationStyle = {};

  if (typeof duration === 'number') {
    durationStyle = {
      WebkitTransitionDuration: duration + 'ms'
    };
  }

  return createPortal( /*#__PURE__*/React.createElement("div", _extends({
    ref: ref
  }, maskAttribute, {
    className: "mask dialog-mask" + (maskAttribute.className ? ' ' + maskAttribute.className : '') + (show ? ' active' : ''),
    style: Object.assign({}, durationStyle, maskAttribute.style || {})
  }), /*#__PURE__*/React.createElement("div", _extends({}, others, {
    className: "dialog" + (animationClassName ? ' ' + animationClassName : '') + (others.className ? ' ' + others.className : '') + (show ? ' active' : ''),
    style: Object.assign({}, durationStyle, others.style || {}),
    onClick: onClick ? onClick : click,
    "data-animation": animation
  }), children && children)), portal || context.portal || document.getElementById('root') || document.body);
});
export default Dialog;