function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

/*
Copyright (c) 2018-2019 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import React, { Children } from 'react';
import { LocaleContext } from '../locale/index.js';
import { ThemeContext } from '../styles/theme-provider.js';
import ChevronRight from '../icon/chevron-right.js';
import ChevronLeft from '../icon/chevron-left.js';
import { StyledRoot, StyledSeparator, StyledList, StyledListItem } from './styled-components.js';
import { getOverrides, mergeOverrides } from '../helpers/overrides.js';
export function BreadcrumbsRoot(props) {
  const {
    overrides = {}
  } = props;
  const numChildren = Children.count(props.children);
  const childrenWithSeparators = [];
  const [Root, baseRootProps] = getOverrides(overrides.Root, StyledRoot);
  const [Right, baseIconProps] = getOverrides(overrides.Icon, ChevronRight);
  const [Left] = getOverrides(overrides.Icon, ChevronLeft);
  const [List, baseListProps] = getOverrides(overrides.List, StyledList);
  const [ListItem, baseListItemProps] = getOverrides(overrides.ListItem, StyledListItem);
  const [Separator, baseSeparatorProps] = getOverrides(overrides.Separator, StyledSeparator);
  const iconOverrides = mergeOverrides({
    Svg: {
      style: {
        verticalAlign: 'text-bottom'
      }
    }
  }, // $FlowFixMe
  baseIconProps && baseIconProps.overrides); // $FlowFixMe

  baseIconProps.overrides = iconOverrides;
  Children.forEach(props.children, (child, index) => {
    childrenWithSeparators.push(React.createElement(ListItem, _extends({
      key: `breadcrumb-item-${index}`,
      $itemIndex: index
    }, baseListItemProps), child, index !== numChildren - 1 && React.createElement(Separator, _extends({}, baseSeparatorProps, {
      key: `separator-${index}`
    }), React.createElement(ThemeContext.Consumer, null, theme => theme.direction === 'rtl' ? React.createElement(Left, baseIconProps) : React.createElement(Right, baseIconProps)))));
  });
  return React.createElement(Root, _extends({
    "aria-label": props.ariaLabel || (props.locale ? props.locale.ariaLabel : ''),
    "data-baseweb": "breadcrumbs"
  }, baseRootProps), React.createElement(List, baseListProps, childrenWithSeparators));
}

function Breadcrumbs(props) {
  return React.createElement(LocaleContext.Consumer, null, locale => React.createElement(BreadcrumbsRoot, _extends({}, props, {
    locale: locale.breadcrumbs
  })));
}

Breadcrumbs.defaultProps = {
  overrides: {}
};
export default Breadcrumbs;