"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var EventStream_1 = require("../../event/EventStream");
var Renderables_1 = require("../Renderables");
var EventType_1 = require("../../event/EventType");
var MessageType_1 = require("../../support/MessageType");
/**
 * Implementation of the 'suggestion' markup element.
 */
var Suggestion = /** @class */ (function () {
    function Suggestion(spec) {
        this.spec = spec;
    }
    /**
     * @inheritDoc
     */
    Suggestion.prototype.render = function (renderer, isNested) {
        var _this = this;
        var position = this.spec.position || 'left';
        var button = document.createElement('button');
        button.setAttribute('name', this.spec.name || "");
        button.classList.add("lto-suggestion", "lto-" + position);
        if (this.spec.id !== undefined) {
            button.id = this.spec.id;
        }
        if (this.spec.class !== undefined) {
            this.spec.class.split(" ").forEach(function (e) { return button.classList.add(e); });
        }
        if (isNested) {
            button.classList.add("lto-nested");
        }
        button.appendChild(document.createTextNode(this.spec.text || ""));
        if (position === "left") {
            button.addEventListener('click', function () {
                // remove left buttons
                var elements = document.querySelectorAll('.lto-suggestion.lto-left');
                elements.forEach(function (element) { return element.remove(); });
                var name = _this.spec.name || "";
                var text = _this.spec.text || "";
                var value = _this.spec.value || "";
                var attributes = { name: name, value: value };
                var payload = { text: text, name: name, value: value };
                var type = MessageType_1.MessageType.SUGGESTION;
                var evType = EventType_1.EventType.withChannelId(EventType_1.EventType.PUBLISH, _this.spec.channelId);
                EventStream_1.default.emit(evType, { attributes: attributes, type: type, payload: payload });
            });
        }
        return button;
    };
    Suggestion.TYPE = "suggestion";
    return Suggestion;
}());
exports.Suggestion = Suggestion;
Renderables_1.default.register(Suggestion.TYPE, Suggestion);
//# sourceMappingURL=index.js.map