import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import * as React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { InputLabel } from '../../Atoms/Inputs/Input';
import { fontSize, prop, theme } from '../../Tools/interpolation';
var Wrapper =
/*#__PURE__*/
styled.div.withConfig({
  componentId: "pe4dcp-0"
})(["\n  position: relative;\n  display: flex;\n  flex-direction: column;\n  height: 100%;\n  width: ", ";\n  box-sizing: border-box;\n\n  &::after {\n    content: '';\n    position: absolute;\n    right: 1rem;\n    bottom: 1.15rem;\n    width: 0;\n    height: 0;\n    border-left: 0.4rem solid transparent;\n    border-right: 0.4rem solid transparent;\n    border-top: 0.4rem solid ", ";\n    pointer-events: none;\n  }\n"], prop('width'), theme('inputColor'));
var Select =
/*#__PURE__*/
styled.select.withConfig({
  componentId: "pe4dcp-1"
})(["\n  width: 100%;\n  height: 2.7rem;\n  padding: 0 2.4rem 0 1rem;\n  color: ", ";\n  background-color: ", ";\n  appearance: none;\n  font-family: ", ";\n  font-weight: ", ";\n  font-size: ", ";\n  font-style: ", ";\n  border-width: 1px;\n  border-color: ", ";\n  border-style: solid;\n  border-radius: ", ";\n  cursor: pointer;\n  outline: none;\n  text-overflow: ellipsis;\n  white-space: nowrap;\n  transition: box-shadow 0.25s ease-out;\n\n  &:disabled {\n    color: ", ";\n    border-color: ", ";\n    background: ", ";\n    cursor: not-allowed;\n  }\n\n  &:required:invalid {\n    color: ", ";\n  }\n\n  option[value=''][disabled] {\n    display: none;\n  }\n\n  option {\n    color: ", ";\n  }\n\n  &:active:not(:disabled),\n  &:focus:not(:disabled) {\n    box-shadow: 0 0 0 1px\n      ", ";\n  }\n"], theme('inputColor'), theme('inputBackgroundColor'), theme('fontPrimary'), prop('weight'), fontSize('md'), function (props) {
  return props.italic === true ? 'italic' : 'normal';
}, function (props) {
  return props.error != null ? theme('dangerColor')(props) : theme('inputBorderColor')(props);
}, theme('inputBorderRadius'), theme('inputColor'), theme('inputBorderColor'), theme('inputBackgroundColorDisabled'), theme('inputPlaceholderColor'), theme('inputColor'), function (props) {
  return props.error != null ? 'transparent' : theme('inputActiveColor');
});

var SingleDropdown = function SingleDropdown(_ref) {
  var className = _ref.className,
      input = _ref.input,
      items = _ref.items,
      placeholder = _ref.placeholder,
      width = _ref.width,
      rest = _objectWithoutProperties(_ref, ["className", "input", "items", "placeholder", "width"]);

  var hasLabel = rest.label != null;
  var hasError = rest.error != null;
  return React.createElement(Wrapper, {
    className: className,
    width: width
  }, (hasLabel || hasError) && React.createElement(InputLabel, {
    disabled: rest.disabled,
    error: hasError,
    name: rest.name
  }, "".concat(rest.label || '').concat(hasLabel && hasError ? ' - ' : '').concat(rest.error || '')), React.createElement(Select, _objectSpread({
    defaultValue: placeholder != null ? '' : undefined
  }, input, rest), placeholder != null && React.createElement("option", {
    disabled: true,
    hidden: true,
    label: placeholder,
    value: ""
  }), items.map(function (item) {
    return React.createElement("option", {
      key: item.value,
      value: item.value
    }, item.text);
  })));
};

SingleDropdown.propTypes = process.env.NODE_ENV !== "production" ? {
  capitalize: PropTypes.bool,
  italic: PropTypes.bool,
  items: PropTypes.arrayOf(PropTypes.shape({
    text: PropTypes.string,
    value: PropTypes.any
  })).isRequired,
  placeholder: PropTypes.string,
  uppercase: PropTypes.bool,
  value: PropTypes.any,
  weight: PropTypes.oneOf([100, 200, 300, 400, 500, 600, 700, 800, 900]),
  width: PropTypes.string.isRequired
} : {};
SingleDropdown.defaultProps = {
  capitalize: false,
  italic: false,
  uppercase: false,
  width: '100%'
};
export default SingleDropdown;