"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.BreadcrumbsItem = BreadcrumbsItem;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _faChevronLeft = require("@fortawesome/free-solid-svg-icons/faChevronLeft");
var _dropdownMenu = require("../dropdown-menu");
var _fontAwesomeIcon = require("../font-awesome-icon");
var _tooltip = require("../tooltip");
var _truncateWithTooltip = require("../truncate-with-tooltip");
var _breadcrumbLinkComponent = require("./breadcrumb-link-component");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function BreadcrumbsItem({
  label,
  options,
  tooltip,
  index,
  selectedKey,
  onDropdownSelect,
  link = '#',
  className = '',
  click = () => {},
  shouldRenderIconBack = false,
  LinkComponent = _breadcrumbLinkComponent.BreadcrumbLinkComponent,
  dropdownMenuProps = {}
}) {
  const tooltipWrapper = tooltip ? children => /*#__PURE__*/(0, _jsxRuntime.jsx)(_tooltip.Tooltip, {
    ...tooltip,
    children: children
  }) : children => children;
  const icon = index === 0 && shouldRenderIconBack && /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
    icon: _faChevronLeft.faChevronLeft,
    "test-id": "crumb-with-arrow-left"
  });
  const labelEl = tooltip ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [icon, label]
  }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_truncateWithTooltip.TruncateWithTooltip, {
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
      children: [icon, label]
    })
  });
  const triggerAriaLabelText = (/*#__PURE__*/_react.default.isValidElement(label) ? undefined // if label is ReactNode - skip
  : label)?.toString();
  return tooltipWrapper(/*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
    className: (0, _classnames.default)('breadcrumb-item', className, {
      'breadcrumb-item-link': link !== '#'
    }),
    "test-id": "breadcrumb-item",
    children: options ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_dropdownMenu.DropdownMenu, {
      ...dropdownMenuProps,
      triggerClassName: (0, _classnames.default)('breadcrumb-item-trigger', dropdownMenuProps.triggerClassName),
      triggerAriaLabelText: triggerAriaLabelText,
      selectedKey: selectedKey,
      options: options,
      onSelect: onDropdownSelect,
      contentClassName: (0, _classnames.default)(dropdownMenuProps.contentClassName, 'breadcrumbs-dropdown-content')
    }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      className: "breadcrumb-item-wrapper",
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkComponent, {
        href: link,
        className: "breadcrumb-link",
        onClick: click,
        testId: `crumb-${index}`,
        children: labelEl
      })
    })
  }));
}