// #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 { CustomElement } from '../Controls/Components/Abstracts/CustomElement';
import { Component } from '../Controls/Decorators/ComponentDecorator';
import { DataTemplateRegistry } from './DataTemplates/DataTemplateRegistry';
// #endregion
/**
 * A custom element that registers and deregisters its template children
 * in the TemplateRegistry based on its connection to the DOM.
 *
 * @public
 */
let TemplateSelectorElement = class TemplateSelectorElement extends CustomElement {
    // #region Fields
    _registeredTemplates;
    // #endregion
    // #region Ctor
    /**
     * Constructs a new instance of the `TemplateSelectorElement` class.
     *
     * @public
     */
    constructor() {
        super();
        this._registeredTemplates = new Array();
    }
    // #endregion
    // #region Methods
    /**
     * @public
     * @override
     */
    connectedCallback() {
        super.connectedCallback();
        this.registerTemplates();
    }
    /**
     * @public
     * @override
     */
    disconnectedCallback() {
        super.disconnectedCallback();
        this.deregisterTemplates();
    }
    /**
     * @private
     */
    registerTemplates() {
        this.querySelectorAll('template').forEach((template) => {
            if (template.id) {
                DataTemplateRegistry.instance.registerTemplate(template.id, template);
                this._registeredTemplates.push(template.id);
            }
        });
    }
    /**
     * @private
     */
    deregisterTemplates() {
        this._registeredTemplates.forEach((templateId) => {
            DataTemplateRegistry.instance.removeTemplate(templateId);
        });
        this._registeredTemplates = [];
    }
};
TemplateSelectorElement = __decorate([
    Component({
        selector: 'mosaik-template-selector'
    }),
    __metadata("design:paramtypes", [])
], TemplateSelectorElement);
export { TemplateSelectorElement };
//# sourceMappingURL=TemplateSelectorElement.js.map