"use strict";

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

var _react = _interopRequireDefault(require("react"));

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

var _classnames = _interopRequireDefault(require("classnames"));

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

function _extends() { _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; }; return _extends.apply(this, arguments); }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

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 mapStepsToInternalProps = function mapStepsToInternalProps(steps, activeStep, props) {
  var activeStepReached = false;
  return steps.map(function (externalStep) {
    var status;

    if (activeStepReached) {
      status = 'notStarted';
    } else if (externalStep.key === activeStep) {
      status = 'active';
      activeStepReached = true;
    } else {
      status = externalStep.status(props);
    }

    var step = _objectSpread(_objectSpread({
      headerLevel: 'h2'
    }, externalStep), {}, {
      props: props,
      status: status
    });

    return step;
  });
};

function StepList(_ref) {
  var steps = _ref.steps,
      props = _ref.props,
      activeStep = _ref.activeStep,
      _ref$type = _ref.type,
      type = _ref$type === void 0 ? 'normal' : _ref$type,
      _ref$headerLevel = _ref.headerLevel,
      headerLevel = _ref$headerLevel === void 0 ? 'h2' : _ref$headerLevel;
  var internalSteps = mapStepsToInternalProps(steps, activeStep, props);
  return /*#__PURE__*/_react.default.createElement("ol", {
    className: (0, _classnames.default)('oec-step-list', {
      embedded: type === 'embedded'
    })
  }, internalSteps.map(function (step) {
    return /*#__PURE__*/_react.default.createElement(_Step.Step, _extends({}, step, {
      type: type,
      headerLevel: headerLevel
    }));
  }));
}