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 * as React from 'react';
import { LocaleContext } from '../locale/index.js'; // Components

import { StyledList, StyledEmptyState } from './styled-components.js';
import OptionList from './option-list.js';
import { getOverrides } from '../helpers/overrides.js'; // Types

export default function Menu(props) {
  const {
    activedescendantId,
    getRequiredItemProps = (item, index) => ({}),
    items,
    noResultsMsg,
    overrides = {},
    rootRef = React.createRef(),
    focusMenu = () => {},
    unfocusMenu = () => {}
  } = props;
  const [List, listProps] = getOverrides(overrides.List, StyledList);
  const [Option, optionProps] = getOverrides(overrides.Option, OptionList);
  const [EmptyState, emptyStateProps] = getOverrides(overrides.EmptyState, StyledEmptyState);
  return React.createElement(LocaleContext.Consumer, null, locale => React.createElement(List, _extends({
    "aria-activedescendant": activedescendantId || null,
    role: "listbox",
    ref: rootRef,
    onMouseEnter: focusMenu,
    onMouseOver: focusMenu,
    onFocus: focusMenu,
    onBlur: unfocusMenu,
    tabIndex: 0,
    "data-baseweb": "menu"
  }, listProps), !items || !items.length ? React.createElement(EmptyState, emptyStateProps, noResultsMsg || locale.menu.noResultsMsg) : items.map((item, index) => {
    const {
      disabled,
      isFocused,
      isHighlighted,
      ref,
      resetMenu = () => {},
      ...restProps
    } = getRequiredItemProps(item, index);
    return React.createElement(Option, _extends({
      key: index,
      item: item,
      overrides: overrides,
      resetMenu: resetMenu,
      role: "option",
      $disabled: disabled,
      ref: ref,
      $isFocused: isFocused,
      $isHighlighted: isHighlighted,
      "aria-selected": isHighlighted && isFocused
    }, restProps, optionProps));
  })));
}