"use strict";

exports.__esModule = true;
exports.useDropdownPlaceholder = useDropdownPlaceholder;
var _react = require("react");
var _providers = require("../providers");
function useDropdownPlaceholder({
  dropdownSelect,
  filter,
  shouldShowPlaceholder,
  isOverflow,
  placeholderProp
}) {
  const {
    select: {
      selectedValues
    },
    container
  } = dropdownSelect;
  const {
    translate
  } = (0, _providers.useDropdownTranslationContext)();
  const selectedValuesText = (0, _react.useMemo)(() => {
    return selectedValues.map(({
      item
    }) => filter.itemName(item)).join(', ');
  }, [selectedValues]);
  return (0, _react.useMemo)(() => {
    let placeholder = '';
    if (!shouldShowPlaceholder) {
      return {
        selectedValuesText,
        placeholder
      };
    }
    if (selectedValues.length !== 0) {
      if (process.env.NODE_ENV === 'test' && selectedValuesText.length > 40 || isOverflow) {
        placeholder = translate('selectedItems', {
          total: selectedValues.length
        });
      } else {
        placeholder = selectedValuesText;
      }
    } else if (placeholderProp) {
      placeholder = placeholderProp;
    } else {
      placeholder = translate('placeholder');
    }
    return {
      selectedValuesText,
      placeholder
    };
  }, [selectedValues, shouldShowPlaceholder, isOverflow, container.initTask.status.status]);
}
//# sourceMappingURL=useDropdownPlaceholder.js.map