"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.OptionList = exports.Option = void 0;
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _ = require("../../../../..");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var StyledList = (0, _styledComponents.default)(_.List).withConfig({
  displayName: "SingleSelectList__StyledList",
  componentId: "sc-13wx8qv-0"
})(["display:flex;flex-direction:column;list-style:none;"]);
var FadedScrollWithoutPaddingBottom = (0, _styledComponents.default)(_.FadedScroll).withConfig({
  displayName: "SingleSelectList__FadedScrollWithoutPaddingBottom",
  componentId: "sc-13wx8qv-1"
})(["height:100%;"]);
var IE11Wrapper = _styledComponents.default.div.withConfig({
  displayName: "SingleSelectList__IE11Wrapper",
  componentId: "sc-13wx8qv-2"
})(["display:flex;flex-direction:row;"]);
var StyledDropdownBubble = (0, _styledComponents.default)(_.DropdownBubble).withConfig({
  displayName: "SingleSelectList__StyledDropdownBubble",
  componentId: "sc-13wx8qv-3"
})(["flex-grow:0;flex-shrink:1;flex-basis:auto;width:100%;padding-top:4px;display:flex;flex-direction:column;"]);
var getTrianglePosition = function getTrianglePosition(position) {
  switch (position) {
    case 'left':
      return 'right';
    case 'bottom':
      return 'center';
    case 'center':
      return 'center';
    default:
      return 'left';
  }
};
var OptionList = exports.OptionList = function OptionList(_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,
    noFormField = _ref.noFormField,
    listPosition = _ref.listPosition,
    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) : 'right',
    maxHeight: maxHeight || '240px',
    invertedColors: invertedColors
  }, searchComponent, _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, null, actionsComponent))));
};
var hoverIfNotKeyboardNav = (0, _styledComponents.css)(["", ""], function (p) {
  return p.isKeyboardNavigation ? '' : "\n&:hover {\n  background: ".concat(p.theme.color.inputHover, ";\n}\n");
});
var StyledOption = (0, _styledComponents.default)(_.Typography).withConfig({
  displayName: "SingleSelectList__StyledOption",
  componentId: "sc-13wx8qv-4"
})(["display:flex;align-items:center;", " color:", ";outline:none;white-space:nowrap;", " background:", ";", " cursor:pointer;", ""], function (p) {
  return !p.fullscreenOnMobile ? "\n\t\t\tpadding-right: ".concat(p.theme.spacing.unit(3), "px;\n\t\t\tpadding-left: ").concat(p.theme.spacing.unit(3), "px;\n\t\t\tpadding-top: ").concat(p.theme.spacing.unit(1), "px;\n\t\t\tpadding-bottom: ").concat(p.theme.spacing.unit(1), "px;\n\t\t\theight: ").concat(p.theme.spacing.unit(6), "px;\n\t") : "\n\t\t\tpadding-right: ".concat(p.theme.spacing.unit(1), "px;\n\t\t\tpadding-left: ").concat(p.theme.spacing.unit(1), "px;\n\t\t\theight: ").concat(p.theme.spacing.unit(10), "px;\n\t\t\tborder-bottom: 1px solid ").concat(p.theme.color.divider, ";\n\t");
}, function (p) {
  return p.selected ? p.theme.color.cta : p.theme.color.text;
}, function (p) {
  return p.focused ? "\n    transform: translateZ(0);\n  " : '';
}, function (p) {
  if (p.focused && p.isKeyboardNavigation) return p.theme.color.inputHover;
  return p.theme.color.selectOptionBackground;
}, hoverIfNotKeyboardNav, function (p) {
  return p.disabled ? "\n        color: ".concat(p.theme.color.disabledText, ";\n        pointer-events: none;\n      ") : "";
});
var EllipsizingText = _styledComponents.default.span.withConfig({
  displayName: "SingleSelectList__EllipsizingText",
  componentId: "sc-13wx8qv-5"
})(["width:100%;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;"]);
var Option = exports.Option = function Option(_ref2) {
  var label = _ref2.label,
    disabled = _ref2.disabled,
    selected = _ref2.selected,
    focused = _ref2.focused,
    onClick = _ref2.onClick,
    isKeyboardNavigation = _ref2.isKeyboardNavigation,
    fullscreenOnMobile = _ref2.fullscreenOnMobile;
  return _react.default.createElement(StyledOption, {
    selected: selected,
    disabled: disabled,
    focused: focused,
    onClick: onClick,
    type: "secondary",
    color: "inherit",
    isKeyboardNavigation: isKeyboardNavigation,
    fullscreenOnMobile: fullscreenOnMobile
  }, _react.default.createElement(EllipsizingText, null, label), selected && _react.default.createElement(_.Flexbox, {
    item: true,
    container: true,
    alignItems: "center"
  }, _react.default.createElement(_.Box, {
    pl: 2
  }, _react.default.createElement(_.Icon.Check16, {
    color: function color(t) {
      return t.color.cta;
    }
  }))));
};