import React from 'react';
import styled, { css } from 'styled-components';
import { Box, DropdownBubble, FadedScroll, Flexbox, Icon, List as UIList, Separator, Typography } from '../../../../..';
var StyledList = styled(UIList).withConfig({
  displayName: "SingleSelectList__StyledList",
  componentId: "sc-13wx8qv-0"
})(["display:flex;flex-direction:column;list-style:none;"]);
var FadedScrollWithoutPaddingBottom = styled(FadedScroll).withConfig({
  displayName: "SingleSelectList__FadedScrollWithoutPaddingBottom",
  componentId: "sc-13wx8qv-1"
})(["height:100%;"]);
var IE11Wrapper = styled.div.withConfig({
  displayName: "SingleSelectList__IE11Wrapper",
  componentId: "sc-13wx8qv-2"
})(["display:flex;flex-direction:row;"]);
var StyledDropdownBubble = styled(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';
  }
};
export var 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.Children.count(children) > 0;
  return React.createElement(IE11Wrapper, null, React.createElement(StyledDropdownBubble, {
    position: noFormField ? getTrianglePosition(listPosition) : 'right',
    maxHeight: maxHeight || '240px',
    invertedColors: invertedColors
  }, searchComponent, React.createElement(FadedScrollWithoutPaddingBottom, {
    enableMobileFade: true,
    fadeHeight: 8
  }, React.createElement(StyledList, {
    role: "listbox"
  }, children)), actionsComponent !== null && React.createElement(React.Fragment, null, areOptionsProvided && React.createElement(Separator, null), React.createElement(Box, null, actionsComponent))));
};
var hoverIfNotKeyboardNav = css(["", ""], function (p) {
  return p.isKeyboardNavigation ? '' : "\n&:hover {\n  background: ".concat(p.theme.color.inputHover, ";\n}\n");
});
var StyledOption = styled(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 = styled.span.withConfig({
  displayName: "SingleSelectList__EllipsizingText",
  componentId: "sc-13wx8qv-5"
})(["width:100%;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;"]);
export var 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.createElement(StyledOption, {
    selected: selected,
    disabled: disabled,
    focused: focused,
    onClick: onClick,
    type: "secondary",
    color: "inherit",
    isKeyboardNavigation: isKeyboardNavigation,
    fullscreenOnMobile: fullscreenOnMobile
  }, React.createElement(EllipsizingText, null, label), selected && React.createElement(Flexbox, {
    item: true,
    container: true,
    alignItems: "center"
  }, React.createElement(Box, {
    pl: 2
  }, React.createElement(Icon.Check16, {
    color: function color(t) {
      return t.color.cta;
    }
  }))));
};