function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import { styled } from '../styles/index.js';
import { TYPE } from './constants.js';
import { getSvgStyles } from '../icon/styled-components.js';
import { StyledList, StyledListItem } from '../menu/index.js';
import { SIZE } from './constants.js';
import { ellipsisText } from '../styles/util.js';

function getFont() {
  var _SIZE$default$SIZE$co;

  var size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : SIZE.default;
  var typography = arguments.length > 1 ? arguments[1] : undefined;
  return (_SIZE$default$SIZE$co = {}, _defineProperty(_SIZE$default$SIZE$co, SIZE.default, typography.font300), _defineProperty(_SIZE$default$SIZE$co, SIZE.compact, typography.font200), _SIZE$default$SIZE$co)[size];
}

function getControlPadding(props, emptyValue) {
  var _SIZE$default$SIZE$co2;

  var sizing = props.$theme.sizing,
      _props$$size = props.$size,
      $size = _props$$size === void 0 ? SIZE.default : _props$$size,
      $type = props.$type,
      $multi = props.$multi;
  var isSearch = $type === TYPE.search;
  var paddingLeft = isSearch ? sizing.scale1000 : sizing.scale500;
  return (_SIZE$default$SIZE$co2 = {}, _defineProperty(_SIZE$default$SIZE$co2, SIZE.default, {
    // `sizing.scale0` based on the multi value component (Tag) top and bottom margin
    paddingTop: $multi && !emptyValue ? "calc(".concat(sizing.scale400, " - ").concat(sizing.scale0, ")") : sizing.scale400,
    paddingBottom: $multi && !emptyValue ? "calc(".concat(sizing.scale400, " - ").concat(sizing.scale0, ")") : sizing.scale400,
    paddingLeft: paddingLeft,
    paddingRight: '0'
  }), _defineProperty(_SIZE$default$SIZE$co2, SIZE.compact, {
    // `sizing.scale0` based on the multi value component (Tag) top and bottom margin
    paddingTop: $multi && !emptyValue ? "calc(".concat(sizing.scale200, " - ").concat(sizing.scale0, ")") : sizing.scale200,
    paddingBottom: $multi && !emptyValue ? "calc(".concat(sizing.scale200, " - ").concat(sizing.scale0, ")") : sizing.scale200,
    paddingLeft: $multi && !emptyValue ? "calc(".concat(paddingLeft, " - ").concat(sizing.scale0, ")") : paddingLeft,
    paddingRight: '0'
  }), _SIZE$default$SIZE$co2)[$size];
}

