'use strict';

Object.defineProperty(exports, "__esModule", {
  value: 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 _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 _getClassName2 = require('babel-plugin-react-css-modules/dist/browser/getClassName');

var _getClassName3 = _interopRequireDefault(_getClassName2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _Icon = require('../../Icon');

var _Icon2 = _interopRequireDefault(_Icon);

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var _styleModuleImportMap = {
  './step.scss': {
    'step--primary': 'flive_step_step--primary',
    'step--primary--with-right-arrow': 'flive_step_step--primary--with-right-arrow',
    'step--primary--last-enabled': 'flive_step_step--primary--last-enabled',
    'title--primary': 'flive_step_title--primary',
    'size-sm': 'flive_step_size-sm',
    'size-md': 'flive_step_size-md',
    'size-lg': 'flive_step_size-lg',
    'step--primary--enabled': 'flive_step_step--primary--enabled',
    'step--primary--selected': 'flive_step_step--primary--selected',
    'step-forbidden': 'flive_step_step-forbidden',
    'decorator--primary': 'flive_step_decorator--primary',
    'decorator--enabled': 'flive_step_decorator--enabled',
    'decorator--selected': 'flive_step_decorator--selected',
    'title--primary--enabled': 'flive_step_title--primary--enabled',
    'title--primary--selected': 'flive_step_title--primary--selected',
    'arrow': 'flive_step_arrow',
    'arrow--selected': 'flive_step_arrow--selected',
    'with-border': 'flive_step_with-border'
  }
};

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; } // eslint-disable-line no-unused-vars


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

  function Step() {
    var _ref;

    var _temp, _this, _ret;

    _classCallCheck(this, Step);

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

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Step.__proto__ || Object.getPrototypeOf(Step)).call.apply(_ref, [this].concat(args))), _this), _this.onClick = function (event) {
      var _this$props = _this.props,
          index = _this$props.index,
          value = _this$props.value,
          onClick = _this$props.onClick,
          enabled = _this$props.enabled,
          forbidden = _this$props.forbidden;

      if (enabled && !forbidden) {
        if (onClick) {
          onClick({ event: event, index: index, value: value });
        }
      } else {
        event.stopPropagation();
        event.preventDefault();
      }
    }, _temp), _possibleConstructorReturn(_this, _ret);
  }

  _createClass(Step, [{
    key: 'render',
    value: function render() {
      var _classNames, _classNames2;

      var _props = this.props,
          index = _props.index,
          enabled = _props.enabled,
          lastEnabled = _props.lastEnabled,
          selected = _props.selected,
          component = _props.component,
          forbidden = _props.forbidden,
          children = _props.children,
          variant = _props.variant,
          size = _props.size,
          icon = _props.icon,
          withBorder = _props.withBorder,
          withRightArrow = _props.withRightArrow,
          className = _props.className,
          rest = _objectWithoutProperties(_props, ['index', 'enabled', 'lastEnabled', 'selected', 'component', 'forbidden', 'children', 'variant', 'size', 'icon', 'withBorder', 'withRightArrow', 'className']);

      var MyComponent = component;
      delete rest.onClick;

      return _react2.default.createElement(
        MyComponent,
        _extends({
          onClick: this.onClick
        }, rest, {
          className: (className ? className + ' ' : '') + (0, _getClassName3.default)((0, _classnames2.default)('step--' + variant, 'size-' + size, (_classNames = {}, _defineProperty(_classNames, 'step--' + variant + '--selected', selected), _defineProperty(_classNames, 'step--' + variant + '--enabled', enabled), _defineProperty(_classNames, 'step--' + variant + '--last-enabled', lastEnabled), _defineProperty(_classNames, 'step--' + variant + '--with-right-arrow', withRightArrow), _defineProperty(_classNames, 'with-border', withBorder), _defineProperty(_classNames, 'step-forbidden', forbidden), _classNames)), _styleModuleImportMap)
        }),
        _react2.default.createElement(
          'span',
          {
            className: (0, _getClassName3.default)((0, _classnames2.default)('decorator--' + variant, {
              'decorator--selected': selected,
              'decorator--enabled': enabled
            }), _styleModuleImportMap)
          },
          icon ? _react2.default.createElement(_Icon2.default, { size: size, name: icon }) : index + 1
        ),
        _react2.default.createElement(
          'span',
          {
            className: (0, _getClassName3.default)((0, _classnames2.default)('title--' + variant, (_classNames2 = {}, _defineProperty(_classNames2, 'title--' + variant + '--enabled', enabled), _defineProperty(_classNames2, 'title--' + variant + '--selected', selected), _classNames2)), _styleModuleImportMap)
          },
          children
        ),
        withBorder && _react2.default.createElement('span', {
          className: (0, _getClassName3.default)((0, _classnames2.default)('arrow', {
            'arrow--selected': selected
          }), _styleModuleImportMap)
        })
      );
    }
  }]);

  return Step;
}(_react.PureComponent);

Step.componentName = 'Step';
Step.propTypes = {
  children: _propTypes2.default.node,
  component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object, _propTypes2.default.func]),
  title: _propTypes2.default.string,
  index: _propTypes2.default.number,
  enabled: _propTypes2.default.bool,
  lastEnabled: _propTypes2.default.bool,
  onClick: _propTypes2.default.func,
  value: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object]),
  selected: _propTypes2.default.bool,
  variant: _propTypes2.default.oneOf(['primary']),
  withBorder: _propTypes2.default.bool,
  size: _propTypes2.default.oneOf(['sm', 'md', 'lg']),
  icon: _propTypes2.default.string,
  withRightArrow: _propTypes2.default.bool,
  forbidden: _propTypes2.default.bool,
  className: _propTypes2.default.string
};
Step.defaultProps = {
  children: null,
  title: '',
  index: 1,
  component: 'button',
  value: null,
  enabled: false,
  lastEnabled: false,
  selected: false,
  onClick: null,
  withBorder: false,
  variant: 'primary',
  size: 'md',
  icon: null,
  withRightArrow: false,
  forbidden: false,
  className: undefined
};
exports.default = Step;
module.exports = exports['default'];