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

// ported to styled-componnets from
// https://github.com/KyleAMathews/react-spinkit
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { compose } from 'recompose';
import { withTheme } from 'grommet/es6/components/hocs';

import { allSpinners } from './spinners';
import { CircleSpinner, ThreeBounceSpinner, CubeGridSpinner, WaveSpinner, FoldingCubeSpinner, DoubleBounceSpinner, WanderingCubesSpinner, ChasingDotsSpinner, RotatingPlaneSpinner, PulseSpinner, WordPressSpinner } from './StyledSpinning';

var styledComponents = {
  'circle': CircleSpinner,
  'three-bounce': ThreeBounceSpinner,
  'cube-grid': CubeGridSpinner,
  'wave': WaveSpinner,
  'folding-cube': FoldingCubeSpinner,
  'double-bounce': DoubleBounceSpinner,
  'wandering-cubes': WanderingCubesSpinner,
  'chasing-dots': ChasingDotsSpinner,
  'rotating-plane': RotatingPlaneSpinner,
  'pulse': PulseSpinner,
  'wordpress': WordPressSpinner

};

var Spinning = function (_Component) {
  _inherits(Spinning, _Component);

  function Spinning() {
    _classCallCheck(this, Spinning);

    return _possibleConstructorReturn(this, _Component.apply(this, arguments));
  }

  Spinning.prototype.render = function render() {
    var _props = this.props,
        kind = _props.kind,
        fadeIn = _props.fadeIn,
        color = _props.color,
        theme = _props.theme,
        size = _props.size;

    var spinnerInfo = allSpinners[kind] || allSpinners['three-bounce'];
    var spinningColor = color;
    if (color === undefined) {
      spinningColor = theme.dark ? 'light-1' : 'dark-1';
    }
    var StyledSpinning = styledComponents[kind];
    return React.createElement(
      StyledSpinning,
      { color: spinningColor, fadeIn: fadeIn, theme: theme, size: size },
      Array.from(Array(spinnerInfo.divCount).keys()).map(function (_, idx) {
        return React.createElement('div', { key: idx });
      })
    );
  };

  return Spinning;
}(Component);

Spinning.defaultProps = {
  kind: 'circle',
  fadeIn: 'full',
  color: undefined,
  size: 'medium'
};
Spinning.propTypes = {
  fadeIn: PropTypes.oneOf(['full', 'half', 'quarter', 'none', 'wordpress']),
  color: PropTypes.string
};


var SpinningDoc = void 0;
if (process.env.NODE_ENV !== 'production') {
  SpinningDoc = require('./doc').default(Spinning); // eslint-disable-line global-require
}

var SpinningWrapper = compose(withTheme)(SpinningDoc || Spinning);

export { SpinningWrapper as Spinning };