// #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 { Property } from '../../../../Decorators/PropertyDecorator';
import { SelectorElement } from '../Selector/SelectorElement';
// #endregion
/**
 * Multi Selector - An abstract foundation for components supporting multiple simultaneous item selections.
 *
 * @description
 * The MultiSelectorElement extends the base SelectorElement to provide multi-selection capabilities,
 * allowing users to select multiple items concurrently from a collection. This element maintains
 * an array of selected items, handles toggle behavior (selecting an already-selected item will
 * deselect it), and emits selection change events for reactive UI updates. It is designed to be
 * extended by concrete implementations such as checkbox lists, multi-select dropdowns, tag pickers,
 * chip selectors, or any component requiring multi-item selection patterns. The element integrates
 * with keyboard navigation and provides comprehensive selection state management.
 *
 * @name Multi Selector
 * @category Selectors
 *
 * @fires selectionChanged {SelectionChangedEvent} - Fired when any item is selected or deselected, providing old and new selected items
 * @fires itemsChanged {ItemsChangedEvent} - Fired when the slotted items collection changes
 * @fires changed {PropertyChangedEvent} - Fired when any property changes
 * @fires connected {ConnectedEvent} - Fired when the element is connected to the DOM
 *
 * @keyhandle Home - Selects or toggles the first item
 * @keyhandle End - Selects or toggles the last item
 *
 * @example
 * Extending for a multi-select list:
 * ```typescript
 * class CheckboxListElement extends MultiSelectorElement<CheckboxItemElement> {
 *   constructor() {
 *     super();
 *     this.selectionChanged.subscribe(({ oldValue, newValue }) => {
 *       console.log('Selection changed:', this.selectedItems);
 *     });
 *   }
 * }
 * ```
 *
 * @example
 * Using multi-selection with custom items:
 * ```html
 * <mosaik-multi-select>
 *   <mosaik-option value="apple">Apple</mosaik-option>
 *   <mosaik-option value="banana">Banana</mosaik-option>
 *   <mosaik-option value="orange">Orange</mosaik-option>
 * </mosaik-multi-select>
 * ```
 *
 * @example
 * Accessing selected items programmatically:
 * ```typescript
 * const multiSelect = document.querySelector('my-multi-selector');
 * multiSelect.select(0); // Select first item
 * multiSelect.select(2); // Select third item (both now selected)
 * console.log(multiSelect.selectedItems); // Array of selected item elements
 * ```
 *
 * @example
 * Listening to selection changes:
 * ```typescript
 * const selector = document.querySelector('my-multi-selector');
 * selector.addEventListener('selectionChanged', (event) => {
 *   const selected = event.target.selectedItems;
 *   console.log(`${selected.length} items selected`);
 *   selected.forEach(item => console.log(item.value));
 * });
 * ```
 *
 * @public
 * @abstract
 */
export class MultiSelectorElement extends SelectorElement {
    // #region Fields
    _selectedItems;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._selectedItems = new Array();
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     * The `is` property represents natural name of this element.
     *
     * @public
     * @static
     * @override
     * @readonly
     */
    static get is() {
        return 'mosaik-MultiSelector';
    }
    /**
     * Gets the first item in the current selection or returns null if the selection is empty.
     *
     * @private
     * @readonly
     */
    get selectedItems() {
        return this._selectedItems;
    }
    // #endregion
    // #region Methods
    /**
     * @protected
     * @override
     */
    onSelectionChanged(oldIndex, newIndex, cb) {
        const item = this.items[newIndex];
        if (item) {
            if (this._selectedItems.includes(item)) {
                this._selectedItems.splice(this._selectedItems.indexOf(item), 1);
            }
            else {
                this._selectedItems.push(item);
            }
            // TODO: prepare display text
            // mybe we can implement formatter method/property for this.
            // same as in avatar element for initals.
            this.requestUpdate('selectedItems');
        }
        super.onSelectionChanged(oldIndex, newIndex, cb);
    }
}
__decorate([
    Property({ type: (Array) }),
    __metadata("design:type", Array),
    __metadata("design:paramtypes", [])
], MultiSelectorElement.prototype, "selectedItems", null);
//# sourceMappingURL=MultiSelectorElement.js.map