"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FormSelect = void 0;

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _branding = require("../../../mixins/branding");

var _typography = require("../../../mixins/typography");

var _forms = require("../internals/forms.css-rules");

var _forms2 = require("../internals/forms.common");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var getForegroundColor = function getForegroundColor(_ref) {
  var theme = _ref.theme,
      error = _ref.error,
      disabled = _ref.disabled,
      isPlaceholderValue = _ref.isPlaceholderValue;
  if (disabled) return (0, _branding.getPaletteColor)('greyscale-dark')({
    theme: theme
  });
  if (error) return (0, _branding.getPaletteColor)('error-fg')({
    theme: theme
  });

  if (isPlaceholderValue) {
    return (0, _branding.getPaletteColor)('greyscale-dark')({
      theme: theme
    });
  }

  return (0, _branding.getPaletteColor)(theme.defaultTextColor || 'greyscale-black')({
    theme: theme
  });
};

var getFormSelectFontWeight = function getFormSelectFontWeight(_ref2) {
  var isPlaceholderValue = _ref2.isPlaceholderValue,
      labelStyle = _ref2.labelStyle;
  return isPlaceholderValue || labelStyle === 'external' ? 'normal' : 'bold';
};

var getFormSelectFontStyle = function getFormSelectFontStyle(_ref3) {
  var isPlaceholderValue = _ref3.isPlaceholderValue;
  return isPlaceholderValue ? 'italic' : undefined;
};

var getSelectPaddingVertical = function getSelectPaddingVertical(_ref4) {
  var theme = _ref4.theme,
      labelStyle = _ref4.labelStyle;
  return labelStyle === 'floating' || labelStyle === 'external-large' ? theme.spacing.s2 : theme.spacing.s1;
}; // Compensate for any overlaid icons.


var getSelectPaddingRight = function getSelectPaddingRight(_ref5) {
  var error = _ref5.error;
  return error ? '78px' : '30px';
};

var getSelectPaddingLeft = function getSelectPaddingLeft(_ref6) {
  var theme = _ref6.theme;
  return theme.spacing.s2;
}; // Setting the height as fontSize plus vertical padding allows consistent
// label float calculations with varying fontSize. We could do this more
// simply by setting margins instead of padding, but then the click hotspot
// for the internal DOM input is too small.


var getHeight = function getHeight(props) {
  return "".concat(Number.parseInt((0, _typography.getFontSize)(props), 10) + Number.parseInt(getSelectPaddingVertical(props), 10) * 2 + 5 // compensate for select inputs clipping descenders.
  , "px");
};

var FormSelect = _styledComponents["default"].select.withConfig({
  displayName: "FormSelect",
  componentId: "sc-1itsrf-0"
})(["&&{appearance:none;border:0;display:block;outline:none;border-radius:", ";color:", ";font-family:", ";font-size:", ";font-weight:", ";font-style:", ";width:100%;padding-top:", ";padding-right:", ";padding-bottom:", ";padding-left:", ";height:", ";margin-top:-5px;opacity:0;transform:none;overflow:hidden;background:transparent;text-overflow:ellipsis;white-space:nowrap;", "}&:-webkit-autofill{-webkit-box-shadow:0 0 0 50px transparent inset;-webkit-text-fill-color:", ";}&:-webkit-autofill:focus{-webkit-box-shadow:0 0 0 50px transparent inset;-webkit-text-fill-color:", ";}option{font-weight:100;font-style:normal;color:", ";}"], _forms.getCardBorderRadius, getForegroundColor, _typography.getFontFamily, _typography.getFontSize, getFormSelectFontWeight, getFormSelectFontStyle, getSelectPaddingVertical, getSelectPaddingRight, getSelectPaddingVertical, getSelectPaddingLeft, getHeight, _forms2.floatingLabelInputStyles, getForegroundColor, getForegroundColor, (0, _branding.getPaletteColor)('greyscale-dark'));

exports.FormSelect = FormSelect;