import { InjectionToken, ModelSignal, Signal } from '@angular/core';
import type { DropdownOptionComponent } from './dropdown-option.component';

/**
 * Interface representing the parent dropdown component.
 * Used to avoid circular dependency with DropdownButtonComponent.
 */
export interface DropdownHost<T> {
  value: ModelSignal<T | null>;
  filter: ModelSignal<string>;
  select: (option: DropdownOptionComponent<T>) => void;
  selectActiveItem: () => void;
  options: Signal<readonly DropdownOptionComponent<T>[]>;
  close: () => void;
  onKeydown: (event: KeyboardEvent) => void;
  equals: Signal<(a: T | null, b: T | null) => boolean>;
}

/**
 * Injection token for the parent dropdown component.
 * The actual DropdownButtonComponent provides itself using this token.
 */
export const DROPDOWN_HOST = new InjectionToken<DropdownHost<unknown>>(
  'DropdownButtonComponent',
);
