/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { IgEvent } from "./IgEvent";
import { shadowWrap } from "./igc-html-element";
export class IgcComponentRendererContainerComponent {
    constructor() {
        this.extraSlotNames = [];
        this.extraSlotNamesMap = new Set();
        this.shadowMode = false;
        this.childContentMode = false;
        this.listeners = [];
        this._currentRoot = null;
    }
    static fromElement(ele) {
        if (ele.$$container) {
            return ele.$$container;
        }
        let c = new IgcComponentRendererContainerComponent();
        c.element = ele;
        if (ele.hasAttribute("shadow-dom-mode")) {
            let shadowRoot = shadowWrap(ele).attachShadow({ mode: "open" });
            c.element = shadowRoot;
            c.shadowMode = true;
        }
        if (ele.hasAttribute("child-content-mode")) {
            c.childContentMode = true;
            c.collectExtraSlots(ele);
        }
        ele.$$container = c;
        return c;
    }
    collectExtraSlots(ele) {
        for (var i = 0; i < ele.children.length; i++) {
            let child = ele.children[i];
            if (child.hasAttribute("slot")) {
                if (!this.extraSlotNamesMap.has(child.getAttribute("slot"))) {
                    this.extraSlotNames.push(child.getAttribute("slot"));
                    this.extraSlotNamesMap.add(child.getAttribute("slot"));
                }
            }
        }
    }
    ensureExtraSlots(ele) {
        let exist = new Set();
        for (var i = 0; i < ele.children.length; i++) {
            if (ele.children[i].tagName == "SLOT") {
                if (ele.hasAttribute("name")) {
                    exist.add(ele.getAttribute("name"));
                }
            }
        }
        for (var i = 0; i < this.extraSlotNames.length; i++) {
            if (!exist.has(this.extraSlotNames[i])) {
                let s = document.createElement("slot");
                s.setAttribute("name", this.extraSlotNames[i]);
                ele.append(s);
            }
        }
    }
    replaceRootItem(t, continueActions) {
        for (let i = this.element.children.length - 1; i >= 0; i--) {
            this.element.children[i].remove();
        }
        let C = t;
        if (C.htmlTagName) {
            t = document.createElement(t.htmlTagName);
        }
        else {
            t = new C();
        }
        this._currentRoot = t;
        this.element.appendChild(this._currentRoot);
        this._currentRoot.width = "100%";
        this._currentRoot.height = "100%";
        if (this.childContentMode) {
            let slot = document.createElement("slot");
            this._currentRoot.appendChild(slot);
            this.ensureExtraSlots(this._currentRoot);
        }
        continueActions(false);
    }
    clearContainer(continueActions) {
        for (let i = this.element.children.length - 1; i >= 0; i--) {
            this.element.children[i].remove();
        }
        continueActions(false);
    }
    getRootObject() {
        return this._currentRoot;
    }
    static isEvent(obj) {
        return obj instanceof IgEvent;
    }
}
//# sourceMappingURL=igc-component-renderer-container-component.js.map
