import EventStream from '../../event/EventStream';
import Renderables from '../Renderables';
import { EventType } from "../../event/EventType";
import { MessageType } from "../../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.SUGGESTION;
                var evType = EventType.withChannelId(EventType.PUBLISH, _this.spec.channelId);
                EventStream.emit(evType, { attributes: attributes, type: type, payload: payload });
            });
        }
        return button;
    };
    Suggestion.TYPE = "suggestion";
    return Suggestion;
}());
export { Suggestion };
Renderables.register(Suggestion.TYPE, Suggestion);
//# sourceMappingURL=index.js.map