'use strict';

var React = require('react');
var primitives = require('@bigbinary/neeto-atoms/primitives');
var classnames = require('classnames');
var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
var general = require('@bigbinary/neeto-commons-frontend/utils/general');
var reactRouterDom = require('react-router-dom');
var jsxRuntime = require('react/jsx-runtime');

var Breadcrumbs = reactUtils.withT(function (_ref) {
  var t = _ref.t,
    _ref$breadcrumbs = _ref.breadcrumbs,
    breadcrumbs = _ref$breadcrumbs === void 0 ? [] : _ref$breadcrumbs,
    _ref$hasTrailingSepar = _ref.hasTrailingSeparator,
    hasTrailingSeparator = _ref$hasTrailingSepar === void 0 ? false : _ref$hasTrailingSepar,
    className = _ref.className;
  return /*#__PURE__*/jsxRuntime.jsx(primitives.Breadcrumb, {
    "aria-label": t("neetoMolecules.breadcrumbs.breadcrumbAriaLabel"),
    className: classnames("mb-4", className),
    children: /*#__PURE__*/jsxRuntime.jsx(primitives.BreadcrumbList, {
      children: breadcrumbs.map(function (_ref2, index) {
        var text = _ref2.text,
          _ref2$link = _ref2.link,
          link = _ref2$link === void 0 ? "#" : _ref2$link;
        var isLast = index + 1 === breadcrumbs.length;
        var isCurrentPage = isLast && !hasTrailingSeparator;
        return /*#__PURE__*/jsxRuntime.jsxs(React.Fragment, {
          children: [/*#__PURE__*/jsxRuntime.jsx(primitives.BreadcrumbItem, {
            "data-testid": "header-breadcrumb",
            children: isCurrentPage ? /*#__PURE__*/jsxRuntime.jsx(primitives.BreadcrumbPage, {
              "data-testid": "".concat(general.hyphenize(text), "-breadcrumb"),
              children: text
            }) : /*#__PURE__*/jsxRuntime.jsx(primitives.BreadcrumbLink, {
              asChild: true,
              children: /*#__PURE__*/jsxRuntime.jsx(reactRouterDom.Link, {
                "data-testid": "".concat(general.hyphenize(text), "-breadcrumb"),
                to: link,
                children: text
              })
            })
          }), !isCurrentPage && /*#__PURE__*/jsxRuntime.jsx(primitives.BreadcrumbSeparator, {})]
        }, index);
      })
    })
  });
});

module.exports = Breadcrumbs;
//# sourceMappingURL=Breadcrumbs.js.map
