"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var node_1 = require("../../support/node");
var Renderables_1 = require("../Renderables");
var Overlay_1 = require("../overlays/Overlay");
var Specification_1 = require("../../support/Specification");
/**
 * Implementation of the 'trigger' markup element.
 * A div HTML element is created and the attributes id,
 * name and text from the markup are applied. The class
 * lto-trigger is added to allow CSS manipulations.
 *
 * @see {@link IRenderable}
 * @see {@link Overlay}
 */
var Trigger = /** @class */ (function () {
    function Trigger(spec) {
        this.spec = spec;
    }
    /**
     * @inheritDoc
     */
    Trigger.prototype.render = function (renderer, isNested) {
        var _this = this;
        var trigger = node_1.default("div");
        new Specification_1.Specification(this.spec).initNode(trigger, "lto-trigger");
        trigger.onClick(function () {
            var overlay = _this.getOverlayFromContainer(trigger.getParentByClass("lto-container"));
            if (!overlay) {
                console.error("No overlay with name " + _this.spec.name + " found");
                return;
            }
            Overlay_1.Overlay.show(overlay);
        });
        return trigger.unwrap();
    };
    Trigger.prototype.getOverlayFromContainer = function (container) {
        if (!container)
            return;
        return container.findAll(".lto-overlays .lto-overlay[name=\"" + this.spec.name + "\"]")[0];
    };
    return Trigger;
}());
exports.Trigger = Trigger;
Renderables_1.default.register("trigger", Trigger);
//# sourceMappingURL=index.js.map