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 { ContentCentricRenderer } from './ContentCentricRenderer';
import { Defaults } from '../support/Defaults';
/**
 * Renderer implementation which is based on the reveal.js library.
 * This renderer supports horizontal as well as vertical navigation.
 */
var RevealJsRenderer = /** @class */ (function (_super) {
    __extends(RevealJsRenderer, _super);
    function RevealJsRenderer(options, content, suggest) {
        var _this = _super.call(this, RevealJsRenderer.wrapContent(content), suggest) || this;
        _this.appendContent = function (element) {
            _this.content.appendChild(element);
            if (_this.Reveal) {
                _this.Reveal.sync();
            }
        };
        if (document === undefined) {
            return _this;
        }
        _this.Reveal = require("reveal.js/js/reveal.js");
        _this.Reveal.initialize(options || {
            controls: false,
            progress: false,
            center: true,
            hash: true,
            controlsLayout: 'bottom-right',
            autoSlide: 1,
            transition: 'slide',
        });
        _this.scrollStrategy = function () {
        };
        return _this;
    }
    /**
     * @inheritDoc
     */
    RevealJsRenderer.prototype.render = function (message, containerType) {
        if (message["render"] === undefined) {
            // do not render renderables with position 'right'
            // ***********************************************
            if (message.position === "right") {
                return [];
            }
        }
        return _super.prototype.render.call(this, message, containerType);
    };
    /**
     * @inheritDoc
     */
    RevealJsRenderer.prototype.renderElement = function (renderable, containerType) {
        var elements = _super.prototype.renderElement.call(this, renderable, containerType);
        // wrap renderables with class lto-container into a section element
        // ****************************************************************
        var sections = document.getElementsByTagName("section");
        if (elements[0].classList.contains("lto-container") && !elements[0].outerHTML.includes("lto-transition")) {
            // create section
            console.debug("Reached container section");
            return this.createNewSection(elements, sections);
        }
        else if (elements[0].classList.contains("lto-container") && elements[0].outerHTML.includes("lto-transition")) {
            console.debug("Reached transition check");
            var transition = elements[0].firstElementChild;
            if (transition && transition.getAttribute("wrapped") === "in") {
                console.debug("Reached transition section");
                if (sections.length === 0) {
                    return this.createNewSection(elements, sections);
                }
                var lastSection_1 = sections.item(sections.length - 1);
                if (lastSection_1) {
                    elements.forEach(function (e) { return lastSection_1.appendChild(e); });
                    return [lastSection_1];
                }
            }
            else {
                return this.createNewSection(elements, sections);
            }
        }
        return elements;
    };
    RevealJsRenderer.prototype.createNewSection = function (elements, sections) {
        var section = document.createElement("section");
        elements.forEach(function (e) { return section.appendChild(e); });
        document.querySelectorAll("section.present").forEach(function (e) {
            e.classList.remove("present");
            e.classList.add("past");
        });
        section.classList.add("present");
        return [section];
    };
    RevealJsRenderer.wrapContent = function (content) {
        var slidesDiv = document.createElement("div");
        slidesDiv.classList.add("slides");
        var revealDiv = document.createElement("div");
        revealDiv.classList.add('reveal');
        revealDiv.appendChild(slidesDiv);
        (content || Defaults.content()).appendChild(revealDiv);
        return slidesDiv;
    };
    RevealJsRenderer.prototype.init = function (channelId) {
        _super.prototype.init.call(this, channelId);
    };
    return RevealJsRenderer;
}(ContentCentricRenderer));
export { RevealJsRenderer };
//# sourceMappingURL=RevealJsRenderer.js.map