"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Renderables_1 = require("../Renderables");
var node_1 = require("../../support/node");
var Specification_1 = require("../../support/Specification");
/**
 * Implementation of the 'textarea' markup element.
 * A textarea HTML element is created and the given
 * attributes cols, rows, id, name, placeholder and class are applied.
 * The class lto-textarea is added to allow CSS manipulations.
 *
 * @see {@link IRenderable}
 */
var Textarea = /** @class */ (function () {
    function Textarea(spec) {
        this.spec = spec;
    }
    /**
     * @inheritDoc
     */
    Textarea.prototype.render = function (renderer, isNested) {
        var textarea = node_1.default("textarea");
        new Specification_1.Specification(this.spec).initNode(textarea, "lto-textarea");
        textarea.addAttributes({
            cols: this.spec.cols,
            rows: this.spec.rows,
            placeholder: this.spec.placeholder ? this.spec.placeholder : ""
        });
        if (this.spec.value) {
            textarea.unwrap().value = this.spec.value;
            textarea.unwrap().setAttribute("data-value", this.spec.value);
        }
        textarea.addClasses(isNested ? "lto-nested" : "");
        textarea.unwrap().addEventListener("input", function () {
            if (textarea.unwrap().value === "") {
                textarea.unwrap().removeAttribute("data-value");
            }
            else {
                textarea.unwrap().setAttribute("data-value", textarea.unwrap().value);
            }
        });
        return textarea.unwrap();
    };
    return Textarea;
}());
exports.Textarea = Textarea;
Renderables_1.default.register("textarea", Textarea);
//# sourceMappingURL=index.js.map