// #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 { Themeable } from '../../../Behaviors/Themeable';
import { Variantable } from '../../../Behaviors/Variantable';
import { addInheritanceProviderController } from '../../../Controllers/InheritanceProviderController';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Watch } from '../../../Decorators/WatchDecorator';
import { CustomElement } from '../../Abstracts/CustomElement';
import { AvatarElement } from './AvatarElement';
import { avatarGroupElementTemplate } from './AvatarGroupElementTemplate';
import { AVATAR_GROUP_INHERITANCE_CONTEXT } from './AvatarGroupInheritanceContext';
import { avatarGroupElementCosmopolitanStyle } from './Themes/AvatarGroupElement.Cosmopolitan';
import { avatarGroupElementJoyStyle } from './Themes/AvatarGroupElement.Joy';
import { avatarGroupElementMemphisStyle } from './Themes/AvatarGroupElement.Memphis';
// #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.
 *
 * @csspart overflow - The overflow part.
 *
 * @cssprop {String} --avatar-group-background-color - The group background color CSS custom property.
 * @cssprop {String} --avatar-group-border-color - The group border color CSS custom property.
 * @cssprop {String} --avatar-group-border-radius - The group border radius CSS custom property.
 * @cssprop {String} --avatar-group-border-style - The group border style CSS custom property.
 * @cssprop {String} --avatar-group-border-width - The group border width CSS custom property.
 * @cssprop {String} --avatar-group-font-family - The group font family CSS custom property.
 * @cssprop {String} --avatar-group-font-letter-spacing - The group font letter spacing CSS custom property.
 * @cssprop {String} --avatar-group-font-line-height - The group font line height CSS custom property.
 * @cssprop {String} --avatar-group-font-size - The group font size CSS custom property.
 * @cssprop {String} --avatar-group-font-text-decoration - The group font text decoration CSS custom property.
 * @cssprop {String} --avatar-group-font-text-transform - The group font text transform CSS custom property.
 * @cssprop {String} --avatar-group-font-weight - The group font weight CSS custom property.
 * @cssprop {String} --avatar-group-foreground-color - The group foreground color CSS custom property.
 * @cssprop {String} --avatar-group-gap - The group gap CSS custom property.
 * @cssprop {String} --avatar-group-padding-bottom - The group padding bottom CSS custom property.
 * @cssprop {String} --avatar-group-padding-left - The group padding left CSS custom property.
 * @cssprop {String} --avatar-group-padding-right - The group padding right CSS custom property.
 * @cssprop {String} --avatar-group-padding-top - The group padding top CSS custom property.
 * @cssprop {String} --avatar-group-shadow - The group shadow CSS custom property.
 * @cssprop {String} --avatar-group-shadow-blur - The group shadow blur CSS custom property.
 * @cssprop {String} --avatar-group-shadow-color - The group shadow color CSS custom property.
 * @cssprop {String} --avatar-group-shadow-offset-x - The group shadow offset x CSS custom property.
 * @cssprop {String} --avatar-group-shadow-offset-y - The group shadow offset y CSS custom property.
 * @cssprop {String} --avatar-group-shadow-spread - The group shadow spread CSS custom property.
 * @cssprop {String} --avatar-group-transition-duration - The group transition duration CSS custom property.
 * @cssprop {String} --avatar-group-transition-mode - The group transition mode CSS custom property.
 * @cssprop {String} --avatar-group-transition-property - The group transition property CSS custom property.
 * @cssprop {String} --avatar-group-translate - The group translate CSS custom property.
 *
 * @dependency mosaik-avatar - The Avatar element.
 *
 * @example
 * Basic avatar group:
 * ```html
 * <mosaik-avatar-group>
 *   <mosaik-avatar></mosaik-avatar>
 *   <mosaik-avatar></mosaik-avatar>
 *   <mosaik-avatar></mosaik-avatar>
 * </mosaik-avatar-group>
 * ```
 *
 * @example
 * Avatar group with max visible count and shared appearance:
 * ```html
 * <mosaik-avatar-group max-length="3" size="medium" appearance="soft" variant="primary">
 *   <mosaik-avatar></mosaik-avatar>
 *   <mosaik-avatar></mosaik-avatar>
 *   <mosaik-avatar></mosaik-avatar>
 *   <mosaik-avatar></mosaik-avatar>
 *   <mosaik-avatar></mosaik-avatar>
 * </mosaik-avatar-group>
 * ```
 *
 * @public
 */
let AvatarGroupElement = class AvatarGroupElement extends Themeable(Disableable(Sizeable(Variantable(Appearanceable(CustomElement))))) {
    // #region Fields
    _provider = addInheritanceProviderController(this, {
        context: AVATAR_GROUP_INHERITANCE_CONTEXT,
        values: () => ({
            size: this.size,
            disabled: this.disabled,
            variant: this.variant,
            appearance: this.appearance
        })
    });
    _maxLength;
    _overflowLength;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._maxLength = 0;
        this._overflowLength = 0;
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     * The `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 indicates whether the `AvatarGroupElement` has a overflow or not.
     *
     * @protected
     * @readonly
     */
    get hasOverflow() {
        return this._overflowLength > 0;
    }
    // #endregion
    // #region Methods
    /**
     * Handles slot changes to manage visibility and overflow calculation.
     *
     * @private
     * @param _event - The slot change event.
     */
    onSlotChange(_event) {
        this.updateVisibilityAndOverflow();
    }
    /**
     * Called when maxLength property changes.
     *
     * @protected
     */
    onMaxLengthPropertyChanged() {
        this.updateVisibilityAndOverflow();
    }
    /**
     * Updates the visibility of slotted items based on maxLength and calculates overflow.
     *
     * @private
     */
    updateVisibilityAndOverflow() {
        // TODO: use Slottable mixin here
        const items = getSlotElements(this.shadowRoot);
        const maxLength = this._maxLength > 0 ? this._maxLength : items.length;
        // Set visibility based on maxLength
        items.forEach((x, i) => {
            x.style.display = i < maxLength || this._maxLength === 0 ? '' : 'none';
        });
        // Calculate overflow
        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('maxLength', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __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