import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { isFunction } from 'lodash';
import { filterKeyCodes } from '../../utils/functions';
import { Icon } from '../Icon';
export var BreadCrumb =
/*#__PURE__*/
function (_PureComponent) {
  _inheritsLoose(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;

    _defineProperty(_assertThisInitialized(_this), "handleSelect", function () {
      var _this$props = _this.props,
          id = _this$props.id,
          onSelect = _this$props.onSelect;
      onSelect(id);
    });

    _defineProperty(_assertThisInitialized(_this), "handleKeyDown", 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.createElement(Icon, {
        className: "rc-breadcrumbs-item-icon",
        name: "chevron-right-small"
      });
    }

    if (isLast || !isFunction(onSelect)) {
      text = React.createElement("span", {
        className: "rc-breadcrumbs-item-name",
        "data-test-automation-id": "breadcrumbLink",
        title: name
      }, name);
    } else {
      text = React.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.createElement("div", {
      className: "rc-breadcrumbs-item",
      "data-test-automation-id": "breadcrumb" + index
    }, arrowIcon, text);
  };

  return BreadCrumb;
}(PureComponent);

_defineProperty(BreadCrumb, "propTypes", {
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
  name: PropTypes.string.isRequired,
  index: PropTypes.number.isRequired,
  isFirst: PropTypes.bool,
  isLast: PropTypes.bool,
  onSelect: PropTypes.func
});

_defineProperty(BreadCrumb, "defaultProps", {
  isFirst: false,
  isLast: false,
  onSelect: null
});