// #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 { getSlotElements } from '../../../../Dom/Slot';
import { Appearanceable } from '../../../Behaviors/Appearanceable';
import { Disableable } from '../../../Behaviors/Disableable';
import { Sizeable } from '../../../Behaviors/Sizeable';
import { Variantable } from '../../../Behaviors/Variantable';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Watch } from '../../../Decorators/WatchDecorator';
import { Appearance } from '../../../Types/Appearance';
import { Size } from '../../../Types/Size';
import { Variant } from '../../../Types/Variant';
import { CustomElement } from '../../Abstracts/CustomElement';
import { AvatarElement } from './AvatarElement';
import { avatarGroupElementTemplate } from './AvatarGroupElementTemplate';
import { avatarGroupElementJoyStyle } from './Themes/AvatarGroupElement.Joy';
import { avatarGroupElementMemphisStyle } from './Themes/AvatarGroupElement.Memphis';
import { avatarGroupElementCosmopolitanStyle } from './Themes/AvatarGroupElement.Cosmopolitan';
import { Themeable } from '../../../Behaviors/Themeable';
// #endregion
/**
 * Avatar Group - A grouping of avatar images typically representing multiple users or entities, often used for social or team displays.
 *
 * @element mosaik-avatar-group
 *
 * @slot - The default slot.
 * @slot overflow - The overflow slot.
 *
 * @public
 */
let AvatarGroupElement = class AvatarGroupElement extends Themeable(Disableable(Sizeable(Variantable(Appearanceable(CustomElement))))) {
    // #region Fields
    _maxLength;
    _overflowLength;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._maxLength = 0;
        this._overflowLength = 0;
    }
    // #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-avatar-group';
    }
    /**
     * Gets or sets the `maxLength` property.
     *
     * @public
     * @attr
     */
    get maxLength() {
        return this._maxLength;
    }
    set maxLength(value) {
        if (this._maxLength !== value) {
            this._maxLength = value;
            this.requestUpdate('maxLength');
        }
    }
    /**
     * Gets a `number` that displays the overflow length of the `AvatarGroupElement`.
     *
     * @protected
     * @readonly
     */
    get overflowLength() {
        return this._overflowLength;
    }
    /**
     * Gets a `boolean` that indecates whether the `AvatarGroupElement` has a overflow or not.
     *
     * @protected
     * @readonly
     */
    get hasOverflow() {
        return this._overflowLength > 0;
    }
    // #endregion
    // #region Methods
    /**
     * @private
     */
    onSlotChange(_event) {
        const items = getSlotElements(this.shadowRoot);
        // set limit display style
        items.forEach((x, i) => {
            x.style.display = i < this._maxLength || this._maxLength === 0 ? '' : 'none';
        });
        // set inherited properties
        items.forEach((x) => {
            x.size = this.size;
            x.disabled = this.disabled;
            x.variant = this.variant;
            x.appearance = this.appearance;
        });
        // TODO: check why this if condition exisits
        if (items) {
            const maxLength = this.maxLength > 0 ? this.maxLength : items.length;
            const numOfChildren = items.length;
            const numToShow = maxLength > 0 && maxLength >= numOfChildren
                ? numOfChildren
                : maxLength;
            this._overflowLength = numToShow < numOfChildren
                ? numOfChildren - maxLength
                : 0;
            this.requestUpdate('overflowLength');
            this.requestUpdate('hasOverflow');
        }
    }
    onSizePropertyChanged(prev, newValue) {
        getSlotElements(this.shadowRoot).forEach((x) => {
            if (newValue) {
                x.size = newValue;
            }
        });
    }
    onDisabledPropertyChanged(prev, newValue) {
        getSlotElements(this.shadowRoot).forEach((x) => {
            if (newValue !== undefined) {
                x.disabled = newValue;
            }
        });
    }
    onVariantPropertyChanged(prev, newValue) {
        getSlotElements(this.shadowRoot).forEach((x) => {
            if (newValue !== undefined) {
                x.variant = newValue;
            }
        });
    }
    onAppearancePropertyChanged(prev, newValue) {
        getSlotElements(this.shadowRoot).forEach((x) => {
            if (newValue !== undefined) {
                x.appearance = newValue;
            }
        });
    }
    onMaxLengthPropertyChanged(prev, newValue) {
        const items = getSlotElements(this.shadowRoot);
        items.forEach((x, i) => {
            x.style.display = i < (newValue ?? 0) || newValue === 0 ? '' : 'none';
        });
        if (items) {
            const maxLength = this.maxLength > 0 ? this.maxLength : items.length;
            const numOfChildren = items.length;
            const numToShow = maxLength > 0 && maxLength >= numOfChildren
                ? numOfChildren
                : maxLength;
            this._overflowLength = numToShow < numOfChildren
                ? numOfChildren - maxLength
                : 0;
            this.requestUpdate('overflowLength');
            this.requestUpdate('hasOverflow');
        }
    }
};
__decorate([
    Attribute({ type: Number }),
    __metadata("design:type", Number),
    __metadata("design:paramtypes", [Number])
], AvatarGroupElement.prototype, "maxLength", null);
__decorate([
    Watch('size', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String]),
    __metadata("design:returntype", void 0)
], AvatarGroupElement.prototype, "onSizePropertyChanged", null);
__decorate([
    Watch('disabled', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Boolean, Boolean]),
    __metadata("design:returntype", void 0)
], AvatarGroupElement.prototype, "onDisabledPropertyChanged", null);
__decorate([
    Watch('variant', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String]),
    __metadata("design:returntype", void 0)
], AvatarGroupElement.prototype, "onVariantPropertyChanged", null);
__decorate([
    Watch('appearance', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String]),
    __metadata("design:returntype", void 0)
], AvatarGroupElement.prototype, "onAppearancePropertyChanged", null);
__decorate([
    Watch('maxLength', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, Number]),
    __metadata("design:returntype", void 0)
], AvatarGroupElement.prototype, "onMaxLengthPropertyChanged", null);
AvatarGroupElement = __decorate([
    Component({
        selector: 'mosaik-avatar-group',
        template: avatarGroupElementTemplate,
        themes: {
            joy: avatarGroupElementJoyStyle,
            memphis: avatarGroupElementMemphisStyle,
            cosmopolitan: avatarGroupElementCosmopolitanStyle
        },
        imports: [AvatarElement]
    }),
    __metadata("design:paramtypes", [])
], AvatarGroupElement);
export { AvatarGroupElement };
//# sourceMappingURL=AvatarGroupElement.js.map