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

  Copyright (c) 2017-2019 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 merge_1 = tslib_1.__importDefault(require("lodash/merge"));
var IconButton_1 = tslib_1.__importDefault(require("@material-ui/core/IconButton"));
var InputAdornment_1 = tslib_1.__importDefault(require("@material-ui/core/InputAdornment"));
var Close_1 = tslib_1.__importDefault(require("@material-ui/icons/Close"));
var MuiInputText = /** @class */ (function (_super) {
    tslib_1.__extends(MuiInputText, _super);
    function MuiInputText() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = { showAdornment: false };
        return _this;
    }
    MuiInputText.prototype.render = function () {
        var _this = this;
        var _a = this.props, data = _a.data, config = _a.config, className = _a.className, id = _a.id, enabled = _a.enabled, uischema = _a.uischema, isValid = _a.isValid, path = _a.path, handleChange = _a.handleChange, schema = _a.schema, muiInputProps = _a.muiInputProps;
        var maxLength = schema.maxLength;
        var appliedUiSchemaOptions = merge_1.default({}, config, uischema.options);
        var inputProps;
        if (appliedUiSchemaOptions.restrict) {
            inputProps = { maxLength: maxLength };
        }
        else {
            inputProps = {};
        }
        inputProps = merge_1.default(inputProps, muiInputProps);
        if (appliedUiSchemaOptions.trim && maxLength !== undefined) {
            inputProps.size = maxLength;
        }
        var onChange = function (ev) { return handleChange(path, ev.target.value); };
        return (react_1.default.createElement(Input_1.default, { type: appliedUiSchemaOptions.format === 'password' ? 'password' : 'text', value: data || '', onChange: onChange, className: className, id: id, disabled: !enabled, autoFocus: appliedUiSchemaOptions.focus, multiline: appliedUiSchemaOptions.multi, fullWidth: !appliedUiSchemaOptions.trim || maxLength === undefined, inputProps: inputProps, error: !isValid, onPointerEnter: function () { return _this.setState({ showAdornment: true }); }, onPointerLeave: function () { return _this.setState({ showAdornment: false }); }, endAdornment: 
            // Use visibility instead of 'Hidden' so the layout doesn't change when the icon is shown
            react_1.default.createElement(InputAdornment_1.default, { position: 'end', style: {
                    visibility: !this.state.showAdornment || !enabled ? 'hidden' : 'visible'
                } },
                react_1.default.createElement(IconButton_1.default, { "aria-label": 'Clear input field', onClick: function () { return handleChange(path, undefined); } },
                    react_1.default.createElement(Close_1.default, null))) }));
    };
    return MuiInputText;
}(react_1.default.PureComponent));
exports.MuiInputText = MuiInputText;
//# sourceMappingURL=MuiInputText.js.map