import * as tslib_1 from "tslib";
import TextInput from '../text-input';
import { create, tsx } from '@dojo/framework/core/vdom';
import { createICacheMiddleware } from '@dojo/framework/core/middleware/icache';
import validation from '../middleware/validation';
import theme from '../middleware/theme';
import * as constrainedInputCss from '../theme/default/constrained-input.m.css';
import * as textInputCss from '../theme/default/text-input.m.css';
const factory = create({
    icache: createICacheMiddleware(),
    validation,
    theme
})
    .properties()
    .children();
export const ConstrainedInput = factory(function ConstrainedInput({ middleware: { icache, validation, theme }, properties, children }) {
    const _a = properties(), { rules, onValidate, helperText } = _a, props = tslib_1.__rest(_a, ["rules", "onValidate", "helperText"]);
    const valid = icache.get('valid');
    const validator = validation(rules);
    const handleValidation = (valid, message) => {
        icache.set('valid', { valid, message });
        onValidate && onValidate(valid);
    };
    const generatedDescribeHelperText = valid && valid.valid === true ? undefined : validator.describe().join(' ');
    return (tsx(TextInput, Object.assign({ key: "root" }, props, { theme: theme.compose(textInputCss, constrainedInputCss), customValidator: validator, valid: valid, onValidate: handleValidation, helperText: helperText ? helperText : generatedDescribeHelperText }), children()[0]));
});
export default ConstrainedInput;

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