"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.List = void 0;
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _ = require("../../../../..");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var StyledColumnsList = (0, _styledComponents.default)(_.List).withConfig({
  displayName: "List__StyledColumnsList",
  componentId: "sc-4m1ztu-0"
})(["display:grid;grid-auto-flow:column;grid-template-rows:repeat(", ",max-content);grid-gap:0;padding:0;list-style:none;position:relative;& li{width:", ";}"], function (p) {
  return p.itemsPerColumn;
}, function (p) {
  return p.columnWidth || 'auto';
});
var StyledList = (0, _styledComponents.default)(_.List).withConfig({
  displayName: "List__StyledList",
  componentId: "sc-4m1ztu-1"
})(["display:flex;flex-direction:column;list-style:none;"]);
var FadedScrollWithoutPaddingBottom = (0, _styledComponents.default)(_.FadedScroll).withConfig({
  displayName: "List__FadedScrollWithoutPaddingBottom",
  componentId: "sc-4m1ztu-2"
})(["height:100%;"]);
var IE11Wrapper = _styledComponents.default.div.withConfig({
  displayName: "List__IE11Wrapper",
  componentId: "sc-4m1ztu-3"
})(["display:flex;flex-direction:row;"]);
var getMinWidth = function getMinWidth(p) {
  if (p.itemsPerColumn) {
    return 'auto';
  }
  if (p.listWidth) {
    return p.listWidth;
  }
  return "".concat(p.theme.spacing.unit(41), "px");
};
var StyledDropdownBubble = (0, _styledComponents.default)(_.DropdownBubble).withConfig({
  displayName: "List__StyledDropdownBubble",
  componentId: "sc-4m1ztu-4"
})(["flex-grow:0;flex-shrink:1;flex-basis:auto;display:flex;flex-direction:column;-ms-overflow-y:scroll;width:", ";min-width:", ";padding-top:", "px;padding-bottom:", "px;"], function (p) {
  return p.itemsPerColumn ? 'auto' : '100%';
}, getMinWidth, function (p) {
  return p.theme.spacing.unit(1);
}, function (p) {
  return p.theme.spacing.unit(1);
});
var getTrianglePosition = function getTrianglePosition(position) {
  switch (position) {
    case 'left':
      return 'right';
    case 'bottom':
      return 'center';
    case 'center':
      return 'center';
    default:
      return 'left';
  }
};
var List = exports.List = function List(_ref) {
  var children = _ref.children,
    _ref$searchComponent = _ref.searchComponent,
    searchComponent = _ref$searchComponent === void 0 ? null : _ref$searchComponent,
    _ref$actionsComponent = _ref.actionsComponent,
    actionsComponent = _ref$actionsComponent === void 0 ? null : _ref$actionsComponent,
    maxHeight = _ref.maxHeight,
    listPosition = _ref.listPosition,
    noFormField = _ref.noFormField,
    placement = _ref.placement,
    itemsPerColumn = _ref.itemsPerColumn,
    columnWidth = _ref.columnWidth,
    listWidth = _ref.listWidth,
    invertedColors = _ref.invertedColors;
  var areOptionsProvided = _react.default.Children.count(children) > 0;
  return _react.default.createElement(IE11Wrapper, null, _react.default.createElement(StyledDropdownBubble, {
    position: noFormField ? getTrianglePosition(listPosition) : 'left',
    placement: placement,
    maxHeight: maxHeight || '240px',
    itemsPerColumn: itemsPerColumn,
    listWidth: listWidth,
    invertedColors: invertedColors
  }, searchComponent, itemsPerColumn ? _react.default.createElement(StyledColumnsList, {
    itemsPerColumn: itemsPerColumn,
    columnWidth: columnWidth,
    role: "listbox"
  }, children) : _react.default.createElement(FadedScrollWithoutPaddingBottom, {
    enableMobileFade: true,
    fadeHeight: 8
  }, _react.default.createElement(StyledList, {
    role: "listbox"
  }, children)), actionsComponent !== null && _react.default.createElement(_react.default.Fragment, null, areOptionsProvided && _react.default.createElement(_.Separator, null), _react.default.createElement(_.Box, {
    pt: areOptionsProvided ? 1 : 0
  }, actionsComponent))));
};