// #region Imports
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { MutationController } from '../../../Controllers/MutationController';
import { Component } from '../../../Decorators/ComponentDecorator';
import { CustomElement } from '../../Abstracts/CustomElement';
import { HelmetServiceLocator } from './Helmet';
// #endregion
/**
 * The `{@link HelmetElement}` element.
 *
 * @public
 */
let HelmetElement = class HelmetElement extends CustomElement {
    // #region Fields
    _mutationController;
    _elements;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._elements = new Array();
        this._mutationController = new MutationController(this, {
            config: {
                childList: true,
                subtree: true
            },
            callback: () => {
                // this.backupAndReplaceElements();
                // Array.from(this.children).forEach(child => {
                //     const tag = child.tagName.toLowerCase() as unknown as keyof KnownHelmetTagNameMap;
                //     HelmetServiceLocator.current.set(tag, child as any);
                // });
            }
        });
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `{@link is}` property.
     * The `{@link is}` property represents natural name of this element.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-helmet';
    }
    // #endregion
    // #region Methods
    /**
     * @public
     * @override
     */
    connectedCallback() {
        super.connectedCallback();
        HelmetServiceLocator.current.changes.subscribe(() => {
            // override default again...
            this.appendDocument();
        });
        this.appendDocument();
    }
    /**
     * @public
     * @override
     */
    disconnectedCallback() {
        this.clearDocument();
        super.disconnectedCallback();
    }
    /**
     * @protected
     * @overload
     */
    createRenderRoot() {
        // we do not want to create a shadow DOM for this element
        return this;
    }
    /**
     * @private
     */
    appendDocument() {
        Array.from(this.children).forEach((child) => {
            const tag = child.tagName.toLowerCase();
            const element = HelmetServiceLocator.current.set(tag, child);
            this._elements.push(element);
        });
    }
    /**
     * @private
     */
    clearDocument() {
        this._elements.forEach((child) => {
            const tag = child.tagName.toLowerCase();
            HelmetServiceLocator.current.remove(tag, child);
        });
        this._elements.splice(0, this._elements.length);
    }
};
HelmetElement = __decorate([
    Component({
        selector: 'mosaik-helmet',
        imports: []
    }),
    __metadata("design:paramtypes", [])
], HelmetElement);
export { HelmetElement };
//# sourceMappingURL=HelmetElement.js.map