"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.converter = exports.types = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _core = require("@material-ui/core");

var _lab = require("@material-ui/lab");

var _jsxRuntime = require("react/jsx-runtime");

var types = ['multiselect'];
exports.types = types;

function AutocompleteField(props) {
  var _props$formData;

  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_lab.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__*/(0, _jsxRuntime.jsx)(_core.Chip, (0, _objectSpread2["default"])({
          variant: "outlined",
          label: option
        }, getTagProps({
          index: index
        })));
      });
    },
    renderInput: function renderInput(params) {
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_core.TextField, (0, _objectSpread2["default"])({}, params));
    }
  });
}

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;
    }
  };
};

exports.converter = converter;
//# sourceMappingURL=autocomplete.cjs.map