"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var icache_1 = require("@dojo/framework/core/middleware/icache");
var vdom_1 = require("@dojo/framework/core/vdom");
var icon_1 = require("../icon");
var constrained_input_1 = require("../constrained-input");
var theme_1 = require("../middleware/theme");
var css = require("../theme/default/password-input.m.css");
var textInputCss = require("../theme/default/text-input.m.css");
var text_input_1 = require("../text-input");
var factory = vdom_1.create({
    icache: icache_1.createICacheMiddleware(),
    theme: theme_1.default
})
    .properties()
    .children();
exports.PasswordInput = factory(function PasswordInput(_a) {
    var _b = _a.middleware, theme = _b.theme, icache = _b.icache, properties = _a.properties, children = _a.children;
    var props = properties();
    var showPassword = icache.getOrSet('showPassword', false);
    var classes = theme.classes(css);
    var trailing = (vdom_1.tsx(text_input_1.Addon, null,
        vdom_1.tsx("button", { onclick: function (e) {
                e.stopPropagation();
                icache.set('showPassword', !showPassword);
            }, classes: classes.toggleButton, type: "button" },
            vdom_1.tsx(icon_1.default, { type: showPassword ? 'eyeSlashIcon' : 'eyeIcon' }))));
    var handleValidation = function (valid, message) {
        icache.set('valid', { valid: valid, message: message });
        props.onValidate && props.onValidate(valid);
    };
    return props.rules ? (vdom_1.tsx(constrained_input_1.default, tslib_1.__assign({}, props, { rules: props.rules, key: "root", type: showPassword ? 'text' : 'password', theme: theme.compose(textInputCss, css) }), tslib_1.__assign({}, children()[0], { trailing: trailing }))) : (vdom_1.tsx(text_input_1.default, tslib_1.__assign({}, props, { key: "root", type: showPassword ? 'text' : 'password', theme: theme.compose(textInputCss, css), onValidate: handleValidation, valid: icache.get('valid') }), tslib_1.__assign({}, children()[0], { trailing: trailing })));
});
exports.default = exports.PasswordInput;

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