"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

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

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

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

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

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

var _lodash = require("lodash");

var _functions = require("../../utils/functions");

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

var BreadCrumb =
/*#__PURE__*/
function (_PureComponent) {
  (0, _inheritsLoose2.default)(BreadCrumb, _PureComponent);

  function BreadCrumb() {
    var _this;

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

    _this = _PureComponent.call.apply(_PureComponent, [this].concat(args)) || this;
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleSelect", function () {
      var _this$props = _this.props,
          id = _this$props.id,
          onSelect = _this$props.onSelect;
      onSelect(id);
    });
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleKeyDown", (0, _functions.filterKeyCodes)(_this.handleSelect));
    return _this;
  }

  var _proto = BreadCrumb.prototype;

  _proto.render = function render() {
    var _this$props2 = this.props,
        name = _this$props2.name,
        isFirst = _this$props2.isFirst,
        isLast = _this$props2.isLast,
        onSelect = _this$props2.onSelect,
        index = _this$props2.index;
    var arrowIcon = null;
    var text = null;

    if (!isFirst) {
      arrowIcon = _react.default.createElement(_Icon.Icon, {
        className: "rc-breadcrumbs-item-icon",
        name: "chevron-right-small"
      });
    }

    if (isLast || !(0, _lodash.isFunction)(onSelect)) {
      text = _react.default.createElement("span", {
        className: "rc-breadcrumbs-item-name",
        "data-test-automation-id": "breadcrumbLink",
        title: name
      }, name);
    } else {
      text = _react.default.createElement("a", {
        className: "rc-breadcrumbs-item-name rc-breadcrumbs-item-link",
        tabIndex: 0,
        onClick: this.handleSelect,
        onKeyDown: this.handleKeyDown,
        "data-test-automation-id": "breadcrumbLink",
        title: name
      }, name);
    }

    return _react.default.createElement("div", {
      className: "rc-breadcrumbs-item",
      "data-test-automation-id": "breadcrumb" + index
    }, arrowIcon, text);
  };

  return BreadCrumb;
}(_react.PureComponent);

exports.BreadCrumb = BreadCrumb;
(0, _defineProperty2.default)(BreadCrumb, "propTypes", {
  id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
  name: _propTypes.default.string.isRequired,
  index: _propTypes.default.number.isRequired,
  isFirst: _propTypes.default.bool,
  isLast: _propTypes.default.bool,
  onSelect: _propTypes.default.func
});
(0, _defineProperty2.default)(BreadCrumb, "defaultProps", {
  isFirst: false,
  isLast: false,
  onSelect: null
});