"use strict";

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

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

exports.__esModule = true;
exports.BreadCrumbs = 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 _classnames = _interopRequireDefault(require("classnames"));

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

var _BreadCrumb = require("./BreadCrumb");

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

  function BreadCrumbs() {
    var _this;

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

    _this = _Component.call.apply(_Component, [this].concat(args)) || this;
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderCrumb", function (item, index) {
      if (index === void 0) {
        index = 0;
      }

      var _this$props = _this.props,
          items = _this$props.items,
          onSelect = _this$props.onSelect;
      var id = item.id,
          name = item.name;
      var isFirst = index <= 0;
      var isLast = index >= items.length - 1;
      return _react.default.createElement(_BreadCrumb.BreadCrumb, {
        key: id,
        id: id,
        name: name,
        isFirst: isFirst,
        isLast: isLast,
        onSelect: onSelect,
        index: index
      });
    });
    return _this;
  }

  var _proto = BreadCrumbs.prototype;

  _proto.render = function render() {
    var _this$props2 = this.props,
        iconName = _this$props2.iconName,
        items = _this$props2.items,
        style = _this$props2.style,
        onSelect = _this$props2.onSelect,
        testAutomationId = _this$props2.testAutomationId;
    var className = (0, _classnames.default)('rc-breadcrumbs', {
      'rc-breadcrumbs-no-handler': !(0, _lodash.isFunction)(onSelect)
    });
    var icon = null;

    if (iconName) {
      icon = _react.default.createElement(_Icon.Icon, {
        name: iconName,
        className: "rc-breadcrumbs-icon"
      });
    }

    return _react.default.createElement("div", {
      style: style,
      className: className,
      "data-test-automation-id": testAutomationId
    }, icon, items.map(this.renderCrumb));
  };

  return BreadCrumbs;
}(_react.Component);

exports.BreadCrumbs = BreadCrumbs;
(0, _defineProperty2.default)(BreadCrumbs, "propTypes", {
  iconName: _propTypes.default.string,
  items: _propTypes.default.arrayOf(_propTypes.default.shape({
    id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
    name: _propTypes.default.string
  })),
  onSelect: _propTypes.default.func,
  testAutomationId: _propTypes.default.string,
  style: _propTypes.default.object
});
(0, _defineProperty2.default)(BreadCrumbs, "defaultProps", {
  iconName: null,
  items: [],
  onSelect: null,
  testAutomationId: 'breadcrumbs',
  style: null,
  breadcrumbMaxWidth: 240
});