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

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

import React, { forwardRef, useContext } from 'react';
import { createPortal } from 'react-dom';
import locale from './../locale'; // 国际化数据

var Loading = forwardRef(function (_ref, ref) {
  var portal = _ref.portal,
      _ref$type = _ref.type,
      type = _ref$type === undefined ? 'floating' : _ref$type,
      _ref$maskAttribute = _ref.maskAttribute,
      maskAttribute = _ref$maskAttribute === undefined ? {} : _ref$maskAttribute,
      iconAttribute = _ref.iconAttribute,
      _ref$captionAttribute = _ref.captionAttribute,
      captionAttribute = _ref$captionAttribute === undefined ? {} : _ref$captionAttribute,
      children = _ref.children,
      _ref$caption = _ref.caption,
      caption = _ref$caption === undefined ? locale('加载中...', 'loading') : _ref$caption,
      others = _objectWithoutProperties(_ref, ['portal', 'type', 'maskAttribute', 'iconAttribute', 'captionAttribute', 'children', 'caption']);

  var content = null;
  if (type === 'custom') {
    // 自定义样式
    content = React.createElement(
      'div',
      _extends({}, others, { className: 'loading-custom' + (others.className ? ' ' + others.className : '') }),
      iconAttribute && React.createElement('span', _extends({}, iconAttribute, { className: 'loading-custom-icon' + (iconAttribute.className ? ' ' + iconAttribute.className : '') })),
      caption && React.createElement(
        'p',
        _extends({}, captionAttribute, { className: 'loading-custom-caption' + (captionAttribute.className ? ' ' + captionAttribute.className : '') }),
        caption
      )
    );
  } else if (type === 'filling') {
    // 填料环
    content = React.createElement(
      'div',
      _extends({}, others, { className: 'loading-filling active' + (others.className ? ' ' + others.className : '') }),
      React.createElement('div', { className: 'loading-filling-icon' })
    );
  } else if (type === 'floating') {
    // 流光
    content = React.createElement(
      'div',
      _extends({}, others, { className: 'loading-floating animated' + (others.className ? ' ' + others.className : '') }),
      React.createElement(
        'div',
        { className: 'loading-floating-icon' },
        React.createElement('div', { className: 'loading-floating-blade' }),
        React.createElement('div', { className: 'loading-floating-blade' }),
        React.createElement('div', { className: 'loading-floating-blade' }),
        React.createElement('div', { className: 'loading-floating-blade' }),
        React.createElement('div', { className: 'loading-floating-blade' }),
        React.createElement('div', { className: 'loading-floating-blade' }),
        React.createElement('div', { className: 'loading-floating-blade' }),
        React.createElement('div', { className: 'loading-floating-blade' }),
        React.createElement('div', { className: 'loading-floating-blade' }),
        React.createElement('div', { className: 'loading-floating-blade' }),
        React.createElement('div', { className: 'loading-floating-blade' }),
        React.createElement('div', { className: 'loading-floating-blade' })
      ),
      caption && React.createElement(
        'div',
        _extends({}, captionAttribute, { className: 'loading-floating-caption' + (captionAttribute.className ? ' ' + captionAttribute.className : '') }),
        caption
      )
    );
  }
  if (portal) {
    return createPortal(React.createElement(
      'div',
      _extends({ ref: ref }, maskAttribute, { className: 'loading-mask mask active' + (maskAttribute.className ? ' ' + maskAttribute.className : '') }),
      content,
      children
    ), portal);
  }
  return React.createElement(
    'div',
    _extends({ ref: ref }, maskAttribute, { className: 'loading-mask mask active' + (maskAttribute.className ? ' ' + maskAttribute.className : '') }),
    content,
    children
  );
});

export default Loading;