import Renderables from '../Renderables';
import node from "../../support/node";
import { Specification } from "../../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("textarea");
        new 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;
}());
export { Textarea };
Renderables.register("textarea", Textarea);
//# sourceMappingURL=index.js.map