"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var text_input_1 = require("../text-input");
var vdom_1 = require("@dojo/framework/core/vdom");
var icache_1 = require("@dojo/framework/core/middleware/icache");
var validation_1 = require("../middleware/validation");
var theme_1 = require("../middleware/theme");
var constrainedInputCss = require("../theme/default/constrained-input.m.css");
var textInputCss = require("../theme/default/text-input.m.css");
var factory = vdom_1.create({
    icache: icache_1.createICacheMiddleware(),
    validation: validation_1.default,
    theme: theme_1.default
})
    .properties()
    .children();
exports.ConstrainedInput = factory(function ConstrainedInput(_a) {
    var _b = _a.middleware, icache = _b.icache, validation = _b.validation, theme = _b.theme, properties = _a.properties, children = _a.children;
    var _c = properties(), rules = _c.rules, onValidate = _c.onValidate, helperText = _c.helperText, props = tslib_1.__rest(_c, ["rules", "onValidate", "helperText"]);
    var valid = icache.get('valid');
    var validator = validation(rules);
    var handleValidation = function (valid, message) {
        icache.set('valid', { valid: valid, message: message });
        onValidate && onValidate(valid);
    };
    var generatedDescribeHelperText = valid && valid.valid === true ? undefined : validator.describe().join(' ');
    return (vdom_1.tsx(text_input_1.default, tslib_1.__assign({ key: "root" }, props, { theme: theme.compose(textInputCss, constrainedInputCss), customValidator: validator, valid: valid, onValidate: handleValidation, helperText: helperText ? helperText : generatedDescribeHelperText }), children()[0]));
});
exports.default = exports.ConstrainedInput;

/*# sourceMappingURL=index.js.map*/