import node from "../../support/node";
import Renderables from "../Renderables";
import { Overlay } from "../overlays/Overlay";
/**
 * 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("div");
        trigger.addClasses("lto-trigger");
        trigger.setId(this.spec.id);
        trigger.setName(this.spec.name);
        trigger.innerText(this.spec.text);
        this.spec.class !== undefined ? trigger.addClasses(this.spec.class) : function () { };
        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.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;
}());
export { Trigger };
Renderables.register("trigger", Trigger);
//# sourceMappingURL=index.js.map