"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 core_1 = require("@jsonforms/core");
var react_2 = require("@jsonforms/react");
var core_2 = require("@material-ui/core");
var core_3 = require("@material-ui/core");
var merge_1 = tslib_1.__importDefault(require("lodash/merge"));
var TrimmableInputLabel = core_2.withStyles({
    root: {
        whiteSpace: 'nowrap',
        overflow: 'hidden',
        textOverflow: 'ellipsis',
        right: '50px',
        bottom: '0px' // avoid horizontal cutoff for characters like `qypgj`
    },
    shrink: {
        width: '125%' // shrinked labels are scaled by 75%, therefore set width to 125% to make it the same width as the input
    }
})(core_2.InputLabel);
var MaterialInputControl = /** @class */ (function (_super) {
    tslib_1.__extends(MaterialInputControl, _super);
    function MaterialInputControl() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    MaterialInputControl.prototype.render = function () {
        var _a = this.props, id = _a.id, description = _a.description, errors = _a.errors, label = _a.label, uischema = _a.uischema, visible = _a.visible, required = _a.required, config = _a.config, input = _a.input;
        var isValid = errors.length === 0;
        var appliedUiSchemaOptions = merge_1.default({}, config, uischema.options);
        var showDescription = !core_1.isDescriptionHidden(visible, description, this.state.isFocused, appliedUiSchemaOptions.showUnfocusedDescription);
        var firstFormHelperText = showDescription
            ? description
            : !isValid
                ? errors
                : null;
        var secondFormHelperText = showDescription && !isValid ? errors : null;
        var InnerComponent = input;
        return (react_1.default.createElement(core_2.Hidden, { xsUp: !visible },
            react_1.default.createElement(core_3.FormControl, { fullWidth: !appliedUiSchemaOptions.trim, onFocus: this.onFocus, onBlur: this.onBlur, id: id },
                react_1.default.createElement(TrimmableInputLabel, { htmlFor: id + '-input', error: !isValid }, core_1.computeLabel(core_1.isPlainLabel(label) ? label : label.default, required, appliedUiSchemaOptions.hideRequiredAsterisk)),
                react_1.default.createElement(InnerComponent, tslib_1.__assign({}, this.props, { id: id + '-input', isValid: isValid, visible: visible })),
                react_1.default.createElement(core_3.FormHelperText, { error: !isValid && !showDescription }, firstFormHelperText),
                react_1.default.createElement(core_3.FormHelperText, { error: !isValid }, secondFormHelperText))));
    };
    return MaterialInputControl;
}(react_2.Control));
exports.MaterialInputControl = MaterialInputControl;
//# sourceMappingURL=MaterialInputControl.js.map