"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
/*
  The MIT License

  Copyright (c) 2017-2020 EclipseSource Munich
  https://github.com/eclipsesource/jsonforms

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
*/
var react_1 = tslib_1.__importDefault(require("react"));
var Input_1 = tslib_1.__importDefault(require("@material-ui/core/Input"));
var Autocomplete_1 = tslib_1.__importDefault(require("@material-ui/lab/Autocomplete"));
var react_2 = require("@jsonforms/react");
var merge_1 = tslib_1.__importDefault(require("lodash/merge"));
exports.MuiAutocomplete = react_1.default.memo(function (props) {
    var data = props.data, className = props.className, id = props.id, enabled = props.enabled, uischema = props.uischema, path = props.path, handleChange = props.handleChange, options = props.options, config = props.config, getOptionLabel = props.getOptionLabel, renderOption = props.renderOption;
    var appliedUiSchemaOptions = merge_1.default({}, config, uischema.options);
    var _a = react_1.default.useState(data), inputValue = _a[0], setInputValue = _a[1];
    var findOption = options.find(function (o) { return o.value === data; });
    return (react_1.default.createElement(Autocomplete_1.default, { className: className, id: id, disabled: !enabled, value: findOption, onChange: function (_event, newValue) {
            handleChange(path, newValue === null || newValue === void 0 ? void 0 : newValue.value);
        }, inputValue: inputValue, onInputChange: function (_event, newInputValue) {
            setInputValue(newInputValue);
        }, autoHighlight: true, autoSelect: true, autoComplete: true, fullWidth: true, options: options, getOptionLabel: getOptionLabel || (function (option) { return option === null || option === void 0 ? void 0 : option.label; }), style: { marginTop: 16 }, renderInput: function (params) { return (react_1.default.createElement(Input_1.default, { style: { width: '100%' }, type: 'text', inputProps: params.inputProps, inputRef: params.InputProps.ref, autoFocus: appliedUiSchemaOptions.focus })); }, renderOption: renderOption }));
}, react_2.areEqual);
//# sourceMappingURL=MuiAutocomplete.js.map