"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.StyledSearchIcon = exports.getLoadingIconStyles = exports.StyledClearIcon = exports.StyledSelectArrow = exports.StyledIconsContainer = exports.StyledInputSizer = exports.StyledInput = exports.StyledInputContainer = exports.StyledSingleValue = exports.StyledPlaceholder = exports.StyledValueContainer = exports.StyledControlContainer = exports.StyledRoot = exports.StyledOptionContent = exports.StyledDropdownListItem = exports.StyledDropdown = exports.StyledDropdownContainer = void 0;

var _index = require("../styles/index.js");

var _constants = require("./constants.js");

var _styledComponents = require("../icon/styled-components.js");

var _index2 = require("../menu/index.js");

var _util = require("../styles/util.js");

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; }

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

  var size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.SIZE.default;
  var typography = arguments.length > 1 ? arguments[1] : undefined;
  return (_SIZE$default$SIZE$co = {}, _defineProperty(_SIZE$default$SIZE$co, _constants.SIZE.default, typography.font300), _defineProperty(_SIZE$default$SIZE$co, _constants.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 ? _constants.SIZE.default : _props$$size,
      $type = props.$type,
      $multi = props.$multi;
  var isSearch = $type === _constants.TYPE.search;
  var paddingLeft = isSearch ? sizing.scale1000 : sizing.scale500;
  return (_SIZE$default$SIZE$co2 = {}, _defineProperty(_SIZE$default$SIZE$co2, _constants.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, _constants.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];
}

var StyledDropdownContainer = (0, _index.styled)('div', function (props) {
  return {
    width: "".concat(props.$width, "px")
  };
});
exports.StyledDropdownContainer = StyledDropdownContainer;
StyledDropdownContainer.displayName = "StyledDropdownContainer";
var StyledDropdown = (0, _index.styled)(_index2.StyledList, function (props) {
  var $maxHeight = props.$maxHeight;
  return {
    maxHeight: $maxHeight
  };
});
exports.StyledDropdown = StyledDropdown;
StyledDropdown.displayName = "StyledDropdown";
var StyledDropdownListItem = _index2.StyledListItem;
exports.StyledDropdownListItem = StyledDropdownListItem;
var StyledOptionContent = (0, _index.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'
  };
});
exports.StyledOptionContent = StyledOptionContent;
StyledOptionContent.displayName = "StyledOptionContent";
var StyledRoot = (0, _index.styled)('div', function (props) {
  var typography = props.$theme.typography,
      $size = props.$size;
  return _objectSpread({}, getFont($size, typography), {
    boxSizing: 'border-box',
    position: 'relative'
  });
});
exports.StyledRoot = StyledRoot;
StyledRoot.displayName = "StyledRoot";
var StyledControlContainer = (0, _index.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 === _constants.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
  };
});
exports.StyledControlContainer = StyledControlContainer;
StyledControlContainer.displayName = "StyledControlContainer";
var StyledValueContainer = (0, _index.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);
});
exports.StyledValueContainer = StyledValueContainer;
StyledValueContainer.displayName = "StyledValueContainer";
var StyledPlaceholder = (0, _index.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));
});
exports.StyledPlaceholder = StyledPlaceholder;
StyledPlaceholder.displayName = "StyledPlaceholder";
var StyledSingleValue = (0, _index.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%'
  }, _util.ellipsisText, getControlPadding(props));
});
exports.StyledSingleValue = StyledSingleValue;
StyledSingleValue.displayName = "StyledSingleValue";
var StyledInputContainer = (0, _index.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'
  };
});
exports.StyledInputContainer = StyledInputContainer;
StyledInputContainer.displayName = "StyledInputContainer";
var StyledInput = (0, _index.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'
  });
});
exports.StyledInput = StyledInput;
StyledInput.displayName = "StyledInput";
var StyledInputSizer = (0, _index.styled)('div', {
  position: 'absolute',
  top: 0,
  left: 0,
  visibility: 'hidden',
  height: 0,
  overflow: 'scroll',
  whiteSpace: 'pre'
});
exports.StyledInputSizer = StyledInputSizer;
StyledInputSizer.displayName = "StyledInputSizer";
var StyledIconsContainer = (0, _index.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
  };
});
exports.StyledIconsContainer = StyledIconsContainer;
StyledIconsContainer.displayName = "StyledIconsContainer";
var StyledSelectArrow = (0, _index.styled)('svg', function (props) {
  var $theme = props.$theme,
      $disabled = props.$disabled;
  var colors = $theme.colors;
  return _objectSpread({}, (0, _styledComponents.getSvgStyles)({
    $theme: $theme
  }), {
    color: $disabled ? colors.inputTextDisabled : colors.foregroundAlt,
    cursor: $disabled ? 'not-allowed' : 'pointer'
  });
});
exports.StyledSelectArrow = StyledSelectArrow;
StyledSelectArrow.displayName = "StyledSelectArrow";
var StyledClearIcon = (0, _index.styled)('svg', function (props) {
  var $theme = props.$theme;
  var colors = $theme.colors;
  return _objectSpread({}, (0, _styledComponents.getSvgStyles)({
    $theme: $theme
  }), {
    color: colors.foregroundAlt,
    cursor: 'pointer'
  });
});
exports.StyledClearIcon = StyledClearIcon;
StyledClearIcon.displayName = "StyledClearIcon";

var getLoadingIconStyles = function getLoadingIconStyles(props) {
  var $theme = props.$theme;
  var colors = $theme.colors;
  return _objectSpread({}, (0, _styledComponents.getSvgStyles)({
    $theme: $theme
  }), {
    color: colors.foregroundAlt
  });
};

exports.getLoadingIconStyles = getLoadingIconStyles;
var StyledSearchIcon = (0, _index.styled)('svg', function (props) {
  var $disabled = props.$disabled,
      $theme = props.$theme;
  var colors = $theme.colors,
      sizing = $theme.sizing;
  return _objectSpread({}, (0, _styledComponents.getSvgStyles)(props), {
    color: $disabled ? colors.inputTextDisabled : colors.foregroundAlt,
    cursor: $disabled ? 'not-allowed' : 'pointer',
    position: 'absolute',
    left: sizing.scale500,
    display: 'inline-block',
    height: '100%'
  });
});
exports.StyledSearchIcon = StyledSearchIcon;
StyledSearchIcon.displayName = "StyledSearchIcon";