var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
import { IBehaviour } from '../api';
import { Defaults } from '../support/Defaults';
import { MessageType } from "../support/MessageType";
import { Label } from "../renderable/label";
import EventStream from "../event/EventStream";
import { EventType } from "../event/EventType";
/**
 * IBehaviour implementation which listens for a mouse click event in order to publish
 * a text message to the outgoing text channel.
 */
var MouseBehaviour = /** @class */ (function (_super) {
    __extends(MouseBehaviour, _super);
    function MouseBehaviour(renderer, button, textArea, callback) {
        var _this = _super.call(this, button || Defaults.invoker(), { type: 'click', handler: function () { return _this.handler(); } }) || this;
        _this.textArea = textArea || Defaults.textbox();
        _this.renderer = renderer;
        _this.callback = callback;
        _this.subscription = null;
        return _this;
    }
    MouseBehaviour.prototype.handler = function () {
        var _this = this;
        var value = this.textArea.value;
        if (this.isValueValid(value)) {
            var evType = EventType.withChannelId(EventType.PUBLISH, this.channelId);
            var attributes = { text: value };
            var type = MessageType.UTTERANCE;
            EventStream.emit(evType, { type: type, payload: value, attributes: attributes });
            this.textArea.value = "";
            this.textArea.dispatchEvent(new Event("input", {}));
            var newElement = { type: Label.TYPE, text: value, position: "right", channelId: this.channelId };
            this.renderer.render(newElement).forEach(function (e) {
                _this.renderer.appendContent(e);
            });
            if (this.callback !== undefined) {
                this.callback();
            }
        }
    };
    return MouseBehaviour;
}(IBehaviour));
export { MouseBehaviour };
//# sourceMappingURL=MouseBehaviour.js.map