export interface NiftiHeader {
  dims: number[];
  pixDims: number[];
  datatype: number;
  littleEndian: boolean;
  voxOffset: number;
  affine: number[][];
  description: string;
}

export interface NiftiData {
  header: NiftiHeader;
  imageData: any; // vtkImageData
  rawData: ArrayBuffer;
  dimensions: [number, number, number];
  spacing: [number, number, number];
}

export interface NiftiViewerProps {
  file: File | null;
  windowWidth?: number;
  windowLevel?: number;
  opacity?: number;
}

// ---------------------------------------------------------------------------
// Types extracted from the segmentation / organ-mask modules that we did NOT
// port (SegmentationTool, OrganSelector, useOrganMasks). The NIfTI renderer
// references these only as `import type`, and the viewer is wired with those
// features disabled (segmentation needs an /api/medsam2/predict backend; organ
// overlays need a mask source — neither exists in ImageHub yet). Kept here as
// standalone aliases so the render path typechecks without the dropped modules.
// ---------------------------------------------------------------------------
export interface BoundingBox {
  x: number;
  y: number;
  width: number;
  height: number;
  sliceIndex: number;
  viewType: "axial" | "coronal" | "sagittal";
}

export interface SegmentationMask {
  viewType: "axial" | "coronal" | "sagittal";
  sliceIndex: number;
  // Normalized coordinates (0-1) for the mask polygon points
  polygonPoints?: Array<{ x: number; y: number }>;
  // Or a base64-encoded mask image
  maskImageData?: string;
  // Bounding box of the mask (normalized 0-1)
  bounds: { x: number; y: number; width: number; height: number };
  // Confidence score
  confidence?: number;
}

// Originally a union of organ names from OrganSelector; we only consume this
// type (never construct organ masks), so a string alias is sufficient.
export type OrganName = string;

export interface OrganMaskData {
  /** Stable unique id (e.g. the mask file id). The renderer keys overlays by this so two
   *  organs that share a display label don't collapse into one. Falls back to organName. */
  id?: string;
  organName: OrganName;
  imageData: any; // vtkImageData
  color: [number, number, number];
}

// ---------------------------------------------------------------------------
// Client-side annotation model (toolbar tools: bbox / points / pen / brush /
// polygon). Geometry is stored in NORMALIZED [0..1] coordinates within a single
// 2D pane, tagged with that pane's view + slice index so an annotation only
// shows on the slice it was drawn on. `bbox` uses [topLeft, bottomRight];
// the freehand/multi-vertex tools store an ordered list of vertices.
// ---------------------------------------------------------------------------
export type AnnotationTool = 'none' | 'bbox' | 'points' | 'pen' | 'brush' | 'polygon';

export interface AnnotationPoint {
  x: number;
  y: number;
}

export interface Annotation {
  id: string;
  view: 'axial' | 'coronal' | 'sagittal';
  sliceIndex: number;
  tool: Exclude<AnnotationTool, 'none'>;
  points: AnnotationPoint[];
  color: string;
  strokeWidth?: number;
  label?: string;
}
