"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.WizardNavbar = void 0;

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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

var _propTypes = _interopRequireDefault(require("prop-types"));

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

var _TabPanel = require("./TabPanel");

var _TabItem = require("./TabItem");

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

var _Block = require("./Block");

var WizardNavbar =
/*#__PURE__*/
function (_React$Component) {
  (0, _inheritsLoose2.default)(WizardNavbar, _React$Component);

  function WizardNavbar() {
    return _React$Component.apply(this, arguments) || this;
  }

  var _proto = WizardNavbar.prototype;

  _proto.render = function render() {
    var _this = this;

    var currentStepIndex = this.context.wizard.getCurrentStepIndex();
    var maxVisitedStepIndex = this.context.wizard.getMaxVisitedStepIndex();
    return _react.default.createElement(_Block.Block, {
      cancelBottomOffset: true
    }, _react.default.createElement(_TabPanel.TabPanel, {
      centered: true,
      noBorder: true
    }, this.context.wizard.getSteps().filter(function (step) {
      return !step.props.skipNavbarItem;
    }).map(function (step, index) {
      var isPassed = index < currentStepIndex;
      var isCurrent = index === currentStepIndex;
      var isBlocked = step.props.disabled || index > maxVisitedStepIndex;
      return _react.default.createElement(_TabItem.TabItem, {
        key: 'wizardStep-' + step.props.id,
        testAutomationId: step.props.id,
        active: isCurrent,
        disabled: isBlocked,
        className: (0, _classnames.default)({
          success: isPassed
        }),
        onSelect: function onSelect() {
          return _this.context.wizard.goToStep(step.props.id);
        }
      }, isPassed ? _react.default.createElement(_Icon.Icon, {
        name: "checkbox-selected-readonly"
      }) : _react.default.createElement("strong", null, index + 1), step.props.tabText || step.props.title);
    })));
  };

  return WizardNavbar;
}(_react.default.Component);

exports.WizardNavbar = WizardNavbar;
(0, _defineProperty2.default)(WizardNavbar, "contextTypes", {
  wizard: _propTypes.default.object.isRequired
});