'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var BreadcrumbShorter = require('../ui/BreadcrumbShorter/BreadcrumbShorter.js');
var Breadcrumbs_styles = require('../Breadcrumbs.styles.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

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.default.createElement(BreadcrumbShorter.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.default.createElement(Breadcrumbs_styles.StyledLink, {
      tabIndex: disabled ? -1 : 0,
      href: href,
      disabled: disabled,
      onClick: onClick,
      isHref: Boolean(href || onClick)
    }, title);
  }), renderSeparator, showItems);
  return renderItems;
};

exports.getRenderItems = getRenderItems;
exports.shortItems = shortItems;
