"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TypeField = void 0;
var _react = _interopRequireDefault(require("react"));
var _i18n = require("@kbn/i18n");
var _eui = require("@elastic/eui");
var _shared_imports = require("../../../shared_imports");
var _constants = require("../constants");
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */

const TypeField = ({
  isDisabled = false,
  includeComposite,
  path,
  defaultValue = [_constants.RUNTIME_FIELD_OPTIONS_PRIMITIVE[0]]
}) => {
  return /*#__PURE__*/_react.default.createElement(_shared_imports.UseField, {
    path: path
  }, ({
    label,
    value,
    setValue
  }) => {
    if (value === undefined) {
      return null;
    }
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_eui.EuiFormRow, {
      label: label,
      fullWidth: true
    }, /*#__PURE__*/_react.default.createElement(_eui.EuiComboBox, {
      placeholder: _i18n.i18n.translate('indexPatternFieldEditor.editor.form.runtimeType.placeholderLabel', {
        defaultMessage: 'Select a type'
      }),
      singleSelection: {
        asPlainText: true
      },
      options: includeComposite ? _constants.RUNTIME_FIELD_OPTIONS : _constants.RUNTIME_FIELD_OPTIONS_PRIMITIVE,
      selectedOptions: value || defaultValue,
      onChange: newValue => {
        if (newValue.length === 0) {
          // Don't allow clearing the type. One must always be selected
          return;
        }
        setValue(newValue);
      },
      isClearable: false,
      isDisabled: isDisabled,
      "data-test-subj": "typeField",
      "aria-label": _i18n.i18n.translate('indexPatternFieldEditor.editor.form.typeSelectAriaLabel', {
        defaultMessage: 'Type select'
      }),
      fullWidth: true
    })));
  });
};
exports.TypeField = TypeField;