"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ListWrapper = void 0;
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _context = require("../context");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var getWidth = function getWidth(p) {
  if (p.width) return p.width;
  if (p.noFormField || p.columns) {
    return 'auto';
  }
  return 'calc(100% + 2px)';
};
var getStylesForPosition = function getStylesForPosition(listPosition) {
  switch (listPosition) {
    case 'left':
      return "right: -1px;";
    default:
      return "left: -1px;";
  }
};
var getStylesForPlacement = function getStylesForPlacement(placement) {
  switch (placement) {
    case 'top':
      return "bottom: 100%;";
    default:
      return "top: 100%;";
  }
};
var StyledListWrapper = _styledComponents.default.div.withConfig({
  displayName: "List__StyledListWrapper",
  componentId: "sc-166tzb-0"
})(["transform:translate3d(0,0,0);position:", ";", " ", " z-index:4;margin:-4px;padding:", ";width:", ";"], function (p) {
  return p.$fullscreenOnMobile ? 'static' : 'absolute';
}, function (p) {
  return getStylesForPlacement(p.placement);
}, function (p) {
  return getStylesForPosition(p.listPosition);
}, function (p) {
  return p.$fullscreenOnMobile ? 0 : '0 4px 4px 4px';
}, getWidth);
var ListWrapper = exports.ListWrapper = _react.default.forwardRef(function (_ref, ref) {
  var Component = _ref.component,
    children = _ref.children,
    noFormField = _ref.noFormField,
    onKeyDown = _ref.onKeyDown,
    onFocus = _ref.onFocus,
    onBlur = _ref.onBlur,
    onMouseMove = _ref.onMouseMove,
    searchComponent = _ref.searchComponent,
    actionsComponent = _ref.actionsComponent,
    width = _ref.width,
    dataTestId = _ref['data-testid'],
    maxHeight = _ref.maxHeight,
    listPosition = _ref.listPosition,
    listWidth = _ref.listWidth,
    placement = _ref.placement,
    itemsPerColumn = _ref.itemsPerColumn,
    columnWidth = _ref.columnWidth,
    invertedColors = _ref.invertedColors;
  var _useSelectMachineFrom = (0, _context.useSelectMachineFromContext)(),
    _useSelectMachineFrom2 = _slicedToArray(_useSelectMachineFrom, 1),
    state = _useSelectMachineFrom2[0];
  var fullscreenOnMobile = state.context.fullscreenOnMobile;
  return _react.default.createElement(StyledListWrapper, {
    ref: ref,
    noFormField: noFormField,
    onKeyDown: onKeyDown,
    onFocus: onFocus,
    onMouseMove: onMouseMove,
    onBlur: onBlur,
    width: width,
    listPosition: listPosition,
    listWidth: listWidth,
    placement: placement,
    $fullscreenOnMobile: fullscreenOnMobile,
    itemsPerColumn: itemsPerColumn,
    invertedColors: invertedColors
  }, _react.default.createElement(Component, {
    searchComponent: searchComponent,
    actionsComponent: actionsComponent,
    maxHeight: maxHeight,
    listPosition: listPosition,
    noFormField: noFormField,
    placement: placement,
    itemsPerColumn: itemsPerColumn,
    listWidth: listWidth,
    columnWidth: columnWidth,
    invertedColors: invertedColors
  }, children));
});