import _pt from "prop-types";

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); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

import { isUndefined, noop } from "lodash";
import React from "react";
import classNames from "classnames";
export var DropdownContents = React.forwardRef(function (_ref, ref) {
  var ariaLabel = _ref.ariaLabel,
      canScroll = _ref.canScroll,
      children = _ref.children,
      className = _ref.className,
      direction = _ref.direction,
      maxHeight = _ref.maxHeight,
      isLoading = _ref.isLoading,
      isNoWrap = _ref.isNoWrap,
      minWidth = _ref.minWidth,
      _ref$renderHeader = _ref.renderHeader,
      renderHeader = _ref$renderHeader === void 0 ? noop : _ref$renderHeader,
      testSection = _ref.testSection,
      props = _objectWithoutProperties(_ref, ["ariaLabel", "canScroll", "children", "className", "direction", "maxHeight", "isLoading", "isNoWrap", "minWidth", "renderHeader", "testSection"]);

  var styleProps = {};

  if (!isUndefined(isLoading)) {
    // Supports loading spinner over <ul> contents
    styleProps.position = "relative";
  }

  if (minWidth) {
    styleProps.minWidth = minWidth;
  }

  if (canScroll) {
    styleProps.overflowY = "visible";
    styleProps.maxHeight = "none";
  }

  var wrapperClasses = classNames({
    nowrap: isNoWrap,
    "oui-dropdown": true,
    "oui-dropdown--right": direction === "left",
    "oui-dropdown--up": direction === "up"
  }, className);
  var listClasses = classNames({
    "min-height--100": isLoading
  });
  var wrapperStyles = {};

  if (maxHeight) {
    wrapperStyles.maxHeight = maxHeight;
  }

  return React.createElement("div", _extends({
    ref: ref,
    className: wrapperClasses,
    style: wrapperStyles
  }, props), renderHeader(), React.createElement("ul", _extends({
    className: listClasses,
    role: "listbox",
    "aria-label": ariaLabel,
    style: styleProps
  }, testSection ? {
    "data-test-section": testSection
  } : {}), children));
});
DropdownContents.propTypes = {
  ariaLabel: _pt.string,
  canScroll: _pt.bool,
  children: _pt.any,
  className: _pt.string,
  direction: _pt.oneOf(["left", "right", "up"]),
  maxHeight: _pt.oneOfType([_pt.string, _pt.number]),
  isLoading: _pt.bool,
  isNoWrap: _pt.bool,
  minWidth: _pt.oneOfType([_pt.string, _pt.number]),
  renderHeader: _pt.func,
  testSection: _pt.string
};
DropdownContents.displayName = "DropdownContents";
DropdownContents.defaultProps = {
  canScroll: false,
  direction: "left",
  isLoading: undefined,
  isNoWrap: false,
  testSection: ""
};
export default DropdownContents;