import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import { Chip, TextField } from '@material-ui/core';
import { Autocomplete } from '@material-ui/lab';
import { jsx as _jsx } from "react/jsx-runtime";
export var types = ['multiselect'];

function AutocompleteField(props) {
  var _props$formData;

  return /*#__PURE__*/_jsx(Autocomplete, {
    multiple: true,
    options: props.schema.items.enumNames,
    value: (_props$formData = props.formData) !== null && _props$formData !== void 0 ? _props$formData : [],
    onChange: function onChange(event, value) {
      return props.onChange(value);
    },
    freeSolo: true,
    renderTags: function renderTags(value, getTagProps) {
      return value.map(function (option, index) {
        return /*#__PURE__*/_jsx(Chip, _objectSpread({
          variant: "outlined",
          label: option
        }, getTagProps({
          index: index
        })));
      });
    },
    renderInput: function renderInput(params) {
      return /*#__PURE__*/_jsx(TextField, _objectSpread({}, params));
    }
  });
}

export var converter = function converter(_ref) {
  var config = _ref.config;
  return function (props) {
    if (config.autocomplete) {
      var _props$schema$items, _props$schema$items$e, _props$uiSchema;

      (_props$schema$items$e = (_props$schema$items = props.schema.items).enumNames) !== null && _props$schema$items$e !== void 0 ? _props$schema$items$e : _props$schema$items.enumNames = []; // Allow values outside the choices

      delete props.schema.items["enum"];
      (_props$uiSchema = props.uiSchema) !== null && _props$uiSchema !== void 0 ? _props$uiSchema : props.uiSchema = {};
      props.uiSchema['ui:field'] = AutocompleteField; // To let AutocompleteField know if this is select or multiselect
      // For now only multiselect is supported
      // props.uiSchema['ui:options'] ??= {};
      // props.uiSchema['ui:options'].type = config.type;
    }
  };
};
//# sourceMappingURL=autocomplete.js.map