// #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 { RendererServiceLocator } from '../../../../Dom/Renderer';
import { Fitable } from '../../../Behaviors/Fitable';
import { Orientable } from '../../../Behaviors/Orientable';
import { Reversible } from '../../../Behaviors/Reversible';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Watch } from '../../../Decorators/WatchDecorator';
import { LayoutElement } from '../Abstracts/LayoutElement';
import { wrapElementTemplate } from './WrapElementTemplate';
import { wrapElementJoyStyle } from './Themes/WrapElement.Joy';
import { wrapElementRetroStyle } from './Themes/WrapElement.Retro';
import { wrapElementCosmopolitanStyle } from './Themes/WrapElement.Cosmopolitan';
import { Themeable } from '../../../Behaviors/Themeable';
import { Gapable } from '../../../Behaviors/Gapable';
// #endregion
/**
 * Wrap - A flexible layout container that automatically wraps child elements to new lines based on available space.
 *
 * @description
 * The Wrap layout component provides a flexible container that automatically wraps child elements to new lines
 * when there's insufficient horizontal space, creating responsive and adaptive layouts. It combines the benefits
 * of flexbox wrapping with configurable gap spacing, orientation control, and reversal options. The component
 * handles dynamic content sizing, maintains consistent spacing between elements, supports both horizontal and
 * vertical orientations, and provides responsive behavior without media queries. Child elements flow naturally
 * within the container, wrapping to new lines as needed. Perfect for tag collections, button groups, card grids,
 * navigation elements, and any interface requiring flexible, space-aware element arrangement.
 *
 * @name Wrap
 * @element mosaik-wrap
 * @category Layouts
 *
 * @slot - The default slot for elements that will wrap based on available space.
 *
 * @cssprop {String} --wrap-gap - The gap between wrapped elements.
 * @cssprop {String} --wrap-columns - The preferred number of columns (if applicable).
 *
 * @example
 * ```html
 * <mosaik-wrap gap="12px">
 *   <mosaik-button>Action 1</mosaik-button>
 *   <mosaik-button>Action 2</mosaik-button>
 *   <mosaik-button>Very Long Action Name</mosaik-button>
 *   <mosaik-button>Action 4</mosaik-button>
 * </mosaik-wrap>
 * ```
 *
 * @example
 * ```html
 * <mosaik-wrap gap="16px" orientation="vertical">
 *   <mosaik-chip>Tag 1</mosaik-chip>
 *   <mosaik-chip>Tag 2</mosaik-chip>
 *   <mosaik-chip>Long Tag Name</mosaik-chip>
 * </mosaik-wrap>
 * ```
 *
 * @public
 */
let WrapElement = class WrapElement extends Themeable(Reversible(Orientable(Fitable(Gapable(LayoutElement))))) {
    // #region Fields
    _columns;
    _reverse;
    // #endregion
    // #region Ctor
    /**
     * Constructs a new instance of the `WrapElement` class.
     *
     * @public
     */
    constructor() {
        super();
        this._columns = 1;
        this._reverse = false;
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     *
     * @public
     * @static
     * @override
     * @readonly
    */
    static get is() {
        return 'mosaik-wrap';
    }
    /**
     * The `columns` property represents the number of columns before wrapping.
     *
     * @public
     */
    get columns() {
        return this._columns;
    }
    set columns(value) {
        if (this._columns !== value) {
            this._columns = value;
            this.requestUpdate('columns');
        }
    }
    // #endregion
    // #region Methods
    /**
     * @protected
     * @override
     */
    onItemsChanged() {
        super.onItemsChanged();
        this.items.forEach((x) => this.renderChild(x));
    }
    /**
     * @protected
     */
    onGapChanged() {
        this.items.forEach((x) => this.renderChild(x));
    }
    /**
     * @protected
     */
    onColumnsChanged() {
        this.items.forEach((x) => this.renderChild(x));
    }
    /**
     * @private
     */
    renderChild(element) {
        RendererServiceLocator.current.setStyle(element, 'flex-basis', 'calc(calc(100% / var(--wrap-columns)) - calc(calc(var(--wrap-gap) * calc(var(--wrap-columns) - 1)) / var(--wrap-columns)))');
        RendererServiceLocator.current.setStyle(element, 'flex-shrink', '1');
        RendererServiceLocator.current.setStyle(element, 'max-width', 'calc(calc(100% / var(--wrap-columns)) - calc(calc(var(--wrap-gap) * calc(var(--wrap-columns) - 1)) / var(--wrap-columns)))');
    }
};
__decorate([
    Attribute({ type: Number }),
    __metadata("design:type", Number),
    __metadata("design:paramtypes", [Number])
], WrapElement.prototype, "columns", null);
__decorate([
    Watch('gap', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], WrapElement.prototype, "onGapChanged", null);
__decorate([
    Watch('columns', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], WrapElement.prototype, "onColumnsChanged", null);
WrapElement = __decorate([
    Component({
        selector: 'mosaik-wrap',
        themes: {
            joy: wrapElementJoyStyle,
            retro: wrapElementRetroStyle,
            cosmopolitan: wrapElementCosmopolitanStyle
        },
        template: wrapElementTemplate
    }),
    __metadata("design:paramtypes", [])
], WrapElement);
export { WrapElement };
//# sourceMappingURL=WrapElement.js.map