// #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 { DomServiceLocator } from '../../../../Dom/Dom';
import { Listen } from '../../../../Events/Decorators/ListenDecorator';
import { Alignable } from '../../../Behaviors/Alignable';
import { Insetable } from '../../../Behaviors/Insetable';
import { ResizeController } from '../../../Controllers/ResizeController';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Watch } from '../../../Decorators/WatchDecorator';
import { CustomElement } from '../../Abstracts/CustomElement';
import { TextElement } from '../../Primitives/Text/TextElement';
import { pageContentElementTemplate } from './PageContentElementTemplate';
import { pageContentElementJoyStyle } from './Themes/PageContentElement.Joy';
import { pageContentElementRetroStyle } from './Themes/PageContentElement.Retro';
import { pageContentElementCosmopolitanStyle } from './Themes/PageContentElement.Cosmopolitan';
import { Themeable } from '../../../Behaviors/Themeable';
import { IntersectionController } from '../../../Controllers/IntersectionController';
// #endregion
/**
 * Page Content - The main content area of a page where the primary information or functionality is presented.
 *
 * @element mosaik-page-content
 *
 * @slot default - The default slot for placing child elements.
 *
 * @public
 */
let PageContentElement = class PageContentElement extends Themeable(Insetable(Alignable(CustomElement))) {
    // #region Fields
    _fullWidthScreenWidth;
    _fullWidth;
    _resizeController;
    _intersectionController;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._fullWidth = false;
        this._fullWidthScreenWidth = window.innerWidth;
        this._resizeController = new ResizeController(this, {
            skipInitial: true,
            callback: () => {
                if (this._fullWidth) {
                    void this.updateComplete.then(() => {
                        this.onResize();
                    });
                }
            }
        });
        this._intersectionController = new IntersectionController(this, {
            skipInitial: true,
            callback: () => {
                if (this._fullWidth) {
                    void this.updateComplete.then(() => {
                        this.onResize();
                    });
                }
            }
        });
    }
    // #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-page-content';
    }
    // #endregion
    // #region Methods
    /**
     * Gets or sets the `fullWidth` property.
     *
     * @public
     * @attr
     */
    get fullWidth() {
        return this._fullWidth;
    }
    set fullWidth(value) {
        if (this._fullWidth !== value) {
            this._fullWidth = value;
            this.requestUpdate('fullWidth');
        }
    }
    // #endregion
    // #region Methods
    /**
     * @protected
     * @override
     */
    onApplyTemplate() {
        super.onApplyTemplate();
        if (this._fullWidth) {
            void this.updateComplete.then(() => {
                this.onResize();
            });
        }
    }
    /**
     * @protected
     */
    onFullWidthPropertyChanged(_prev, next) {
        if (next) {
            void this.updateComplete.then(() => {
                this._resizeController.observe(this);
                this._intersectionController.observe(this);
            });
        }
        else {
            void this.updateComplete.then(() => {
                this._resizeController.unobserve(this);
                this._intersectionController.unobserve(this);
            });
        }
    }
    /**
     * @protected
     */
    onWindowResize() {
        if (this._fullWidth) {
            this.onResize();
        }
    }
    /**
     * @private
     */
    onResize() {
        requestAnimationFrame(() => {
            this._fullWidthScreenWidth = window.innerWidth;
            // TODO: Fix this static selector
            DomServiceLocator.current.findAncestor(this, 'mosaik-page');
            // TODO: Fix this static selector
            const page = DomServiceLocator.current.findAncestor(this, 'mosaik-page', { strict: true });
            const baseMargin = getComputedStyle(page).marginLeft;
            const basePadding = getComputedStyle(page).paddingLeft;
            // Calculate the dynamic values based on screenWidth
            const baseWidth = 1890; // Base width for calculation
            const calculatedWidth = baseWidth + (this._fullWidthScreenWidth - baseWidth);
            // Adjust the properties based on calculations
            this.style.setProperty('--page-content-left', `calc(-1 * (${baseMargin} + ${basePadding}))`);
            this.style.setProperty('--page-content-width', `${calculatedWidth}px`);
            this.style.setProperty('--page-content-max-width', `${calculatedWidth}px`);
            this.style.setProperty('--page-content-padding-left', `calc(${baseMargin} + ${basePadding})`);
            this.style.setProperty('--page-content-padding-right', `calc(${baseMargin} + ${basePadding})`);
        });
    }
};
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], PageContentElement.prototype, "fullWidth", null);
__decorate([
    Watch('fullWidth'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Boolean, Boolean]),
    __metadata("design:returntype", void 0)
], PageContentElement.prototype, "onFullWidthPropertyChanged", null);
__decorate([
    Listen('resize', 'window', { passive: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], PageContentElement.prototype, "onWindowResize", null);
PageContentElement = __decorate([
    Component({
        selector: 'mosaik-page-content',
        template: pageContentElementTemplate,
        themes: {
            joy: pageContentElementJoyStyle,
            retro: pageContentElementRetroStyle,
            cosmopolitan: pageContentElementCosmopolitanStyle
        },
        host: {
            slot: 'content'
        },
        imports: [
            TextElement
        ]
    }),
    __metadata("design:paramtypes", [])
], PageContentElement);
export { PageContentElement };
//# sourceMappingURL=PageContentElement.js.map