﻿// Type definitions for @friedrich.fschr/epub-parser
export interface EpubFile {
  loadChapter(id: string): Promise<EpubProcessedChapter>;
  getFileInfo(): EpubFileInfo;
  getMetadata(): EpubMetadata;
  getManifest(): Record<string, ManifestItem>;
  getSpine(): EpubSpine;
  getGuide(): EpubGuide;
  getCollection(): EpubCollection;
  getToc(): EpubToc;
  getPageList(): PageList;
  getNavList(): NavList;
  resolveHref(href: string): EpubResolvedHref | undefined;
  destroy(): void;
}

export interface EpubProcessedChapter {
  html: string;
  css: EpubCssPart[];
}

export interface EpubCssPart {
  id: string;
  href: string;
}

export interface EpubFileInfo {
  fileName: string;
  mimetype: string;
}

export interface EpubMetadata {
  title: string;
  creator: string;
  subject: string;
  description: string;
  publisher: string;
  contributor: string;
  date: string;
  type: string;
  format: string;
  identifier: string;
  source: string;
  language: string;
  relation: string;
  coverage: string;
  rights: string;
  meta: Record<string, string>[];
}

export interface ManifestItem {
  id: string;
  href: string;
  mediaType: string;
}

export interface EpubGuideReference {
  type: string;
  title: string;
  href: string;
}

export type EpubGuide = EpubGuideReference[];

export interface EpubSpineItem {
  id: string;
  linear: boolean;
}

export type EpubSpine = EpubSpineItem[];

export interface EpubCollection {
  role: string;
  metadata?: Record<string, string>;
  links: { href: string; title?: string }[];
  collections?: EpubCollection[];
}

export interface NavPoint {
  id: string;
  playOrder: string;
  navLabel: string;
  content: {
    id: string;
    src: string;
  };
  children?: NavPoint[];
}

export type EpubToc = NavPoint[];

export interface PageTarget {
  id: string;
  value: string;
  type: string;
  playOrder: string;
  content: {
    id: string;
    src: string;
  };
}

export interface PageList {
  pageTarget: PageTarget[];
}

export interface NavTarget {
  id: string;
  value: string;
  playOrder: string;
  content: {
    id: string;
    src: string;
  };
}

export interface NavList {
  navLabel: string;
  navTarget: NavTarget[];
}

export interface EpubResolvedHref {
  id: string;
  selector: string;
}

export function initEpubFile(
  epubPath: File,
  resourceSaveDir?: string
): Promise<EpubFile>;

export function createFileFromData(
  name: string,
  data: Uint8Array,
  type?: string
): File;

export function loadEpubFromFS(
  filePath: string,
  readFunction: (path: string) => Promise<Uint8Array>
): Promise<File>;

export function getResourceData(
  url: string
): { data: Uint8Array; type: string } | undefined;

export const EPUB_HREF_PREFIX: string;
