var _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; };

var _class, _temp;

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { createPortal } from 'react-dom';

var Alert = (_temp = _class = function (_Component) {
  _inherits(Alert, _Component);

  // 全局配置
  function Alert(props, context) {
    _classCallCheck(this, Alert);

    var _this = _possibleConstructorReturn(this, _Component.call(this, props, context));

    _this.componentDidMount = function () {};

    return _this;
  }

  Alert.prototype.render = function render() {
    var _this2 = this;

    // 全局配置
    var _context$locale = this.context.locale,
        locale = _context$locale === undefined ? {} : _context$locale;

    var _props = this.props,
        portal = _props.portal,
        show = _props.show,
        animation = _props.animation,
        duration = _props.duration,
        _props$maskAttribute = _props.maskAttribute,
        maskAttribute = _props$maskAttribute === undefined ? {} : _props$maskAttribute,
        caption = _props.caption,
        _props$captionAttribu = _props.captionAttribute,
        captionAttribute = _props$captionAttribu === undefined ? {} : _props$captionAttribu,
        icon = _props.icon,
        _props$contentAttribu = _props.contentAttribute,
        contentAttribute = _props$contentAttribu === undefined ? {} : _props$contentAttribu,
        _props$submitCaption = _props.submitCaption,
        submitCaption = _props$submitCaption === undefined ? locale['ok'] || '确定' : _props$submitCaption,
        _props$submitAttribut = _props.submitAttribute,
        submitAttribute = _props$submitAttribut === undefined ? {} : _props$submitAttribut,
        _props$cancelCaption = _props.cancelCaption,
        cancelCaption = _props$cancelCaption === undefined ? locale['cancel'] || '取消' : _props$cancelCaption,
        _props$cancelAttribut = _props.cancelAttribute,
        cancelAttribute = _props$cancelAttribut === undefined ? {} : _props$cancelAttribut,
        children = _props.children,
        others = _objectWithoutProperties(_props, ['portal', 'show', 'animation', 'duration', 'maskAttribute', 'caption', 'captionAttribute', 'icon', 'contentAttribute', 'submitCaption', 'submitAttribute', 'cancelCaption', 'cancelAttribute', 'children']);
    // 构建动画


    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;
      case 'none':
        animationClassName = '';
        break;
      default:
        animationClassName = 'popup-animation middle';
    }
    // 动画时长
    var durationStyle = {};
    if (typeof duration === 'number') {
      durationStyle = {
        WebkitTransitionDuration: duration + 'ms'
      };
    }
    return createPortal(React.createElement(
      'div',
      _extends({
        ref: function ref(el) {
          _this2.$el = el;
        }
      }, maskAttribute, {
        className: 'mask alert-mask' + (maskAttribute.className ? ' ' + maskAttribute.className : '') + (show ? ' active' : ''),
        style: Object.assign({}, durationStyle, maskAttribute.style || {})
      }),
      React.createElement(
        'div',
        _extends({
          'data-animation': animation
        }, others, {
          className: 'alert' + (animationClassName ? ' ' + animationClassName : '') + (others.className ? ' ' + others.className : '') + (show ? ' active' : ''),
          style: Object.assign({}, durationStyle, others.style || {})
        }),
        caption && React.createElement(
          'h1',
          captionAttribute,
          caption
        ),
        React.createElement(
          'div',
          _extends({}, contentAttribute, { className: 'alert-content' + (contentAttribute.className ? ' ' + contentAttribute.className : '') }),
          icon,
          children
        ),
        React.createElement(
          'div',
          { className: 'alert-handler' },
          cancelAttribute.onClick && React.createElement(
            'a',
            _extends({}, cancelAttribute, { className: 'alert-cancel button lg' + (cancelAttribute.className ? ' ' + cancelAttribute.className : '') }),
            cancelCaption
          ),
          submitAttribute.onClick && React.createElement(
            'a',
            _extends({}, submitAttribute, { className: 'alert-submit button lg' + (submitAttribute.className ? ' ' + submitAttribute.className : '') }),
            submitCaption
          )
        )
      )
    ), portal || this.context.portal || document.getElementById('root') || document.body);
  };

  return Alert;
}(Component), _class.contextTypes = {
  locale: PropTypes.object,
  portal: PropTypes.object
}, _class.defaultProps = {
  animation: 'zoom'
}, _temp);
export { Alert as default };
Alert.propTypes = process.env.NODE_ENV !== "production" ? {
  portal: PropTypes.object,
  show: PropTypes.bool,
  animation: PropTypes.string, // slideLeft | slideRight | slideUp | slideDown | zoom | fade
  duration: PropTypes.number,

  maskAttribute: PropTypes.object,

  caption: PropTypes.node,
  captionAttribute: PropTypes.object,

  icon: PropTypes.node,

  contentAttribute: PropTypes.object,

  submitCaption: PropTypes.node,
  submitAttribute: PropTypes.object,

  cancelCaption: PropTypes.node,
  cancelAttribute: PropTypes.object,

  children: PropTypes.node
} : {};