/**
 * Source item used by the select component.
 */
export type SelectSourceItem = {
	/**
	 * Unique identifier for the item.
	 */
	id: string;
	/**
	 * Display label for the item.
	 */
	displayName: string;
};

/**
 * Label formatter for multiple selected values.
 */
export type SelectedLabelType = (value: string[]) => string;

/**
 * Label formatters for single and multiple selection modes.
 */
export type SelectedLabelTypeForAllModes = {
	/**
	 * Formatter for single selection mode.
	 */
	single?: (value: string, selectedItem?: SelectSourceItem) => string;
	/**
	 * Formatter for multiple selection mode.
	 */
	multiple?: (value: string[], selectedItem?: SelectSourceItem[]) => string;
};

/**
 * Dropdown configuration options for input select.
 */
export type VegaDropdownPropsForSelect = Partial<
	Pick<
		HTMLVegaDropdownElement,
		| 'positionRelativeTo'
		| 'maxHeight'
		| 'matchContainerHeight'
		| 'searchable'
		| 'caseSensitive'
		| 'matchTargetWidth'
		| 'useDefaultFilter'
		| 'size'
		| 'searchTriggerBy'
		| 'isScreenPosition'
		| 'itemDisplayRule'
		| 'resettable'
		| 'preserveValueIfNotInSource'
	>
>;

/**
 * Tooltip configuration for selected label text in input select.
 */
export type VegaInputSelectTooltipProps = Partial<
	Pick<HTMLVegaTooltipElement, 'placement' | 'maxWidth' | 'minWidth'>
>;

/**
 * Tooltip configuration for dropdown items in input select.
 */
export type VegaInputSelectDropdownTooltipProps = Partial<
	Pick<HTMLVegaTooltipElement, 'placement' | 'maxWidth' | 'minWidth'>
>;

/**
 * Size options for the input select component.
 */
export type VegaInputSelectSize = 'default' | 'small';
/**
 * Selection mode for the input select.
 */
export type SelectType = 'single' | 'multiple';
/**
 * Value type derived from selection mode.
 */
export type SelectValueType<T extends SelectType> = T extends 'single' ? string : string[];

/**
 * Lazy-load response structure for select data sources.
 */
export type VegaInputSourceLazyLoadResponse = {
	/**
	 * Whether more items are available to load.
	 */
	hasMore: boolean;
	/**
	 * Newly loaded items.
	 */
	items: SelectSourceItem[];
};

/**
 * Callback used to lazily load input select items.
 */
export type VegaInputSelectSourceLazyLoadCallback = (
	endIndex: number,
) => Promise<VegaInputSourceLazyLoadResponse>;
