function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(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.font200), _defineProperty(_SIZE$compact$SIZE$de, SIZE.default, typography.font300), _defineProperty(_SIZE$compact$SIZE$de, SIZE.large, typography.font400), _SIZE$compact$SIZE$de)[size];
}

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

  var $theme = props.$theme,
      sizing = props.$theme.sizing,
      _props$$size = props.$size,
      $size = _props$$size === void 0 ? SIZE.default : _props$$size,
      $type = props.$type,
      $multi = props.$multi,
      $isEmpty = props.$isEmpty;
  var isSearch = $type === TYPE.search;
  var paddingLeft = isSearch ? "calc(".concat(sizing.scale1000, " - ").concat(sizing.scale0, ")") : sizing.scale400;
  return (_SIZE$compact$SIZE$de2 = {}, _defineProperty(_SIZE$compact$SIZE$de2, SIZE.compact, (_SIZE$compact = {
    // `sizing.scale0` based on the multi value component (Tag) top and bottom margin
    paddingTop: $multi && !$isEmpty ? "calc(".concat(sizing.scale100, " - ").concat(sizing.scale0, ")") : sizing.scale200,
    paddingBottom: $multi && !$isEmpty ? "calc(".concat(sizing.scale100, " - ").concat(sizing.scale0, ")") : sizing.scale200
  }, _defineProperty(_SIZE$compact, $theme.direction === 'rtl' ? 'paddingRight' : 'paddingLeft', $multi && !$isEmpty ? "calc(".concat(paddingLeft, " - ").concat(sizing.scale0, ")") : paddingLeft), _defineProperty(_SIZE$compact, $theme.direction === 'rtl' ? 'paddingLeft' : 'paddingRight', '0'), _SIZE$compact)), _defineProperty(_SIZE$compact$SIZE$de2, SIZE.default, (_SIZE$default = {
    // `sizing.scale0` based on the multi value component (Tag) top and bottom margin
    paddingTop: $multi && !$isEmpty ? "calc(".concat(sizing.scale400, " - ").concat(sizing.scale0, ")") : sizing.scale400,
    paddingBottom: $multi && !$isEmpty ? "calc(".concat(sizing.scale400, " - ").concat(sizing.scale0, ")") : sizing.scale400
  }, _defineProperty(_SIZE$default, $theme.direction === 'rtl' ? 'paddingRight' : 'paddingLeft', $multi && !$isEmpty ? "calc(".concat(paddingLeft, " + ").concat(sizing.scale0, ")") : paddingLeft), _defineProperty(_SIZE$default, $theme.direction === 'rtl' ? 'paddingLeft' : 'paddingRight', 0), _SIZE$default)), _defineProperty(_SIZE$compact$SIZE$de2, SIZE.large, (_SIZE$large = {
    // `sizing.scale0` based on the multi value component (Tag) top and bottom margin
    paddingTop: $multi && !$isEmpty ? "calc(".concat(sizing.scale600, " - ").concat(sizing.scale0, ")") : sizing.scale550,
    paddingBottom: $multi && !$isEmpty ? "calc(".concat(sizing.scale600, " - ").concat(sizing.scale0, ")") : sizing.scale550
  }, _defineProperty(_SIZE$large, $theme.direction === 'rtl' ? 'paddingRight' : 'paddingLeft', $multi && !$isEmpty ? "calc(".concat(paddingLeft, " - ").concat(sizing.scale0, ")") : paddingLeft), _defineProperty(_SIZE$large, $theme.direction === 'rtl' ? 'paddingLeft' : 'paddingRight', 0), _SIZE$large)), _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',
    width: '100%'
  });
});
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.borderFocus,
      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('div', function (props) {
  var padding = getControlPadding(props);
  return _objectSpread({
    boxSizing: 'border-box',
    position: 'relative',
    flexGrow: 1,
    flexShrink: 1,
    flexBasis: '0%',
    display: 'flex',
    alignItems: 'center',
    flexWrap: props.$multi ? 'wrap' : 'nowrap',
    overflow: 'hidden'
  }, padding);
});
StyledValueContainer.displayName = "StyledValueContainer";
export var StyledPlaceholder = styled('div', function (props) {
  var $disabled = props.$disabled,
      colors = props.$theme.colors;
  return {
    color: $disabled ? colors.inputTextDisabled : colors.foregroundAlt,
    maxWidth: '100%',
    overflow: 'hidden',
    textOverflow: 'ellipsis',
    whiteSpace: 'nowrap'
  };
});
StyledPlaceholder.displayName = "StyledPlaceholder";
export var StyledSingleValue = styled('div', function (props) {
  var _objectSpread2;

  var $searchable = props.$searchable,
      $size = props.$size,
      $theme = props.$theme,
      typography = props.$theme.typography;
  var font = getFont($size, typography);
  return _objectSpread((_objectSpread2 = {
    lineHeight: !$searchable ? font.lineHeight : 'inherit',
    boxSizing: 'border-box'
  }, _defineProperty(_objectSpread2, $theme.direction === 'rtl' ? 'marginRight' : 'marginLeft', $theme.sizing.scale0), _defineProperty(_objectSpread2, "height", '100%'), _defineProperty(_objectSpread2, "maxWidth", '100%'), _objectSpread2), ellipsisText);
});
StyledSingleValue.displayName = "StyledSingleValue";
export var StyledInputContainer = styled('div', function (props) {
  var $size = props.$size,
      $searchable = props.$searchable,
      _props$$theme2 = props.$theme,
      typography = _props$$theme2.typography,
      sizing = _props$$theme2.sizing,
      $isEmpty = props.$isEmpty;
  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: $isEmpty ? 0 : sizing.scale0,
    marginRight: 0,
    paddingTop: 0,
    paddingBottom: 0,
    paddingLeft: 0,
    paddingRight: 0,
    height: String(!$searchable ? font.lineHeight : 'auto'),
    maxHeight: String(font.lineHeight)
  };
});
StyledInputContainer.displayName = "StyledInputContainer";
export var StyledInput = styled('input', function (props) {
  var typography = props.$theme.typography,
      $size = props.$size,
      $searchable = props.$searchable,
      $width = props.$width;
  return _objectSpread({}, getFont($size, typography), {
    boxSizing: 'content-box',
    width: !$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 _objectSpread3;

  var $size = _ref.$size,
      $theme = _ref.$theme,
      typography = _ref.$theme.typography;
  return _objectSpread({}, getFont($size, typography), (_objectSpread3 = {
    position: 'absolute',
    top: 0
  }, _defineProperty(_objectSpread3, $theme.direction === 'rtl' ? 'right' : 'left', 0), _defineProperty(_objectSpread3, "visibility", 'hidden'), _defineProperty(_objectSpread3, "height", 0), _defineProperty(_objectSpread3, "overflow", 'scroll'), _defineProperty(_objectSpread3, "whiteSpace", 'pre'), _objectSpread3));
});
StyledInputSizer.displayName = "StyledInputSizer";
export var StyledIconsContainer = styled('div', function (_ref2) {
  var $theme = _ref2.$theme,
      sizing = _ref2.$theme.sizing;
  return _defineProperty({
    boxSizing: 'border-box',
    position: 'relative',
    display: 'flex',
    flexShrink: 0,
    alignItems: 'center',
    alignSelf: 'stretch'
  }, $theme.direction === 'rtl' ? 'paddingLeft' : 'paddingRight', sizing.scale500);
});
StyledIconsContainer.displayName = "StyledIconsContainer";

function getSvgStyles(_ref4) {
  var $theme = _ref4.$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.foreground,
    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.foreground,
    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.foreground
  });
};
export var StyledSearchIcon = styled('div', function (props) {
  var _objectSpread4;

  var $disabled = props.$disabled,
      $theme = props.$theme;
  var colors = $theme.colors,
      sizing = $theme.sizing;
  return _objectSpread({}, getSvgStyles(props), (_objectSpread4 = {
    color: $disabled ? colors.inputTextDisabled : colors.foreground,
    cursor: $disabled ? 'not-allowed' : 'pointer',
    position: 'absolute'
  }, _defineProperty(_objectSpread4, $theme.direction === 'rtl' ? 'right' : 'left', sizing.scale500), _defineProperty(_objectSpread4, "display", 'flex'), _defineProperty(_objectSpread4, "alignItems", 'center'), _defineProperty(_objectSpread4, "height", '100%'), _objectSpread4));
});
StyledSearchIcon.displayName = "StyledSearchIcon";