import { ForgeAiDropdownMenuItemComponent } from './ai-dropdown-menu-item.js'; export type DropdownMenuSelectionMode = 'none' | 'single' | 'multi'; /** * Base interface for dropdown menu selection change events */ export interface BaseDropdownChangeEventDetail { selectionMode: DropdownMenuSelectionMode; timestamp: number; } /** * Event detail for 'none' selection mode (actions only) */ export interface ActionEventDetail extends BaseDropdownChangeEventDetail { selectionMode: 'none'; value: string; selectedItem: ForgeAiDropdownMenuItemComponent; } /** * Event detail for 'single' selection mode */ export interface SingleSelectionEventDetail extends BaseDropdownChangeEventDetail { selectionMode: 'single'; value: string | null; selectedItem: ForgeAiDropdownMenuItemComponent | null; previousValue?: string | null; } /** * Event detail for 'multi' selection mode */ export interface MultiSelectionEventDetail extends BaseDropdownChangeEventDetail { selectionMode: 'multi'; value: string[]; selectedItem: ForgeAiDropdownMenuItemComponent[]; addedItems?: ForgeAiDropdownMenuItemComponent[]; removedItems?: ForgeAiDropdownMenuItemComponent[]; } /** * Union type for all dropdown change event details */ export type DropdownChangeEventDetail = ActionEventDetail | SingleSelectionEventDetail | MultiSelectionEventDetail; /** * Configuration options for selection behavior */ export interface SelectionConfig { mode: DropdownMenuSelectionMode; closeOnSingleSelect?: boolean; showSelectionCount?: boolean; } /** * Manages selection state and behavior for dropdown menus. * * The SelectionManager is responsible for handling all aspects of item selection * within dropdown menus, supporting three distinct modes: * * - **none**: Items act as actions only, no persistent selection state * - **single**: Single selection with radio button behavior * - **multi**: Multiple selection with checkbox behavior * * It provides type-safe event dispatching with mode-specific event details * and maintains consistent selection state across all menu items. * * @example * ```typescript * const manager = new SelectionManager( * () => getAllMenuItems(), * (detail) => handleSelectionChange(detail), * { mode: 'single', closeOnSingleSelect: true } * ); * * // Handle item selection * const result = manager.selectItem(menuItem); * if (result.shouldClose) { * closeDropdown(); * } * ``` */ export declare class SelectionManager { private _getMenuItems; private _onSelectionChange; private _value; private _config; constructor(_getMenuItems: () => ForgeAiDropdownMenuItemComponent[], _onSelectionChange: (detail: DropdownChangeEventDetail) => void, config: SelectionConfig); /** * Gets the current selection value */ get value(): string | string[] | null; /** * Sets the selection value and updates item states */ set value(newValue: string | string[] | null); /** * Gets the current selection mode */ get selectionMode(): DropdownMenuSelectionMode; /** * Updates the selection mode and reconfigures items */ set selectionMode(mode: DropdownMenuSelectionMode); /** * Updates the selection configuration */ updateConfig(config: Partial): void; /** * Handles item selection based on the current mode */ selectItem(item: ForgeAiDropdownMenuItemComponent): { shouldClose: boolean; }; /** * Gets the currently selected items */ getSelectedItems(): ForgeAiDropdownMenuItemComponent[]; /** * Gets text representation of the current selection */ getSelectedText(): string; /** * Checks if selection text should be displayed */ shouldShowSelectedText(): boolean; /** * Updates the selection state of all menu items */ private _updateItemSelectionState; /** * Handles action-only selection (no state change) */ private _handleActionSelection; /** * Handles single selection mode */ private _handleSingleSelection; /** * Handles multi-selection mode */ private _handleMultiSelection; /** * Gets the selected values as an array */ private _getSelectedValuesArray; /** * Resets the selection state */ reset(): void; }