import { FrameRenderable, FrameState } from "../preview/FrameController.js";
import { EFFramegen } from "../EF_FRAMEGEN.js";
import { EFMedia } from "./EFMedia.js";
import { RenderToVideoOptions } from "../preview/renderTimegroupToVideo.types.js";
import * as lit3 from "lit";
import { PropertyValueMap } from "lit";
import { VideoSample } from "mediabunny";
import * as lit_html3 from "lit-html";
import * as lit_html_directives_ref0 from "lit-html/directives/ref";

//#region src/elements/EFVideo.d.ts
declare global {
  var EF_FRAMEGEN: EFFramegen;
}
interface LoadingState {
  isLoading: boolean;
  operation: "scrub-segment" | "video-segment" | "seeking" | "decoding" | null;
  message: string;
}
/**
 * Event detail for scrub segment loading progress.
 * Dispatched during prefetchScrubSegments to indicate network activity.
 */

declare class VideoSeekTask {
  #private;
  value: VideoSample | undefined;
  task: ((...args: any[]) => any) | undefined;
  taskComplete: Promise<VideoSample | undefined>;
  begin(): void;
  complete(sample: VideoSample | undefined): void;
  abort(): void;
}
declare const EFVideo_base: typeof EFMedia;
declare class EFVideo extends EFVideo_base implements FrameRenderable {
  #private;
  static styles: lit3.CSSResult[];
  canvasRef: lit_html_directives_ref0.Ref<HTMLCanvasElement>;
  unifiedVideoSeekTask: VideoSeekTask;
  /**
   * Get the current rendition being displayed.
   * @public
   */
  get currentRenditionId(): "main" | "scrub" | undefined;
  /**
   * Query readiness state for a given time.
   * @implements FrameRenderable
   *
   * Note: The timeMs parameter is the root timegroup's time. We check against
   * this.currentSourceTimeMs since that's what we cache in prepareFrame.
   */
  getFrameState(_timeMs: number): FrameState;
  /**
   * Async preparation - seeks video and caches the sample.
   * @implements FrameRenderable
   *
   * Note: The timeMs parameter is the root timegroup's time. We ignore it and
   * use this.currentSourceTimeMs instead, which accounts for:
   * - Our position within the parent timegroup (ownCurrentTimeMs)
   * - Source trimming (sourceIn/sourceOut or trimStart/trimEnd)
   */
  prepareFrame(_timeMs: number, signal: AbortSignal): Promise<void>;
  /**
   * Synchronous render - paints cached video sample to canvas.
   * @implements FrameRenderable
   *
   * Note: The timeMs parameter is the root timegroup's time. We use
   * this.currentSourceTimeMs to match what prepareFrame cached.
   */
  renderFrame(_timeMs: number): void;
  /**
   * Loading state for user feedback
   */
  loadingState: {
    isLoading: boolean;
    operation: LoadingState["operation"];
    message: string;
  };
  constructor();
  protected updated(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
  render(): lit_html3.TemplateResult<1>;
  get canvasElement(): HTMLCanvasElement | undefined;
  /**
   * Start a delayed loading operation for testing
   */
  startDelayedLoading(operationId: string, message: string, options?: {
    background?: boolean;
  }): void;
  /**
   * Clear a delayed loading operation for testing
   */
  clearDelayedLoading(operationId: string): void;
  /**
   * Set loading state for user feedback
   */
  private setLoadingState;
  /**
   * Paint the current video frame to canvas
   */
  paint(seekToMs: number, parentSpan?: any): void;
  /**
   * Clear the canvas when element becomes inactive
   */
  clearCanvas(): void;
  /**
   * Display a video frame on the canvas
   */
  displayFrame(frame: VideoFrame, seekToMs: number, parentSpan?: any): void;
  /**
   * Check if we're in production rendering mode (EF_FRAMEGEN active) vs preview mode
   */
  private isInProductionRenderingMode;
  /**
   * Check if EF_FRAMEGEN has explicitly started frame rendering (not just initialization)
   */
  private isFrameRenderingActive;
  /**
   * Get a decoded VideoFrame at a specific source media timestamp.
   * Returns a standard WebCodecs VideoFrame — caller MUST call .close() when done.
   *
   * Uses the same routing logic as the unified video system:
   * - "auto": main track for production rendering, follows normal routing otherwise
   * - "scrub": force low-res scrub track (for thumbnails)
   * - "main": force full-quality main track
   *
   * @param sourceTimeMs - Timestamp in source media coordinates (not timeline)
   * @param options - Quality and abort signal
   * @returns VideoFrame that the caller must close()
   * @public
   */
  getVideoFrameAtSourceTime(sourceTimeMs: number, options?: {
    quality?: "auto" | "scrub" | "main";
    signal?: AbortSignal;
  }): Promise<VideoFrame>;
  /**
   * Capture a video frame directly at a source media timestamp.
   * Designed for export/rendering.
   * Does NOT paint to the element's internal canvas.
   *
   * Uses the same routing logic as unified video system:
   * - "auto": main track for production rendering, follows normal routing otherwise
   * - "scrub": force low-res scrub track (for thumbnails)
   * - "main": force full-quality main track
   *
   * @param sourceTimeMs - Timestamp in source media coordinates (not timeline)
   * @param options - Capture options including quality and abort signal
   * @returns Frame data for serialization
   * @public
   */
  captureFrameAtSourceTime(sourceTimeMs: number, options?: {
    quality?: "auto" | "scrub" | "main";
    signal?: AbortSignal;
  }): Promise<{
    dataUrl: string;
    width: number;
    height: number;
  }>;
  /**
   * Pre-fetch scrub segments for given timestamps.
   * Loads 30-second segments sequentially, emitting progress events.
   * This ensures scrub track is cached for fast thumbnail generation.
   *
   * @param timestamps - Array of timestamps (in ms) that will be captured
   * @param onProgress - Optional callback for loading progress
   * @param signal - Optional AbortSignal for cancellation
   * @returns Promise that resolves when all segments are cached
   * @public
   */
  prefetchScrubSegments(timestamps: number[], onProgress?: (loaded: number, total: number, segmentTimeRange: [number, number]) => void, signal?: AbortSignal): Promise<void>;
  /**
   * Clean up resources when component is disconnected
   */
  disconnectedCallback(): void;
  didBecomeRoot(): void;
  didBecomeChild(): void;
  /**
   * Get the natural dimensions of the video (coded width and height).
   * Returns null if the video hasn't loaded yet or canvas isn't available.
   *
   * @public
   */
  getNaturalDimensions(): {
    width: number;
    height: number;
  } | null;
  /**
   * Render this video element to an MP4 using the direct video-to-video fast path.
   * Bypasses DOM serialization — decodes frames directly and re-encodes to MP4.
   * Respects trim, CSS filter, and opacity.
   *
   * @param options - Rendering options (fps, codec, bitrate, etc.)
   * @returns Promise resolving to video buffer (if returnBuffer), or undefined
   * @public
   */
  renderToVideo(options?: RenderToVideoOptions): Promise<Uint8Array | undefined>;
}
declare global {
  interface HTMLElementTagNameMap {
    "ef-video": EFVideo;
  }
}
//#endregion
export { EFVideo };
//# sourceMappingURL=EFVideo.d.ts.map