import React__default from 'react';
import { BreadcrumbShorter } from '../ui/BreadcrumbShorter/BreadcrumbShorter.js';
import { StyledLink } from '../Breadcrumbs.styles.js';

var shortItems = function shortItems(items, renderSeparator, showItems) {
  if (!showItems || showItems < 2 || items.length <= showItems) {
    return items;
  }
  var leftSlice = Math.floor(showItems / 2);
  var rightSlice = items.length - leftSlice - showItems % 2;
  var renderItems = items.slice(leftSlice, rightSlice);
  var shorter = /*#__PURE__*/React__default.createElement(BreadcrumbShorter, {
    separator: renderSeparator
  }, renderItems);
  items.splice(leftSlice, rightSlice - leftSlice, shorter);
  return items;
};
var getRenderItems = function getRenderItems(items, renderSeparator, showItems) {
  var renderItems = shortItems(items.map(function (item) {
    if (item.renderItem) {
      return item.renderItem();
    }
    var title = item.title,
      disabled = item.disabled,
      href = item.href,
      onClick = item.onClick;
    return /*#__PURE__*/React__default.createElement(StyledLink, {
      tabIndex: disabled ? -1 : 0,
      href: href,
      disabled: disabled,
      onClick: onClick,
      isHref: Boolean(href || onClick)
    }, title);
  }), renderSeparator, showItems);
  return renderItems;
};

export { getRenderItems, shortItems };
