// #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 { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { CustomElement } from '../../Abstracts/CustomElement';
import { viewElementTemplate } from './RegionViewElementTemplate';
import { Themeable } from '../../../Behaviors/Themeable';
import { regionViewElementCosmopolitanStyle } from './Themes/RegionViewElement.Cosmopolitan';
import { regionViewElementJoyStyle } from './Themes/RegionViewElement.Joy';
import { regionViewElementMemphisStyle } from './Themes/RegionViewElement.Memphis';
// #endregion
/**
 * View - A view definition component for use within a Region.
 *
 * Acts as a template container that stores its content for lazy instantiation.
 * The view's children are not instantiated until the view becomes active within its parent region.
 * This enables efficient memory usage and clean lifecycle management for complex view hierarchies.
 *
 * @name ViewElement
 * @element mosaik-region-view
 * @category Grouping
 *
 * @slot default - The content to be rendered when this view becomes active
 *
 * @example
 * ```html
 * <mosaik-region active="home">
 *   <mosaik-region-view name="home" default>
 *     <my-home-component></my-home-component>
 *   </mosaik-region-view>
 *   <mosaik-region-view name="profile">
 *     <my-profile-component></my-profile-component>
 *   </mosaik-region-view>
 * </mosaik-region>
 * ```
 *
 * @public
 */
let RegionViewElement = class RegionViewElement extends Themeable(CustomElement) {
    // #region Fields
    _name;
    _default;
    _template;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._name = '';
        this._default = false;
        this._template = null;
    }
    // #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-region';
    }
    /**
     * The unique name identifier for this view within a region.
     *
     * @public
     */
    get name() {
        return this._name;
    }
    set name(value) {
        this._name = value;
    }
    /**
     * Whether this view is the default active view in the region.
     *
     * @public
     */
    get default() {
        return this._default;
    }
    set default(value) {
        this._default = value;
    }
    // #endregion
    // #region Methods
    /**
     * @public
     * @override
     */
    firstUpdated(changedProperties) {
        super.firstUpdated(changedProperties);
        // Capture content after Lit has rendered and slotted the children
        if (!this._template) {
            this.captureContentAsTemplate();
        }
    }
    /**
     * Gets the template containing the view's content.
     *
     * @returns The template element or null if not yet captured
     * @public
     */
    getTemplate() {
        return this._template;
    }
    /**
     * Captures the light DOM children as a template and removes them from the DOM.
     * This prevents custom elements from being instantiated until the view is activated.
     *
     * @private
     */
    captureContentAsTemplate() {
        if (!this.name) {
            console.warn('mosaik-region-view requires a unique name attribute', this);
            return;
        }
        // Get the slot element from shadow DOM
        const slot = this.shadowRoot?.querySelector('slot');
        if (!slot) {
            return;
        }
        // Get the assigned nodes from the slot
        const assignedNodes = slot.assignedNodes({ flatten: true });
        if (assignedNodes.length === 0) {
            return;
        }
        // Create template element to store the content
        this._template = document.createElement('template');
        // Move all assigned nodes into the template
        assignedNodes.forEach((node) => {
            if (this._template) {
                this._template.content.appendChild(node);
            }
        });
    }
};
__decorate([
    Attribute({
        type: String,
        useDefault: true
    }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], RegionViewElement.prototype, "name", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], RegionViewElement.prototype, "default", null);
RegionViewElement = __decorate([
    Component({
        selector: 'mosaik-region-view',
        template: viewElementTemplate,
        themes: {
            joy: regionViewElementJoyStyle,
            memphis: regionViewElementMemphisStyle,
            cosmopolitan: regionViewElementCosmopolitanStyle
        }
    }),
    __metadata("design:paramtypes", [])
], RegionViewElement);
export { RegionViewElement };
//# sourceMappingURL=RegionViewElement.js.map