"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.DropdownContents = void 0;

var _propTypes = _interopRequireDefault(require("prop-types"));

var _lodash = require("lodash");

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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

var DropdownContents = _react["default"].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 ? _lodash.noop : _ref$renderHeader,
      testSection = _ref.testSection,
      props = _objectWithoutProperties(_ref, ["ariaLabel", "canScroll", "children", "className", "direction", "maxHeight", "isLoading", "isNoWrap", "minWidth", "renderHeader", "testSection"]);

  var styleProps = {};

  if (!(0, _lodash.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 = (0, _classnames["default"])({
    nowrap: isNoWrap,
    "oui-dropdown": true,
    "oui-dropdown--right": direction === "left",
    "oui-dropdown--up": direction === "up"
  }, className);
  var listClasses = (0, _classnames["default"])({
    "min-height--100": isLoading
  });
  var wrapperStyles = {};

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

  return _react["default"].createElement("div", _extends({
    ref: ref,
    className: wrapperClasses,
    style: wrapperStyles
  }, props), renderHeader(), _react["default"].createElement("ul", _extends({
    className: listClasses,
    role: "listbox",
    "aria-label": ariaLabel,
    style: styleProps
  }, testSection ? {
    "data-test-section": testSection
  } : {}), children));
});

exports.DropdownContents = DropdownContents;
DropdownContents.propTypes = {
  ariaLabel: _propTypes["default"].string,
  canScroll: _propTypes["default"].bool,
  children: _propTypes["default"].any,
  className: _propTypes["default"].string,
  direction: _propTypes["default"].oneOf(["left", "right", "up"]),
  maxHeight: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
  isLoading: _propTypes["default"].bool,
  isNoWrap: _propTypes["default"].bool,
  minWidth: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
  renderHeader: _propTypes["default"].func,
  testSection: _propTypes["default"].string
};
DropdownContents.displayName = "DropdownContents";
DropdownContents.defaultProps = {
  canScroll: false,
  direction: "left",
  isLoading: undefined,
  isNoWrap: false,
  testSection: ""
};
var _default = DropdownContents;
exports["default"] = _default;