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 { AbstractDecorator } from "./AbstractDecorator";
import { ProcessNode } from "../../renderable/rating/ProcessNode";
import { Rating } from "../../renderable/rating";
import { EventFactory } from "../../event/EventFactory";
/**
 * The rating decorator adds two rating buttons (like, dislike)
 * after each system conversation output,
 * to allow users to give feedback.
 */
var RatingDecorator = /** @class */ (function (_super) {
    __extends(RatingDecorator, _super);
    function RatingDecorator(renderer, renderStrategy) {
        if (renderStrategy === void 0) { renderStrategy = RatingRenderStrategy.ALL_EXCEPT_DISABLED_RATINGS; }
        var _this = _super.call(this, renderer) || this;
        _this.renderStrategy = renderStrategy;
        return _this;
    }
    /**
     * Appends a rating to eligible interaction root containers. A container is eligible for rating rendering if
     * the rating markup element is specified and the enabled attribute is not set to false. A container is also
     * eligible for rating rendering if no rating markup element is specified and ratingsEnabledByDefault is set to
     * true.
     *
     * @param renderable the renderable specification which was received
     * @param parentContainer the parent container of the current renderable
     */
    RatingDecorator.prototype.render = function (renderable, parentContainer) {
        var result = _super.prototype.render.call(this, renderable, parentContainer);
        if (!this.shouldRenderRatingFor(renderable, parentContainer))
            return result;
        var processNode = ProcessNode.createFromSpecification(renderable);
        if (processNode === null)
            return result;
        // Append rating buttons to allow feedback
        var r = new Rating({
            type: Rating.TYPE,
            channelId: this.channelId
        }, processNode, new EventFactory(this.channelId));
        var ratingElement = r.render(this, false);
        result.push(ratingElement);
        return result;
    };
    RatingDecorator.prototype.shouldRenderRatingFor = function (renderable, parentContainer) {
        if (parentContainer)
            return false;
        if (!RatingDecorator.isRootContainerOfInteraction(renderable))
            return false;
        var child = (renderable.elements || [undefined])[0] || { type: undefined, enabled: undefined };
        return (child.type === "rating" && child.enabled === true)
            || (this.renderStrategy === RatingRenderStrategy.ALL_EXCEPT_DISABLED_RATINGS && child.enabled !== false);
    };
    RatingDecorator.isRootContainerOfInteraction = function (renderable) {
        return renderable["type"] === "container"
            && renderable["position"] === "left"
            && renderable["qualifier"] !== null;
    };
    return RatingDecorator;
}(AbstractDecorator));
export { RatingDecorator };
export var RatingRenderStrategy;
(function (RatingRenderStrategy) {
    RatingRenderStrategy[RatingRenderStrategy["ALL_EXCEPT_DISABLED_RATINGS"] = 0] = "ALL_EXCEPT_DISABLED_RATINGS";
    RatingRenderStrategy[RatingRenderStrategy["ONLY_ENABLED_RATINGS"] = 1] = "ONLY_ENABLED_RATINGS";
})(RatingRenderStrategy || (RatingRenderStrategy = {}));
//# sourceMappingURL=RatingDecorator.js.map