var _excluded = ["children", "noFormField", "open", "onFocus", "onBlur", "fullWidth", "id", "size", "labelToolTip", "labelTooltipPosition", "labelTooltipInModal", "innerRef"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from 'react';
import styled, { css } from 'styled-components';
import { Flexbox, FormField, OldIcon } from '../../../../..';
var Chevron = styled(OldIcon.ChevronDown).withConfig({
  displayName: "FormFieldOrFragment__Chevron",
  componentId: "sc-1y3h7ub-0"
})(["transform:translateY(-50%) ", ";transform-origin:center center;transition:transform 0.16s ease-out;position:absolute;height:", "px;top:50%;right:", "px;pointer-events:none;"], function (p) {
  return p.open ? 'rotate(180deg)' : 'rotate(0)';
}, function (p) {
  return p.theme.spacing.unit(2);
}, function (p) {
  return p.theme.spacing.unit(1);
});
var StyledRelativeDiv = styled.div.withConfig({
  displayName: "FormFieldOrFragment__StyledRelativeDiv",
  componentId: "sc-1y3h7ub-1"
})(["position:relative;display:block;width:", ";"], function (p) {
  return p.fullWidth ? '100%' : 'auto';
});
var determineHeight = function determineHeight(p) {
  if (p.height) {
    return p.theme.spacing.unit(p.height);
  }
  return p.size === 's' ? p.theme.spacing.unit(8) : p.theme.spacing.unit(10);
};
var height = css(["height:", "px;"], determineHeight);
var hoverBorderStyles = css(["", ""], function (p) {
  return p.disabled ? '' : "\n    &:hover {\n      border-color: ".concat(p.theme.color.inputBorderHover, ";\n    }\n");
});
var focusBorderStyles = css(["&:focus-within{border-color:", ";}&.focus-within{border-color:", ";}"], function (p) {
  return p.theme.color.borderActive;
}, function (p) {
  return p.theme.color.borderActive;
});
var hasError = function hasError(error) {
  return error && error !== '';
};
var borderStyles = css(["border:1px solid ", ";position:relative;", " ", ""], function (p) {
  if (hasError(p.error)) return p.theme.color.inputBorderError;
  if (p.success) return p.theme.color.inputBorderSuccess;
  return p.theme.color.inputBorder;
}, hoverBorderStyles, focusBorderStyles);
var SelectWrapper = styled.div.withConfig({
  displayName: "FormFieldOrFragment__SelectWrapper",
  componentId: "sc-1y3h7ub-2"
})(["", " ", " background:", ";box-sizing:border-box;position:relative;border-radius:", ";"], height, borderStyles, function (p) {
  return p.theme.color.inputBackground;
}, function (_ref) {
  var theme = _ref.theme;
  return theme.borderRadius4;
});
export var FormFieldOrFragment = React.forwardRef(function (_ref2, ref) {
  var children = _ref2.children,
    noFormField = _ref2.noFormField,
    open = _ref2.open,
    onFocus = _ref2.onFocus,
    onBlur = _ref2.onBlur,
    fullWidth = _ref2.fullWidth,
    id = _ref2.id,
    size = _ref2.size,
    labelToolTip = _ref2.labelToolTip,
    labelTooltipPosition = _ref2.labelTooltipPosition,
    labelTooltipInModal = _ref2.labelTooltipInModal,
    innerRef = _ref2.innerRef,
    props = _objectWithoutProperties(_ref2, _excluded);
  if (noFormField) {
    return React.createElement(StyledRelativeDiv, {
      tabIndex: 0,
      ref: ref,
      fullWidth: fullWidth,
      width: props.width,
      onBlur: onBlur,
      onFocus: onFocus
    }, React.createElement(Flexbox, _extends({
      ref: innerRef,
      container: true,
      alignItems: "center"
    }, fullWidth ? {
      width: '100%'
    } : {}), children));
  }
  return React.createElement(StyledRelativeDiv, {
    fullWidth: fullWidth,
    width: props.width
  }, React.createElement(Flexbox, _extends({
    container: true,
    alignItems: "center"
  }, fullWidth ? {
    width: '100%'
  } : {}), React.createElement(FormField, _extends({
    fieldId: id,
    labelTooltip: labelToolTip,
    labelTooltipPosition: labelTooltipPosition,
    labelTooltipInModal: labelTooltipInModal
  }, props, fullWidth ? {
    width: '100%'
  } : {}, {
    ref: ref
  }), React.createElement(SelectWrapper, _extends({
    ref: innerRef,
    onBlur: onBlur,
    onFocus: onFocus,
    size: size
  }, props, {
    tabIndex: 0
  }), children, React.createElement(Chevron, {
    open: open
  })))));
});
FormFieldOrFragment.displayName = 'FormFieldOrFragment';