/* eslint-disable @typescript-eslint/no-explicit-any */
// #region Imports
/**
 * Reference to a drop list group.
 * Manages automatic connection of multiple drop lists.
 *
 * @public
 */
export class DropListGroupRef {
    // #region Fields
    _dropLists;
    _disabled;
    // #endregion
    // #region Ctor
    /**
     * Create a new DropListGroupRef.
     *
     * @param config - Configuration options.
     */
    constructor(config) {
        console.log('[DropListGroupRef] Constructor', { config });
        this._dropLists = new Set();
        this._disabled = config?.disabled ?? false;
    }
    // #endregion
    // #region Properties
    /**
     * Get whether the group is disabled.
     *
     * @public
     */
    get disabled() {
        return this._disabled;
    }
    /**
     * Set whether the group is disabled.
     *
     * @public
     */
    set disabled(value) {
        if (this._disabled !== value) {
            console.log('[DropListGroupRef] Disabled changed', { from: this._disabled, to: value });
            this._disabled = value;
            this._updateConnections();
        }
    }
    /**
     * Get all registered drop lists.
     *
     * @public
     */
    get dropLists() {
        return this._dropLists;
    }
    // #endregion
    // #region Methods
    /**
     * Register a drop list with this group.
     *
     * @param dropList - Drop list to register.
     *
     * @public
     */
    registerDropList(dropList) {
        if (!this._dropLists.has(dropList)) {
            console.log('[DropListGroupRef] Registering drop list', { dropList, count: this._dropLists.size + 1 });
            this._dropLists.add(dropList);
            this._updateConnections();
        }
    }
    /**
     * Unregister a drop list from this group.
     *
     * @param dropList - Drop list to unregister.
     *
     * @public
     */
    unregisterDropList(dropList) {
        if (this._dropLists.has(dropList)) {
            console.log('[DropListGroupRef] Unregistering drop list', { dropList, remaining: this._dropLists.size - 1 });
            this._dropLists.delete(dropList);
            this._updateConnections();
        }
    }
    /**
     * Dispose of the group and clean up.
     *
     * @public
     */
    dispose() {
        console.log('[DropListGroupRef] Disposing', { count: this._dropLists.size });
        this._dropLists.clear();
    }
    // #endregion
    // #region Private Methods
    /**
     * Update connections between all drop lists.
     * Each list will be connected to all other lists in the group.
     *
     * @private
     */
    _updateConnections() {
        console.log(`[DropListGroupRef] Updating connections`, {
            listCount: this._dropLists.size,
            disabled: this._disabled
        });
        if (this._disabled) {
            // Clear all connections
            this._dropLists.forEach((list) => {
                list.connectTo([]);
            });
            console.log('[DropListGroupRef] Cleared all connections (group disabled)');
            return;
        }
        // Connect each list to all others
        this._dropLists.forEach((currentList) => {
            const otherLists = Array.from(this._dropLists).filter((list) => list !== currentList);
            currentList.connectTo(otherLists);
            console.log(`[DropListGroupRef] Connected list to ${otherLists.length} other lists`);
        });
    }
}
// #endregion
// #region Factory
/**
 * Create a new DropListGroupRef.
 *
 * @param config - Configuration options.
 * @returns New DropListGroupRef instance.
 *
 * @public
 */
export function createDropListGroupRef(config) {
    return new DropListGroupRef(config);
}
// #endregion
//# sourceMappingURL=DropListGroupRef.js.map