"use strict";

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

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

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

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

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

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

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

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

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

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

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

var _iconsReact = require("@wfp/icons-react");

var _js = require("../../globals/js");

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var prefix = _js.settings.prefix;

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

  var _super = _createSuper(StepNavigationItem);

  function StepNavigationItem() {
    (0, _classCallCheck2.default)(this, StepNavigationItem);
    return _super.apply(this, arguments);
  }

  (0, _createClass2.default)(StepNavigationItem, [{
    key: "render",
    value: function render() {
      var _this = this,
          _icon$status;

      var _this$props = this.props,
          className = _this$props.className,
          handleTabClick = _this$props.handleTabClick,
          index = _this$props.index,
          label = _this$props.label,
          status = _this$props.status,
          helperText = _this$props.helperText,
          selectedPage = _this$props.selectedPage,
          _onClick = _this$props.onClick,
          page = _this$props.page,
          renderAnchor = _this$props.renderAnchor;
      var classes = (0, _classnames.default)("".concat(prefix, "--step-navigation__nav-item"), (0, _defineProperty2.default)({}, "".concat(prefix, "--step-navigation__nav-item--before"), page < selectedPage), (0, _defineProperty2.default)({}, "".concat(prefix, "--step-navigation__nav-item--selected"), page === selectedPage), (0, _defineProperty2.default)({}, "".concat(prefix, "--step-navigation__nav-item--").concat(status), status), className);
      var anchorProps = {
        className: "".concat(prefix, "--step-navigation__nav-link"),
        ref: function ref(e) {
          _this.tabAnchor = e;
        }
      };
      var icon = {
        'not-started': {
          icon: _iconsReact.EllipsisGlyph
        },
        warning: {
          icon: _iconsReact.WarningOutlineGlyph
        },
        locked: {
          icon: _iconsReact.LockedGlyph
        },
        skip: {
          icon: _iconsReact.OverflowMenuGlyph
        },
        disabled: {
          icon: _iconsReact.ErrorGlyph
        },
        complete: {
          icon: _iconsReact.CheckmarkGlyph
        },
        summary: {
          icon: _iconsReact.MenuGlyph
        }
      };
      var Icon = (_icon$status = icon[status]) === null || _icon$status === void 0 ? void 0 : _icon$status.icon;
      return /*#__PURE__*/_react.default.createElement("li", {
        tabIndex: -1,
        className: classes,
        onClick: function onClick(evt) {
          if (status !== 'locked') {
            handleTabClick(index, label, evt);

            _onClick(evt);
          }
        },
        role: "presentation"
      }, renderAnchor ? renderAnchor(anchorProps) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
        className: "".concat(prefix, "--step-navigation__nav-item__indicator")
      }, status && page !== selectedPage ? /*#__PURE__*/_react.default.createElement(Icon, {
        width: "14",
        height: "14",
        description: "Step Item"
      }) : /*#__PURE__*/_react.default.createElement("span", null, page + 1)), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("span", {
        className: "".concat(prefix, "--step-navigation__nav-item__text")
      }, label), helperText && /*#__PURE__*/_react.default.createElement("span", {
        className: "".concat(prefix, "--step-navigation__nav-item__helper-text")
      }, helperText))));
    }
  }]);
  return StepNavigationItem;
}(_react.default.Component);

exports.default = StepNavigationItem;
(0, _defineProperty2.default)(StepNavigationItem, "propTypes", {
  /**
   * Provide a className that is applied to the StepNavigation component
   *
   */
  className: _propTypes.default.string,

  /**
   * Provide text that is used alongside the control label for additional help
   *
   */
  helperText: _propTypes.default.node,

  /**
   * Provide the index of the each item
   *
   */
  index: _propTypes.default.number,

  /**
   * Provide the text that will be read by a screen reader when visiting this control
   *
   */
  label: _propTypes.default.string,

  /**
   * By default, this value is "presentation". You can also provide an alternate
   * role if it makes sense from the accessibility-side
   */
  role: _propTypes.default.string.isRequired,

  /**
   * On click handler to change the currently active item.
   **/
  onClick: _propTypes.default.func.isRequired,

  /**
   * Optionally provide an index for the currently selected <Tab>
   */
  selectedPage: _propTypes.default.number.isRequired,

  /**
   * An optional parameter to allow overriding the anchor rendering.
   * Useful for using Tab along with react-router or other client
   * side router libraries.
   */
  renderAnchor: _propTypes.default.func
});
(0, _defineProperty2.default)(StepNavigationItem, "defaultProps", {
  role: 'presentation',
  label: 'provide a label',
  tabIndex: 0,
  selectedPage: 0,
  onClick: function onClick() {}
});