import * as React from 'react';
import { injectIntl } from 'react-intl';
import Label from '../../components/label/Label';
import SingleSelectField from '../../components/select-field/SingleSelectField';
import messages from './messages';
import './EnumMetadataField.scss';
const EnumMetadataField = ({
  blurExceptionClassNames,
  dataKey,
  dataValue,
  displayName,
  description,
  intl,
  onChange,
  onRemove,
  options = []
}) => {
  const selectOptions = options.map(option => ({
    displayText: option.key,
    value: option.key,
    isSelectable: true
  }));
  const defaultValue = intl.formatMessage(messages.metadataFieldSelectValue);
  selectOptions.unshift({
    displayText: defaultValue,
    value: defaultValue,
    isSelectable: false
  });
  return /*#__PURE__*/React.createElement("div", {
    className: "bdl-EnumMetadataField"
  }, /*#__PURE__*/React.createElement(Label, {
    text: displayName
  }, !!description && /*#__PURE__*/React.createElement("i", {
    className: "bdl-EnumMetadataField-desc"
  }, description), /*#__PURE__*/React.createElement(SingleSelectField, {
    blurExceptionClassNames: blurExceptionClassNames,
    isEscapedWithReference: true,
    isScrollable: true,
    onChange: option => {
      if (option.isSelectable) {
        onChange(dataKey, option.value);
      } else if (onRemove) {
        onRemove(dataKey);
      }
    },
    options: selectOptions,
    selectedValue:
    // Conditional to make flow happy, dataValue should never be an array
    Array.isArray(dataValue) ? dataValue.join(', ') : dataValue || defaultValue
  })));
};
export { EnumMetadataField as EnumMetadataFieldBase };
export default injectIntl(EnumMetadataField);
//# sourceMappingURL=EnumMetadataField.js.map