/**
 * `<stream-ui>` — Renders an AsyncIterable<string> as streaming text. Used for LLM output and real-time logs.
 *
 * @see https://ui-kit.exe.xyz/site/components/stream
 *
 * Type declarations generated by scripts/build/dts-codegen.mjs from
 * the component's `.a2ui.json` sidecar(s). Edit the source `.yaml`,
 * run `npm run build:components`, then `npm run codegen:dts` to
 * regenerate; or hand-author this file fully if rich event types are
 * needed beyond what the yaml `events:` block can express.
 */

import { UIElement } from '../../core/element.js';

export type StreamEndEvent = CustomEvent<unknown>;
export interface StreamErrorEventDetail {
  /** Error object or message. */
  error: Record<string, unknown>;
}

export type StreamErrorEvent = CustomEvent<StreamErrorEventDetail>;
export type StreamStartEvent = CustomEvent<unknown>;

export class UIStream extends UIElement {
  /** Milliseconds between character renders. 0 = real-time. */
  pace: number;
  /** Read-only reflected state, true while stream is active */
  streaming: boolean;

  addEventListener<K extends keyof HTMLElementEventMap>(
    type: K,
    listener: (this: UIStream, ev: HTMLElementEventMap[K]) => unknown,
    options?: boolean | AddEventListenerOptions,
  ): void;
  addEventListener(type: 'stream-end', listener: (ev: StreamEndEvent) => unknown, options?: boolean | AddEventListenerOptions): void;
  addEventListener(type: 'stream-error', listener: (ev: StreamErrorEvent) => unknown, options?: boolean | AddEventListenerOptions): void;
  addEventListener(type: 'stream-start', listener: (ev: StreamStartEvent) => unknown, options?: boolean | AddEventListenerOptions): void;
}