export var StyledDropdownContainer = styled('div', function (props) {
  var sizing = props.$theme.sizing;
  return {
    boxSizing: 'border-box',
    position: 'absolute',
    width: '100%',
    zIndex: 1,
    marginTop: sizing.scale300,
    paddingTop: '0',
    paddingBottom: '0',
    paddingLeft: sizing.scale300,
    paddingRight: sizing.scale300
  };
});
StyledDropdownContainer.displayName = "StyledDropdownContainer";
export var StyledDropdown = styled(StyledList, function (props) {
  var $maxHeight = props.$maxHeight;
  return {
    maxHeight: $maxHeight
  };
});
StyledDropdown.displayName = "StyledDropdown";
export var StyledDropdownListItem = StyledListItem;
export var StyledOptionContent = styled('div', function (props) {
  var $isHighlighted = props.$isHighlighted,
      $selected = props.$selected,
      $disabled = props.$disabled,
      $theme = props.$theme;
  var _$theme$colors = $theme.colors,
      foregroundAlt = _$theme$colors.foregroundAlt,
      primary400 = _$theme$colors.primary400,
      foreground = _$theme$colors.foreground;
  return {
    cursor: $disabled ? 'not-allowed' : 'pointer',
    color: $disabled ? foregroundAlt : $selected || $isHighlighted ? primary400 : foreground,
    fontWeight: $selected ? 'bold' : 'normal'
  };
});
StyledOptionContent.displayName = "StyledOptionContent";
export var StyledRoot = styled('div', function (props) {
  var typography = props.$theme.typography,
      $size = props.$size;
  return _objectSpread({}, getFont($size, typography), {
    boxSizing: 'border-box',
    position: 'relative'
  });
});
StyledRoot.displayName = "StyledRoot";
export var StyledControlContainer = styled('div', function (props) {
  var $disabled = props.$disabled,
      $error = props.$error,
      $isFocused = props.$isFocused,
      $isPseudoFocused = props.$isPseudoFocused,
      $type = props.$type,
      $searchable = props.$searchable,
      _props$$theme = props.$theme,
      colors = _props$$theme.colors,
      sizing = _props$$theme.sizing,
      animation = _props$$theme.animation,
      borders = _props$$theme.borders;
  return {
    boxSizing: 'border-box',
    overflow: 'hidden',
    width: '100%',
    color: $disabled ? colors.inputTextDisabled : colors.foreground,
    display: 'flex',
    justifyContent: 'space-between',
    cursor: $disabled ? 'not-allowed' : $searchable || $type === TYPE.search ? 'text' : 'pointer',
    backgroundColor: $disabled ? colors.inputFillDisabled : $isFocused || $isPseudoFocused ? colors.background : $error ? colors.negative50 : colors.inputFill,
    borderWidth: '1px',
    borderStyle: 'solid',
    borderColor: $disabled ? colors.inputFillDisabled : $error ? colors.negative400 : $isFocused || $isPseudoFocused ? colors.primary400 : colors.inputFill,
    borderRadius: borders.useRoundedCorners ? sizing.scale100 : '0',
    boxShadow: "0 2px 6px ".concat($disabled ? 'transparent' : $isFocused || $isPseudoFocused ? $error ? colors.shadowError : colors.shadowFocus : 'transparent'),
    transitionProperty: 'border, boxShadow, backgroundColor',
    transitionDuration: animation.timing100,
    transitionTimingFunction: animation.easeOutCurve
  };
});
StyledControlContainer.displayName = "StyledControlContainer";
export var StyledValueContainer = styled('span', function (props) {
  var padding = getControlPadding(props);
  return _objectSpread({
    boxSizing: 'border-box',
    position: 'relative',
    flexGrow: 1,
    flexShrink: 1,
    flexBasis: '0%',
    display: 'flex',
    alignItems: 'center',
    flexWrap: 'wrap',
    overflow: 'hidden'
  }, padding);
});
StyledValueContainer.displayName = "StyledValueContainer";
export var StyledPlaceholder = styled('div', function (props) {
  var $disabled = props.$disabled,
      colors = props.$theme.colors;
  return _objectSpread({
    position: 'absolute',
    top: '0',
    bottom: '0',
    right: '0',
    left: '0',
    color: $disabled ? colors.inputTextDisabled : colors.foregroundAlt,
    maxWidth: '100%',
    overflow: 'hidden',
    textOverflow: 'ellipsis',
    whiteSpace: 'nowrap'
  }, getControlPadding(props, true));
});
StyledPlaceholder.displayName = "StyledPlaceholder";
export var StyledSingleValue = styled('div', function (props) {
  var $searchable = props.$searchable,
      $size = props.$size,
      typography = props.$theme.typography;
  var font = getFont($size, typography);
  return _objectSpread({
    lineHeight: !$searchable ? font.lineHeight : 'inherit',
    boxSizing: 'border-box',
    position: 'absolute',
    top: '0',
    left: '0',
    height: '100%',
    maxWidth: '100%'
  }, ellipsisText, getControlPadding(props));
});
StyledSingleValue.displayName = "StyledSingleValue";
export var StyledInputContainer = styled('div', function (props) {
  var $multi = props.$multi,
      $size = props.$size,
      $searchable = props.$searchable,
      _props$$theme2 = props.$theme,
      typography = _props$$theme2.typography,
      sizing = _props$$theme2.sizing;
  var font = getFont($size, typography);
  return {
    position: 'relative',
    display: 'inline-block',
    maxWidth: '100%',
    background: 'transparent',
    border: 'none',
    boxShadow: 'none',
    outline: 'none',
    marginTop: '0',
    marginBottom: '0',
    marginLeft: '0',
    marginRight: '0',
    // sizing.scale0 to match the multi value component (Tag) top and bottom margin
    paddingTop: $multi ? sizing.scale0 : '0',
    paddingBottom: $multi ? sizing.scale0 : '0',
    paddingLeft: '0',
    paddingRight: '0',
    height: !$searchable ? font.lineHeight : 'auto'
  };
});
StyledInputContainer.displayName = "StyledInputContainer";
export var StyledInput = styled('input', function (props) {
  var typography = props.$theme.typography,
      $size = props.$size,
      $disabled = props.$disabled,
      $searchable = props.$searchable,
      $width = props.$width;
  return _objectSpread({}, getFont($size, typography), {
    boxSizing: 'content-box',
    width: $disabled || !$searchable ? '1px' : $width || '100%',
    maxWidth: '100%',
    background: 'transparent',
    border: 'none',
    boxShadow: 'none',
    display: 'inline-block',
    outline: 'none',
    marginTop: '0',
    marginBottom: '0',
    marginLeft: '0',
    marginRight: '0',
    paddingTop: '0',
    paddingBottom: '0',
    paddingLeft: '0',
    paddingRight: '0'
  });
});
StyledInput.displayName = "StyledInput";
export var StyledInputSizer = styled('div', {
  position: 'absolute',
  top: 0,
  left: 0,
  visibility: 'hidden',
  height: 0,
  overflow: 'scroll',
  whiteSpace: 'pre'
});
StyledInputSizer.displayName = "StyledInputSizer";
export var StyledIconsContainer = styled('div', function (_ref) {
  var sizing = _ref.$theme.sizing;
  return {
    boxSizing: 'border-box',
    position: 'relative',
    display: 'flex',
    flexShrink: 0,
    alignItems: 'center',
    alignSelf: 'stretch',
    paddingRight: sizing.scale500
  };
});
StyledIconsContainer.displayName = "StyledIconsContainer";
export var StyledSelectArrow = styled('svg', function (props) {
  var $theme = props.$theme,
      $disabled = props.$disabled;
  var colors = $theme.colors;
  return _objectSpread({}, getSvgStyles({
    $theme: $theme
  }), {
    color: $disabled ? colors.inputTextDisabled : colors.foregroundAlt,
    cursor: $disabled ? 'not-allowed' : 'pointer'
  });
});
StyledSelectArrow.displayName = "StyledSelectArrow";
export var StyledClearIcon = styled('svg', function (props) {
  var $theme = props.$theme;
  var colors = $theme.colors;
  return _objectSpread({}, getSvgStyles({
    $theme: $theme
  }), {
    color: colors.foregroundAlt,
    cursor: 'pointer'
  });
});
StyledClearIcon.displayName = "StyledClearIcon";
export var getLoadingIconStyles = function getLoadingIconStyles(props) {
  var $theme = props.$theme;
  var colors = $theme.colors;
  return _objectSpread({}, getSvgStyles({
    $theme: $theme
  }), {
    color: colors.foregroundAlt
  });
};
export var StyledSearchIcon = styled('svg', function (props) {
  var $disabled = props.$disabled,
      $theme = props.$theme;
  var colors = $theme.colors,
      sizing = $theme.sizing;
  return _objectSpread({}, getSvgStyles(props), {
    color: $disabled ? colors.inputTextDisabled : colors.foregroundAlt,
    cursor: $disabled ? 'not-allowed' : 'pointer',
    position: 'absolute',
    left: sizing.scale500,
    display: 'inline-block',
    height: '100%'
  });
});
StyledSearchIcon.displayName = "StyledSearchIcon";