"use strict";

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

var React = _interopRequireWildcard(require("react"));

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

var _autosizeInput = _interopRequireDefault(require("./autosize-input"));

var _value = _interopRequireDefault(require("./value"));

var _multiValue = _interopRequireDefault(require("./multi-value"));

var _dropdown = _interopRequireDefault(require("./dropdown"));

var _utils = require("./utils");

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

var _overrides = require("../helpers/overrides");

var _spinner = require("../spinner");

var _icon = require("../icon");

var _defaultProps = _interopRequireDefault(require("./default-props"));

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

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || 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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }

function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

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

var Select =
/*#__PURE__*/
function (_React$Component) {
  _inherits(Select, _React$Component);

  function Select() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, Select);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Select)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "wrapper", void 0);

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "input", void 0);

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "dragging", void 0);

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "focusAfterClear", void 0);

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "openAfterFocus", void 0);

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", {
      inputValue: '',
      isFocused: false,
      isOpen: false,
      isPseudoFocused: false
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleTouchOutside", function (event) {
      // Handle touch outside on ios to dismiss menu
      // $FlowFixMe
      if (_this.wrapper && !_this.wrapper.contains(event.target)) {
        _this.closeMenu();
      }
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleTouchMove", function () {
      // Set a flag that the view is being dragged
      _this.dragging = true;
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleTouchStart", function () {
      // Set a flag that the view is not being dragged
      _this.dragging = false;
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleTouchEnd", function (event) {
      // Check if the view is being dragged. In this case
      // we don't want to fire the click event (because the user only wants to scroll)
      if (_this.dragging) return; // Fire the mouse events

      _this.handleClick(event);
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleTouchEndClearValue", function (event) {
      // Check if the view is being dragged. In this case
      // we don't want to fire the click event (because the user only wants to scroll)
      if (_this.dragging) return; // Clear the value

      _this.clearValue(event);
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleClick", function (event) {
      // If the event was triggered by a mouse click and not the primary
      // button, or if the component is disabled, ignore it
      if (_this.props.disabled || // $FlowFixMe
      event.type === 'click' && event.button !== 0) {
        return;
      } // $FlowFixMe


      if (event.target.tagName === 'INPUT') {
        if (!_this.state.isFocused) {
          _this.openAfterFocus = _this.props.openOnClick;

          _this.focus();
        } else if (!_this.state.isOpen) {
          _this.setState({
            isOpen: true,
            isPseudoFocused: false
          });
        }

        return;
      }

      event.preventDefault(); // For the non-searchable select, toggle the menu

      if (!_this.props.searchable) {
        // This code means that if a select is searchable,
        // onClick the options menu will not appear, only on
        // subsequent click will it open.
        _this.focus();

        return _this.setState({
          isOpen: !_this.state.isOpen
        });
      }

      if (_this.state.isFocused) {
        // On iOS, we can get into a state where we think the input is
        // focused but it isn't really, since iOS ignores programmatic
        // calls to input.focus() that weren't triggered by a click event.
        // Call focus() again here to be safe.
        _this.focus();

        var toOpen = true; // clears the value so that the cursor will be at the end of input when the component re-renders

        if (_this.input) _this.input.value = '';

        if (_this.focusAfterClear) {
          toOpen = false;
          _this.focusAfterClear = false;
        } // if the input is focused, ensure the menu is open


        _this.setState({
          isOpen: toOpen,
          isPseudoFocused: false
        });
      } else {
        // otherwise, focus the input and open the menu
        _this.openAfterFocus = _this.props.openOnClick;

        _this.focus();
      }
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleClickOnArrow", function (event) {
      // if the event was triggered by a mouse click and not the primary
      // button, or if the component is disabled, ignore it.
      if (_this.props.disabled || // $FlowFixMe
      event.type === 'click' && event.button !== 0) {
        return;
      }

      if (_this.state.isOpen) {
        // prevent default event handlers
        event.stopPropagation();
        event.preventDefault();

        _this.closeMenu();
      } else {
        // If the menu isn't open, let the event bubble to the main handleClick
        _this.setState({
          isOpen: true
        });
      }
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleInputFocus", function (event) {
      if (_this.props.disabled) return;
      var toOpen = _this.state.isOpen || _this.openAfterFocus; //if focus happens after clear values, don't open dropdown yet.

      toOpen = _this.focusAfterClear ? false : toOpen;

      if (_this.props.onFocus) {
        _this.props.onFocus(event);
      }

      _this.setState({
        isFocused: true,
        isOpen: !!toOpen
      });

      _this.focusAfterClear = false;
      _this.openAfterFocus = false;
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleInputBlur", function (event) {
      if (_this.props.onBlur) {
        _this.props.onBlur(event);
      }

      var onBlurredState = {
        isFocused: false,
        isOpen: false,
        isPseudoFocused: false
      };

      if (_this.props.onBlurResetsInput) {
        // $FlowFixMe
        onBlurredState.inputValue = '';
      }

      _this.setState(onBlurredState);
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleInputChange", function (event) {
      var newInputValue = event.target.value;

      _this.setState({
        inputValue: newInputValue,
        isOpen: true,
        isPseudoFocused: false
      });

      if (_this.props.onInputChange) {
        _this.props.onInputChange(event);
      }
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleKeyDown", function (event) {
      if (_this.props.disabled) return;

      switch (event.keyCode) {
        case 8:
          // backspace
          if (!_this.state.inputValue && _this.props.backspaceRemoves) {
            event.preventDefault();

            _this.popValue();
          }

          break;

        case 13:
          // enter
          event.preventDefault();
          event.stopPropagation();

          if (!_this.state.isOpen) {
            _this.setState({
              isOpen: true
            });
          }

          break;

        case 27:
          // escape
          event.preventDefault();

          if (_this.state.isOpen) {
            _this.closeMenu();

            event.stopPropagation();
          } else if (_this.props.clearable && _this.props.escapeClearsValue) {
            _this.clearValue(event);

            event.stopPropagation();
          }

          break;

        case 32:
          // space
          if (_this.props.searchable) {
            break;
          }

          event.preventDefault();

          if (!_this.state.isOpen) {
            _this.setState({
              isOpen: true
            });
          }

          break;

        case 38:
          // up
          event.preventDefault();

          if (!_this.state.isOpen) {
            _this.setState({
              isOpen: true
            });
          }

          break;

        case 40:
          // down
          event.preventDefault();

          if (!_this.state.isOpen) {
            _this.setState({
              isOpen: true
            });
          }

          break;

        case 33:
          // page up
          event.preventDefault();

          if (!_this.state.isOpen) {
            _this.setState({
              isOpen: true
            });
          }

          break;

        case 34:
          // page down
          event.preventDefault();

          if (!_this.state.isOpen) {
            _this.setState({
              isOpen: true
            });
          }

          break;

        case 35:
          // end key
          if (event.shiftKey) {
            break;
          }

          event.preventDefault();

          if (!_this.state.isOpen) {
            _this.setState({
              isOpen: true
            });
          }

          break;

        case 36:
          // home key
          if (event.shiftKey) {
            break;
          }

          event.preventDefault();

          if (!_this.state.isOpen) {
            _this.setState({
              isOpen: true
            });
          }

          break;

        case 46:
          // delete
          if (!_this.state.inputValue && _this.props.deleteRemoves) {
            event.preventDefault();

            _this.popValue();
          }

          break;
      }
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "getOptionLabel", function (_ref) {
      var option = _ref.option;
      return option[_this.props.labelKey];
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "selectValue", function (_ref2) {
      var item = _ref2.item;

      if (item.disabled) {
        return;
      } // NOTE: we add/set the value in a callback to make sure the
      // input value is empty to avoid styling issues in Chrome


      var updatedValue = _this.props.onSelectResetsInput ? '' : _this.state.inputValue;

      if (_this.props.multi) {
        _this.setState({
          inputValue: updatedValue,
          isOpen: !_this.props.closeOnSelect
        }, function () {
          var valueArray = _this.props.value;

          if (valueArray.some(function (i) {
            return i[_this.props.valueKey] === item[_this.props.valueKey];
          })) {
            _this.removeValue(item);
          } else {
            _this.addValue(item);
          }
        });
      } else {
        _this.setState({
          inputValue: updatedValue,
          isOpen: !_this.props.closeOnSelect,
          isPseudoFocused: _this.state.isFocused
        }, function () {
          _this.setValue([item], item, _constants.STATE_CHANGE_TYPE.select);
        });
      }
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "addValue", function (item) {
      var valueArray = _toConsumableArray(_this.props.value);

      _this.setValue(valueArray.concat(item), item, _constants.STATE_CHANGE_TYPE.select);
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "popValue", function () {
      if (_this.props.multi) {
        var valueArray = _toConsumableArray(_this.props.value);

        var valueLength = valueArray.length;
        if (!valueLength) return;
        if (valueArray[valueLength - 1].clearableValue === false) return;
        var item = valueArray.pop();

        _this.setValue(valueArray, item, _constants.STATE_CHANGE_TYPE.remove);
      }
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "removeValue", function (item) {
      var valueArray = _toConsumableArray(_this.props.value);

      _this.setValue(valueArray.filter(function (i) {
        return i[_this.props.valueKey] !== item[_this.props.valueKey];
      }), item, _constants.STATE_CHANGE_TYPE.remove);

      _this.focus();
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "clearValue", function (event) {
      // if the event was triggered by a mouse click and not the primary
      // button, ignore it.
      // $FlowFixMe
      if (event && event.type === 'click' && event.button !== 0) {
        return;
      }

      event.preventDefault();

      _this.setValue(_this.getResetValue(), null, _constants.STATE_CHANGE_TYPE.clear);

      _this.setState({
        inputValue: '',
        isOpen: false
      }, _this.focus);

      _this.focusAfterClear = true;
    });

    return _this;
  }

  _createClass(Select, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      if (this.props.autoFocus) {
        this.focus();
      }
    }
  }, {
    key: "componentDidUpdate",
    value: function componentDidUpdate(prevProps, prevState) {
      if (prevState.isOpen !== this.state.isOpen) {
        this.toggleTouchOutsideEvent(this.state.isOpen);
        var handler = this.state.isOpen ? this.props.onOpen : this.props.onClose;
        handler && handler();
      }
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      this.toggleTouchOutsideEvent(false);
    }
  }, {
    key: "toggleTouchOutsideEvent",
    value: function toggleTouchOutsideEvent(enabled) {
      if (typeof document !== 'undefined') {
        if (enabled) {
          document.addEventListener('touchstart', this.handleTouchOutside);
        } else {
          document.removeEventListener('touchstart', this.handleTouchOutside);
        }
      }
    }
  }, {
    key: "focus",
    value: function focus() {
      if (!this.input) return;
      this.input.focus();
    }
  }, {
    key: "closeMenu",
    value: function closeMenu() {
      if (this.props.onCloseResetsInput) {
        this.setState({
          inputValue: '',
          isOpen: false,
          isPseudoFocused: this.state.isFocused && !this.props.multi
        });
      } else {
        this.setState({
          isOpen: false,
          isPseudoFocused: this.state.isFocused && !this.props.multi
        });
      }
    }
  }, {
    key: "getValueArray",

    /**
     * Extends the value into an array from the given options
     */
    value: function getValueArray(value) {
      var _this2 = this;

      if (!Array.isArray(value)) {
        if (value === null || value === undefined) return [];
        value = [value];
      }

      return value.map(function (value) {
        return (0, _utils.expandValue)(value, _this2.props);
      });
    }
  }, {
    key: "setValue",
    value: function setValue(value, option, type) {
      if (this.props.onChange) {
        this.props.onChange({
          value: value,
          option: option,
          type: type
        });
      }
    }
  }, {
    key: "getResetValue",
    value: function getResetValue() {
      // Clear all except not clearable values
      return this.props.value.filter(function (item) {
        return item.clearableValue === false;
      });
    }
  }, {
    key: "renderLoading",
    value: function renderLoading() {
      if (!this.props.isLoading) return;
      var sharedProps = this.getSharedProps();
      var _this$props$overrides = this.props.overrides,
          overrides = _this$props$overrides === void 0 ? {} : _this$props$overrides;

      var _getOverrides = (0, _overrides.getOverrides)(overrides.LoadingIndicator, _spinner.Spinner),
          _getOverrides2 = _slicedToArray(_getOverrides, 2),
          LoadingIndicator = _getOverrides2[0],
          loadingIndicatorProps = _getOverrides2[1];

      return React.createElement(LoadingIndicator, _extends({
        size: 16,
        overrides: {
          Svg: {
            style: _styledComponents.getLoadingIconStyles
          }
        }
      }, sharedProps, loadingIndicatorProps));
    }
  }, {
    key: "renderValue",
    value: function renderValue(valueArray, isOpen) {
      var _this3 = this;

      var _this$props$overrides2 = this.props.overrides,
          overrides = _this$props$overrides2 === void 0 ? {} : _this$props$overrides2;
      var sharedProps = this.getSharedProps();
      var renderLabel = this.props.getValueLabel || this.getOptionLabel;

      var _getOverrides3 = (0, _overrides.getOverrides)(overrides.Placeholder, _styledComponents.StyledPlaceholder),
          _getOverrides4 = _slicedToArray(_getOverrides3, 2),
          Placeholder = _getOverrides4[0],
          placeholderProps = _getOverrides4[1];

      if (!valueArray.length) {
        var showPlaceholder = (0, _utils.shouldShowPlaceholder)(this.state, this.props, isOpen);
        return showPlaceholder ? React.createElement(Placeholder, _extends({}, sharedProps, placeholderProps), this.props.placeholder) : null;
      }

      if (this.props.multi) {
        return valueArray.map(function (value, i) {
          var disabled = sharedProps.$disabled || value.clearableValue === false;
          return React.createElement(_multiValue.default, _extends({
            value: value,
            key: "value-".concat(i, "-").concat(value[_this3.props.valueKey]),
            removeValue: function removeValue() {
              _this3.removeValue(value);
            },
            disabled: disabled,
            overrides: {
              MultiValue: overrides.MultiValue
            }
          }, sharedProps, {
            $disabled: disabled
          }), renderLabel({
            option: value,
            index: i
          }));
        });
      } else if ((0, _utils.shouldShowValue)(this.state, this.props)) {
        return React.createElement(_value.default, _extends({
          value: valueArray[0],
          disabled: this.props.disabled,
          overrides: {
            SingleValue: overrides.SingleValue
          }
        }, sharedProps), renderLabel({
          option: valueArray[0]
        }));
      }
    }
  }, {
    key: "renderInput",
    value: function renderInput() {
      var _this4 = this;

      var _this$props$overrides3 = this.props.overrides,
          overrides = _this$props$overrides3 === void 0 ? {} : _this$props$overrides3;

      var _getOverrides5 = (0, _overrides.getOverrides)(overrides.InputContainer, _styledComponents.StyledInputContainer),
          _getOverrides6 = _slicedToArray(_getOverrides5, 2),
          InputContainer = _getOverrides6[0],
          inputContainerProps = _getOverrides6[1];

      var sharedProps = this.getSharedProps();
      var isOpen = this.state.isOpen;
      var value = this.state.inputValue;

      if (value && !this.props.onSelectResetsInput && !this.state.isFocused) {
        // It hides input value when it is not focused and was not reset on select
        value = '';
      }

      var inputProps = {
        'aria-expanded': isOpen,
        'aria-haspopup': isOpen,
        'aria-label': this.props['aria-label'],
        'aria-describedby': this.props['aria-describedby'],
        'aria-labelledby': this.props['aria-labelledby'],
        'aria-autocomplete': 'list',
        'aria-disabled': this.props.disabled || null,
        disabled: this.props.disabled || null,
        inputRef: function inputRef(ref) {
          return _this4.input = ref;
        },
        onBlur: this.handleInputBlur,
        onChange: this.handleInputChange,
        onFocus: this.handleInputFocus,
        overrides: {
          Input: overrides.Input
        },
        required: this.props.required,
        role: 'combobox',
        value: value
      };

      if (!this.props.searchable) {
        return React.createElement(InputContainer, _extends({
          "aria-expanded": isOpen,
          "aria-disabled": this.props.disabled,
          "aria-label": this.props['aria-label'],
          "aria-labelledby": this.props['aria-labelledby'],
          onBlur: this.handleInputBlur,
          onFocus: this.handleInputFocus,
          $ref: function $ref(ref) {
            return _this4.input = ref;
          },
          role: "combobox",
          tabIndex: 0
        }, sharedProps, inputContainerProps));
      }

      return React.createElement(InputContainer, _extends({}, sharedProps, inputContainerProps), React.createElement(_autosizeInput.default, _extends({}, sharedProps, inputProps)));
    }
  }, {
    key: "renderClear",
    value: function renderClear() {
      var sharedProps = this.getSharedProps();
      var value = this.props.value;
      if (!this.props.clearable || !value || !value.length || this.props.disabled || this.props.isLoading) return;
      var _this$props$overrides4 = this.props.overrides,
          overrides = _this$props$overrides4 === void 0 ? {} : _this$props$overrides4;

      var _getOverrides7 = (0, _overrides.getOverrides)(overrides.ClearIcon, _icon.Delete),
          _getOverrides8 = _slicedToArray(_getOverrides7, 2),
          ClearIcon = _getOverrides8[0],
          clearIconProps = _getOverrides8[1];

      var ariaLabel = this.props.multi ? 'Clear all' : 'Clear value';
      return React.createElement(ClearIcon, _extends({
        size: 16,
        title: ariaLabel,
        "aria-label": ariaLabel,
        onClick: this.clearValue,
        onTouchEnd: this.handleTouchEndClearValue,
        onTouchMove: this.handleTouchMove,
        onTouchStart: this.handleTouchStart,
        overrides: {
          Svg: _styledComponents.StyledClearIcon
        }
      }, sharedProps, clearIconProps));
    }
  }, {
    key: "renderArrow",
    value: function renderArrow() {
      if (this.props.type !== _constants.TYPE.select) {
        return null;
      }

      var _this$props$overrides5 = this.props.overrides,
          overrides = _this$props$overrides5 === void 0 ? {} : _this$props$overrides5;

      var _getOverrides9 = (0, _overrides.getOverrides)(overrides.SelectArrow, _icon.TriangleDown),
          _getOverrides10 = _slicedToArray(_getOverrides9, 2),
          SelectArrow = _getOverrides10[0],
          selectArrowProps = _getOverrides10[1];

      var sharedProps = this.getSharedProps();
      return React.createElement(SelectArrow, _extends({
        size: 16,
        title: 'open',
        onClick: this.handleClickOnArrow,
        overrides: {
          Svg: _styledComponents.StyledSelectArrow
        }
      }, sharedProps, selectArrowProps));
    }
  }, {
    key: "renderSearch",
    value: function renderSearch() {
      if (this.props.type !== _constants.TYPE.search) {
        return null;
      }

      var _this$props$overrides6 = this.props.overrides,
          overrides = _this$props$overrides6 === void 0 ? {} : _this$props$overrides6;

      var _getOverrides11 = (0, _overrides.getOverrides)(overrides.SearchIcon, _icon.Search),
          _getOverrides12 = _slicedToArray(_getOverrides11, 2),
          SearchIcon = _getOverrides12[0],
          searchIconProps = _getOverrides12[1];

      var sharedProps = this.getSharedProps();
      return React.createElement(SearchIcon, _extends({
        size: 16,
        title: 'search',
        onClick: this.handleClickOnArrow,
        overrides: {
          Svg: _styledComponents.StyledSearchIcon
        }
      }, sharedProps, searchIconProps));
    }
  }, {
    key: "filterOptions",
    value: function filterOptions(excludeOptions) {
      var filterValue = this.state.inputValue;
      var options = this.props.options || [];

      if (this.props.filterOptions) {
        return this.props.filterOptions(options, filterValue, excludeOptions, {
          valueKey: this.props.valueKey,
          labelKey: this.props.labelKey
        });
      } else {
        return options;
      }
    }
  }, {
    key: "renderMenu",
    value: function renderMenu(options, valueArray) {
      var _this$props = this.props,
          error = _this$props.error,
          getOptionLabel = _this$props.getOptionLabel,
          isLoading = _this$props.isLoading,
          labelKey = _this$props.labelKey,
          maxDropdownHeight = _this$props.maxDropdownHeight,
          multi = _this$props.multi,
          noResultsMsg = _this$props.noResultsMsg,
          overrides = _this$props.overrides,
          required = _this$props.required,
          searchable = _this$props.searchable,
          size = _this$props.size,
          type = _this$props.type,
          valueKey = _this$props.valueKey;
      var dropdownProps = {
        error: error,
        getOptionLabel: getOptionLabel || this.getOptionLabel,
        isLoading: isLoading,
        labelKey: labelKey,
        maxDropdownHeight: maxDropdownHeight,
        multi: multi,
        onItemSelect: this.selectValue,
        options: options,
        overrides: overrides,
        required: required,
        searchable: searchable,
        size: size,
        type: type,
        value: valueArray,
        valueKey: valueKey
      };

      if (options && options.length) {
        return React.createElement(_dropdown.default, dropdownProps);
      } else if (noResultsMsg) {
        var _noResults;

        var noResults = (_noResults = {}, _defineProperty(_noResults, valueKey, 'NO_RESULTS_FOUND'), _defineProperty(_noResults, labelKey, noResultsMsg), _defineProperty(_noResults, "disabled", true), _noResults);
        return React.createElement(_dropdown.default, _extends({}, dropdownProps, {
          options: [noResults]
        }));
      } else {
        return null;
      }
    }
  }, {
    key: "getSharedProps",
    value: function getSharedProps() {
      var _this$props2 = this.props,
          disabled = _this$props2.disabled,
          error = _this$props2.error,
          isLoading = _this$props2.isLoading,
          multi = _this$props2.multi,
          required = _this$props2.required,
          size = _this$props2.size,
          searchable = _this$props2.searchable,
          type = _this$props2.type;
      var _this$state = this.state,
          isOpen = _this$state.isOpen,
          isFocused = _this$state.isFocused,
          isPseudoFocused = _this$state.isPseudoFocused;
      return {
        $disabled: disabled,
        $error: error,
        $isFocused: isFocused,
        $isLoading: isLoading,
        $isOpen: isOpen,
        $isPseudoFocused: isPseudoFocused,
        $multi: multi,
        $required: required,
        $searchable: searchable,
        $size: size,
        $type: type
      };
    }
  }, {
    key: "render",
    value: function render() {
      var _this5 = this;

      var _this$props3 = this.props,
          _this$props3$override = _this$props3.overrides,
          overrides = _this$props3$override === void 0 ? {} : _this$props3$override,
          type = _this$props3.type,
          multi = _this$props3.multi,
          value = _this$props3.value,
          filterOutSelected = _this$props3.filterOutSelected;

      var _getOverrides13 = (0, _overrides.getOverrides)(overrides.Root, _styledComponents.StyledRoot),
          _getOverrides14 = _slicedToArray(_getOverrides13, 2),
          Root = _getOverrides14[0],
          rootProps = _getOverrides14[1];

      var _getOverrides15 = (0, _overrides.getOverrides)(overrides.ControlContainer, _styledComponents.StyledControlContainer),
          _getOverrides16 = _slicedToArray(_getOverrides15, 2),
          ControlContainer = _getOverrides16[0],
          controlContainerProps = _getOverrides16[1];

      var _getOverrides17 = (0, _overrides.getOverrides)(overrides.ValueContainer, _styledComponents.StyledValueContainer),
          _getOverrides18 = _slicedToArray(_getOverrides17, 2),
          ValueContainer = _getOverrides18[0],
          valueContainerProps = _getOverrides18[1];

      var sharedProps = this.getSharedProps();
      var valueArray = this.getValueArray(value);
      var options = this.filterOptions(multi && filterOutSelected ? valueArray : null);
      var isOpen = this.state.isOpen;

      if (multi && !options.length && valueArray.length && !this.state.inputValue) {
        isOpen = false;
      }

      sharedProps.$isOpen = isOpen;
      return React.createElement(Root, _extends({
        $ref: function $ref(ref) {
          return _this5.wrapper = ref;
        }
      }, sharedProps, rootProps), React.createElement(ControlContainer, _extends({
        onKeyDown: this.handleKeyDown,
        onClick: this.handleClick,
        onTouchEnd: this.handleTouchEnd,
        onTouchMove: this.handleTouchMove,
        onTouchStart: this.handleTouchStart
      }, sharedProps, controlContainerProps), type === _constants.TYPE.search ? this.renderSearch() : null, React.createElement(ValueContainer, _extends({
        role: "list"
      }, sharedProps, valueContainerProps), this.renderValue(valueArray, isOpen), this.renderInput()), this.renderLoading(), this.renderClear(), type === _constants.TYPE.select ? this.renderArrow() : null), isOpen ? this.renderMenu(options, valueArray) : null);
    }
  }]);

  return Select;
}(React.Component);

_defineProperty(Select, "defaultProps", _defaultProps.default);

var _default = Select;
exports.default = _default;