// Centralized type definitions for the PDF viewer
// This file contains all type definitions in one place for easier management

/**
 * PDF.js Library Types
 */
interface PDFDocumentProxy {
  getPage(pageNumber: number): Promise<PDFPageProxy>;
  numPages: number;
  destroy(): void;
}

interface PDFPageProxy {
  getViewport(options: { scale: number }): { width: number; height: number };
  render(options: {
    canvasContext: CanvasRenderingContext2D;
    viewport: any;
    renderQuality?: string;
  }): { promise: Promise<void> };
  cleanup(): void;
}

interface PDFDocumentLoadingTask {
  promise: Promise<PDFDocumentProxy>;
}

/**
 * DOM API Extensions
 */
interface OffscreenCanvas {
  transferToImageBitmap(): ImageBitmap;
}

// Extend Performance interface for non-standard memory API
interface Performance {
  memory?: {
    usedJSHeapSize: number;
    jsHeapSizeLimit: number;
  };
}

/**
 * Window Extensions
 */
interface Window {
  pdfjsLib: any;
  __TAURI__?: {
    invoke(cmd: string, args?: any): Promise<any>;
  };
}

/**
 * Common Utility Types
 */
type DispatchRenderFunction = (
  pageNum: number,
  scale: number,
  vpWidth: number,
  vpHeight: number,
  gen: number,
  quality: number
) => void;

type ZoomCallback = (
  newScale: number,
  bufferSet: Set<number>,
  visibleSet: Set<number>
) => void;

type GetVisibilityState = () => {
  bufferSet: Set<number>;
  visibleSet: Set<number>;
};

/**
 * Annotation Types
 */
interface Quad {
  points: { x: number; y: number }[];
}

interface Annotation {
  id: string;
  page: number;
  quads: Quad[];
  content?: string;
  color?: string;
  type: string;
}

/**
 * Performance Monitoring Types
 */
interface PerformanceStats {
  fps: number;
  avgFrameTime: number;
  renderQuality: number;
  adaptiveMode: boolean;
}

/**
 * Viewport and Geometry Types
 */
interface Viewport {
  width: number;
  height: number;
}

interface BoundingBox {
  x: number;
  y: number;
  width: number;
  height: number;
}

// PDF.js library declaration
declare const pdfjsLib: {
  getDocument(options: { url: string }): PDFDocumentLoadingTask;
  GlobalWorkerOptions: {
    workerSrc: string;
  };
};

export { 
  PDFDocumentProxy, 
  PDFPageProxy, 
  PDFDocumentLoadingTask,
  OffscreenCanvas,
  PerformanceStats,
  Viewport,
  BoundingBox,
  Quad,
  Annotation,
  DispatchRenderFunction,
  ZoomCallback,
  GetVisibilityState
};