import React from 'react';
import classnames from 'classnames';
import { faChevronLeft } from '@fortawesome/free-solid-svg-icons/faChevronLeft';
import { DropdownMenu } from '../dropdown-menu';
import { FontAwesomeIcon } from '../font-awesome-icon';
import { Tooltip } from '../tooltip';
import { TruncateWithTooltip } from '../truncate-with-tooltip';
import { BreadcrumbLinkComponent } from './breadcrumb-link-component';
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
export function BreadcrumbsItem({
  label,
  options,
  tooltip,
  index,
  selectedKey,
  onDropdownSelect,
  link = '#',
  className = '',
  click = () => {},
  shouldRenderIconBack = false,
  LinkComponent = BreadcrumbLinkComponent,
  dropdownMenuProps = {}
}) {
  const tooltipWrapper = tooltip ? children => /*#__PURE__*/_jsx(Tooltip, {
    ...tooltip,
    children: children
  }) : children => children;
  const icon = index === 0 && shouldRenderIconBack && /*#__PURE__*/_jsx(FontAwesomeIcon, {
    icon: faChevronLeft,
    "test-id": "crumb-with-arrow-left"
  });
  const labelEl = tooltip ? /*#__PURE__*/_jsxs(_Fragment, {
    children: [icon, label]
  }) : /*#__PURE__*/_jsx(TruncateWithTooltip, {
    children: /*#__PURE__*/_jsxs("span", {
      children: [icon, label]
    })
  });
  const triggerAriaLabelText = (/*#__PURE__*/React.isValidElement(label) ? undefined // if label is ReactNode - skip
  : label)?.toString();
  return tooltipWrapper(/*#__PURE__*/_jsx("li", {
    className: classnames('breadcrumb-item', className, {
      'breadcrumb-item-link': link !== '#'
    }),
    "test-id": "breadcrumb-item",
    children: options ? /*#__PURE__*/_jsx(DropdownMenu, {
      ...dropdownMenuProps,
      triggerClassName: classnames('breadcrumb-item-trigger', dropdownMenuProps.triggerClassName),
      triggerAriaLabelText: triggerAriaLabelText,
      selectedKey: selectedKey,
      options: options,
      onSelect: onDropdownSelect,
      contentClassName: classnames(dropdownMenuProps.contentClassName, 'breadcrumbs-dropdown-content')
    }) : /*#__PURE__*/_jsx("span", {
      className: "breadcrumb-item-wrapper",
      children: /*#__PURE__*/_jsx(LinkComponent, {
        href: link,
        className: "breadcrumb-link",
        onClick: click,
        testId: `crumb-${index}`,
        children: labelEl
      })
    })
  }));
}