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

    _defineProperty(_assertThisInitialized(_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.createElement(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 = classnames('rc-breadcrumbs', {
      'rc-breadcrumbs-no-handler': !isFunction(onSelect)
    });
    var icon = null;

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

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

  return BreadCrumbs;
}(Component);

_defineProperty(BreadCrumbs, "propTypes", {
  iconName: PropTypes.string,
  items: PropTypes.arrayOf(PropTypes.shape({
    id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
    name: PropTypes.string
  })),
  onSelect: PropTypes.func,
  testAutomationId: PropTypes.string,
  style: PropTypes.object
});

_defineProperty(BreadCrumbs, "defaultProps", {
  iconName: null,
  items: [],
  onSelect: null,
  testAutomationId: 'breadcrumbs',
  style: null,
  breadcrumbMaxWidth: 240
});