'use strict';

exports.__esModule = true;

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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactDom = require('react-dom');

var _instance = require('../Context/instance.js');

var _instance2 = _interopRequireDefault(_instance);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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

var Loading = (0, _react.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,
      caption = _ref.caption,
      others = _objectWithoutProperties(_ref, ['portal', 'type', 'maskAttribute', 'iconAttribute', 'captionAttribute', 'children', 'caption']);

  // context
  var context = (0, _react.useContext)(_instance2.default) || {};
  var locale = context.locale || {};

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

exports.default = Loading;
module.exports = exports['default'];