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-2019 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 { StyledList, StyledListItem } from '../menu/index.js';
import { SIZE } from './constants.js';
import { ellipsisText } from '../styles/util.js';

function getFont() {
  var _SIZE$compact$SIZE$de;

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

function getControlPadding(props, emptyValue) {
  var _SIZE$compact$SIZE$de2;

  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$compact$SIZE$de2 = {}, _defineProperty(_SIZE$compact$SIZE$de2, 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'
  }), _defineProperty(_SIZE$compact$SIZE$de2, 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$compact$SIZE$de2, SIZE.large, {
    // `sizing.scale0` based on the multi value component (Tag) top and bottom margin
    paddingTop: $multi && !emptyValue ? "calc(".concat(sizing.scale550, " - ").concat(sizing.scale0, ")") : sizing.scale550,
    paddingBottom: $multi && !emptyValue ? "calc(".concat(sizing.scale550, " - ").concat(sizing.scale0, ")") : sizing.scale550,
    paddingLeft: $multi && !emptyValue ? "calc(".concat(paddingLeft, " - ").concat(sizing.scale0, ")") : paddingLeft,
    paddingRight: 0
  }), _SIZE$compact$SIZE$de2)[$size];
}

export var StyledDropdownContainer = styled('div', function (props) {
  return {
    width: "".concat(String(props.$width), "px")
  };
});
StyledDropdownContainer.displayName = "StyledDropdownContainer";
export var StyledDropdown = StyledList;
export var StyledDropdownListItem = StyledListItem;
export var StyledOptionContent = styled('div', function (props) {
  var $isHighlighted = props.$isHighlighted,
      $selected = props.$selected,
      $disabled = props.$disabled,
      $theme = props.$theme;
  return {
    cursor: $disabled ? 'not-allowed' : 'pointer',
    color: $selected && !$isHighlighted ? $theme.colors.menuFontSelected : null,
    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";

function getControlContainerColors($disabled, $isFocused, $isPseudoFocused, $positive, $error, colors) {
  if ($disabled) {
    return {
      color: colors.inputTextDisabled,
      borderColor: colors.inputFillDisabled,
      backgroundColor: colors.inputFillDisabled
    };
  }

  if ($isFocused || $isPseudoFocused) {
    return {
      color: colors.foreground,
      borderColor: colors.primary400,
      backgroundColor: colors.inputFillActive
    };
  }

  if ($error) {
    return {
      color: colors.foreground,
      borderColor: colors.inputBorderError,
      backgroundColor: colors.inputFillError
    };
  }

  if ($positive) {
    return {
      color: colors.foreground,
      borderColor: colors.inputBorderPositive,
      backgroundColor: colors.inputFillPositive
    };
  }

  return {
    color: colors.foreground,
    borderColor: colors.inputFill,
    backgroundColor: colors.inputFill
  };
}

export var StyledControlContainer = styled('div', function (props) {
  var $disabled = props.$disabled,
      $error = props.$error,
      $positive = props.$positive,
      $isFocused = props.$isFocused,
      $isPseudoFocused = props.$isPseudoFocused,
      $type = props.$type,
      $searchable = props.$searchable,
      _props$$theme = props.$theme,
      borders = _props$$theme.borders,
      colors = _props$$theme.colors,
      animation = _props$$theme.animation;
  return _objectSpread({
    borderTopLeftRadius: borders.inputBorderRadius,
    borderTopRightRadius: borders.inputBorderRadius,
    borderBottomRightRadius: borders.inputBorderRadius,
    borderBottomLeftRadius: borders.inputBorderRadius,
    boxSizing: 'border-box',
    overflow: 'hidden',
    width: '100%',
    display: 'flex',
    justifyContent: 'space-between',
    cursor: $disabled ? 'not-allowed' : $searchable || $type === TYPE.search ? 'text' : 'pointer',
    borderWidth: '2px',
    borderStyle: 'solid',
    transitionProperty: 'border, box-shadow, background-color',
    transitionDuration: animation.timing100,
    transitionTimingFunction: animation.easeOutCurve
  }, getControlContainerColors($disabled, $isFocused, $isPseudoFocused, $positive, $error, colors));
});
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 $size = props.$size,
      $searchable = props.$searchable,
      typography = props.$theme.typography;
  var font = getFont($size, typography);
  return {
    position: 'relative',
    display: 'inline-block',
    maxWidth: '100%',
    backgroundColor: 'transparent',
    border: 'none',
    boxShadow: 'none',
    boxSizing: 'border-box',
    outline: 'none',
    marginTop: 0,
    marginBottom: 0,
    marginLeft: 0,
    marginRight: 0,
    paddingTop: 0,
    paddingBottom: 0,
    paddingLeft: 0,
    paddingRight: 0,
    height: String(!$searchable ? font.lineHeight : 'auto'),
    maxHeight: font.lineHeight
  };
});
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', function (_ref) {
  var $size = _ref.$size,
      typography = _ref.$theme.typography;
  return _objectSpread({}, getFont($size, typography), {
    position: 'absolute',
    top: 0,
    left: 0,
    visibility: 'hidden',
    height: 0,
    overflow: 'scroll',
    whiteSpace: 'pre'
  });
});
StyledInputSizer.displayName = "StyledInputSizer";
export var StyledIconsContainer = styled('div', function (_ref2) {
  var sizing = _ref2.$theme.sizing;
  return {
    boxSizing: 'border-box',
    position: 'relative',
    display: 'flex',
    flexShrink: 0,
    alignItems: 'center',
    alignSelf: 'stretch',
    paddingRight: sizing.scale500
  };
});
StyledIconsContainer.displayName = "StyledIconsContainer";

function getSvgStyles(_ref3) {
  var $theme = _ref3.$theme;
  return {
    display: 'inline-block',
    fill: 'currentColor',
    color: 'currentColor',
    height: $theme.sizing.scale600,
    width: $theme.sizing.scale600
  };
}

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('div', 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: 'flex',
    alignItems: 'center',
    height: '100%'
  });
});
StyledSearchIcon.displayName = "StyledSearchIcon";