/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
export var shouldShowValue = function shouldShowValue(state, props) {
  var inputValue = state.inputValue,
      isPseudoFocused = state.isPseudoFocused,
      isFocused = state.isFocused;
  var onSelectResetsInput = props.onSelectResetsInput;
  if (!inputValue) return true;

  if (!onSelectResetsInput) {
    return !(!isFocused && isPseudoFocused || isFocused && !isPseudoFocused);
  }

  return false;
};
export var shouldShowPlaceholder = function shouldShowPlaceholder(state, props, isOpen) {
  var inputValue = state.inputValue,
      isPseudoFocused = state.isPseudoFocused,
      isFocused = state.isFocused;
  var onSelectResetsInput = props.onSelectResetsInput;
  return !inputValue || !onSelectResetsInput && !isOpen && !isPseudoFocused && !isFocused;
};
export var expandValue = function expandValue( // eslint-disable-next-line flowtype/no-weak-types
value, props) {
  var options = props.options,
      valueKey = props.valueKey;
  if (!options) return value;

  for (var i = 0; i < options.length; i++) {
    if (String(options[i][valueKey]) === String(value[valueKey])) {
      return options[i];
    }
  }

  return value;
};