"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Breadcrumbs = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _truncatedBreadcrumbs = require("./truncated-breadcrumbs");
var _breadcrumbsItem = require("./breadcrumbs-item");
var _breadcrumbLinkComponent = require("./breadcrumb-link-component");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const maxBreadcrumbsItemWidth = 200;
/** Breadcrumbs allow showing users their location within a website
 * [CAPITALIZATION] Based on component in trail, each new step starts with a capital
 * @midnight-gray-supported
 * @alpine-light-supported
 */
const Breadcrumbs = ({
  crumbs,
  className = '',
  shouldRenderIconBack = false,
  maxBreadcrumbsWidth = 650,
  LinkComponent = _breadcrumbLinkComponent.BreadcrumbLinkComponent
}) => {
  const showItemsInBreadcrumbs = Math.ceil(maxBreadcrumbsWidth / maxBreadcrumbsItemWidth);
  const crumbsNumber = crumbs?.length;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
    children: crumbsNumber > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
      className: (0, _classnames.default)('breadcrumbs', className),
      "test-id": "breadcrumbs"
      // eslint-disable-next-line react/forbid-dom-props
      ,
      style: {
        maxWidth: maxBreadcrumbsWidth
      },
      children: crumbsNumber > showItemsInBreadcrumbs && crumbsNumber > 2 ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_truncatedBreadcrumbs.TruncatedBreadcrumbs, {
        crumbs: crumbs,
        showItemsInBreadcrumbs: showItemsInBreadcrumbs
      }) : crumbs.map((item, index) => /*#__PURE__*/(0, _react.createElement)(_breadcrumbsItem.BreadcrumbsItem, {
        ...item,
        key: index,
        index: index,
        shouldRenderIconBack: shouldRenderIconBack,
        LinkComponent: LinkComponent
      }))
    })
  });
};
exports.Breadcrumbs = Breadcrumbs;