'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _Steps = require('./Steps');

var _Steps2 = _interopRequireDefault(_Steps);

var _Step = require('./Step');

var _Step2 = _interopRequireDefault(_Step);

var _StepperContent = require('./StepperContent');

var _StepperContent2 = _interopRequireDefault(_StepperContent);

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

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

var Stepper = function (_PureComponent) {
  _inherits(Stepper, _PureComponent);

  function Stepper() {
    var _ref;

    var _temp, _this, _ret;

    _classCallCheck(this, Stepper);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Stepper.__proto__ || Object.getPrototypeOf(Stepper)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
      value: null,
      reCalculateSelection: true
    }, _this.onStepsChange = function (value) {
      _this.setState({
        value: value,
        reCalculateSelection: false
      });
    }, _temp), _possibleConstructorReturn(_this, _ret);
  }

  _createClass(Stepper, [{
    key: 'componentWillReceiveProps',
    value: function componentWillReceiveProps() {
      this.setState({
        reCalculateSelection: true
      });
    }
  }, {
    key: 'buildChildren',
    value: function buildChildren() {
      var _this2 = this;

      var _props = this.props,
          children = _props.children,
          variant = _props.variant,
          withBorder = _props.withBorder,
          withRightArrow = _props.withRightArrow,
          size = _props.size;
      var _state = this.state,
          value = _state.value,
          reCalculateSelection = _state.reCalculateSelection;

      return _react.Children.map(children, function (child) {
        if (!(0, _react.isValidElement)(child)) {
          return child;
        }
        var componentName = child.type.componentName;

        switch (componentName) {
          case 'Steps':
            return _react2.default.createElement(
              'div',
              { className: 'flive_stepper_steps-wrapper' },
              _react2.default.cloneElement(child, {
                onChange: _this2.onStepsChange,
                reCalculateSelection: reCalculateSelection,
                variant: variant,
                withBorder: withBorder,
                withRightArrow: withRightArrow,
                size: size
              })
            );
          case 'StepperContent':
            return _react2.default.cloneElement(child, {
              value: value,
              variant: variant,
              withBorder: withBorder,
              size: size
            });
          default:
            return child;
        }
      });
    }
  }, {
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        { className: this.props.className },
        this.buildChildren()
      );
    }
  }]);

  return Stepper;
}(_react.PureComponent);

Stepper.propTypes = {
  /** @ignore */
  className: _propTypes2.default.string,
  /** @ignore */
  children: _propTypes2.default.node,
  variant: _propTypes2.default.string,
  withBorder: _propTypes2.default.bool,
  withRightArrow: _propTypes2.default.bool,
  size: _propTypes2.default.oneOf(['sm', 'md', 'lg'])
};
Stepper.defaultProps = {
  className: undefined,
  children: null,
  variant: 'primary',
  withBorder: false,
  withRightArrow: false,
  size: 'md'
};


Stepper.Steps = _Steps2.default;
Stepper.Step = _Step2.default;
Stepper.StepperContent = _StepperContent2.default;

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