/**
 * WorkbookReader - Browser Streaming Workbook Reader
 *
 * This module contains the full shared implementation for the streaming
 * workbook reader and a browser-compatible `WorkbookReader` that buffers
 * waiting worksheets in memory.
 *
 * Node.js uses `workbook-reader.ts`, which extends the same base implementation
 * with filesystem-specific features (filename input + temp-file buffering).
 */
import { EventEmitter, Readable } from "@stream";
import { iterateStream } from "@excel/utils/iterate-stream";
import { StylesXform } from "@excel/xlsx/xform/style/styles-xform";
import type { WorksheetState, Font, WorkbookProperties } from "@excel/types";
import { WorksheetReader } from "@excel/stream/worksheet-reader";
import { HyperlinkReader, type Hyperlink } from "@excel/stream/hyperlink-reader";
export interface InternalWorksheetOptions {
    worksheets?: "emit" | "ignore" | "prep";
    sharedStrings?: "cache" | "emit" | "ignore";
    hyperlinks?: "cache" | "emit" | "ignore";
    styles?: "cache" | "ignore";
    entries?: "emit" | "ignore";
}
export interface SharedStringRichText {
    richText: Array<{
        font: Partial<Font> | null;
        text: string | null;
    }>;
}
export type SharedStringValue = string | SharedStringRichText;
export interface WorkbookRelationship {
    Id: string;
    Target: string;
    Type?: string;
}
export interface SheetMetadata {
    id: number;
    name: string;
    state?: WorksheetState;
    rId: string;
}
export interface WorkbookModel {
    sheets?: SheetMetadata[];
    properties?: Partial<WorkbookProperties>;
    views?: unknown[];
    definedNames?: unknown[];
}
export interface WorkbookPropertiesXform {
    model?: Partial<WorkbookProperties>;
}
export interface EntryPayload {
    type: "shared-strings" | "styles" | "workbook" | "worksheet" | "hyperlinks";
    id?: string;
}
export type ParseEventType = "shared-strings" | "worksheet" | "hyperlinks";
export interface SharedStringEvent {
    eventType: "shared-strings";
    value: {
        index: number;
        text: SharedStringValue;
    };
}
export interface WorksheetReadyEvent<TWorksheetReader> {
    eventType: "worksheet";
    value: TWorksheetReader;
}
export interface HyperlinksEvent<THyperlinkReader> {
    eventType: "hyperlinks";
    value: THyperlinkReader;
}
export type ParseEvent<TWorksheetReader, THyperlinkReader> = SharedStringEvent | WorksheetReadyEvent<TWorksheetReader> | HyperlinksEvent<THyperlinkReader>;
export interface WaitingWorksheetEntry {
    eventType: "waiting-worksheet";
    sheetNo: string;
    entry: any;
}
export type CommonInput = Uint8Array | ArrayBuffer | Readable | ReadableStream<Uint8Array>;
export interface WorkbookReaderOptions {
    worksheets?: "emit" | "ignore";
    sharedStrings?: "cache" | "emit" | "ignore";
    hyperlinks?: "cache" | "emit" | "ignore";
    styles?: "cache" | "ignore";
    entries?: "emit" | "ignore";
}
/** Constructor type for WorksheetReader/HyperlinkReader */
export interface ReaderConstructor<TReader, TWorkbook> {
    new (params: {
        workbook: TWorkbook;
        id: number;
        iterator: AsyncIterable<never>;
        options: InternalWorksheetOptions;
    }): TReader;
}
export declare abstract class WorkbookReaderBase<TInput, TWorksheetReader extends EventEmitter & {
    id?: number | string;
    name?: string;
    state?: WorksheetState;
}, THyperlinkReader extends EventEmitter & {
    hyperlinks?: Record<string, Hyperlink>;
}, TWaitingWorksheet = unknown> extends EventEmitter {
    input: TInput;
    options: {
        worksheets: "emit" | "ignore";
        sharedStrings: "cache" | "emit" | "ignore";
        hyperlinks: "cache" | "emit" | "ignore";
        styles: "cache" | "ignore";
        entries: "emit" | "ignore";
    };
    styles: StylesXform;
    stream?: Readable;
    sharedStrings?: SharedStringValue[];
    workbookRels?: WorkbookRelationship[];
    properties?: WorkbookPropertiesXform;
    model?: WorkbookModel;
    protected _hyperlinkReadersBySheetNo?: Record<string, THyperlinkReader>;
    protected _workbookRelIdByTarget?: Record<string, string>;
    protected _sheetByRelId?: Record<string, SheetMetadata>;
    getHyperlinkReader(sheetNo: number | string): THyperlinkReader | undefined;
    getHyperlink(sheetNo: number | string, rId: string): Hyperlink | undefined;
    getHyperlinkTarget(sheetNo: number | string, rId: string): string | undefined;
    protected WorksheetReaderClass: ReaderConstructor<TWorksheetReader, this>;
    protected HyperlinkReaderClass: ReaderConstructor<THyperlinkReader, this>;
    constructor(input: TInput, options: WorkbookReaderOptions, WorksheetReaderClass: ReaderConstructor<TWorksheetReader, any>, HyperlinkReaderClass: ReaderConstructor<THyperlinkReader, any>);
    _getStream(input: TInput): Readable;
    abstract _storeWaitingWorksheet(sheetNo: string, entry: any): Promise<TWaitingWorksheet>;
    abstract _processWaitingWorksheets(waitingWorksheets: TWaitingWorksheet[]): AsyncIterableIterator<WorksheetReadyEvent<TWorksheetReader>>;
    _cleanupWaitingWorksheets(_waitingWorksheets: TWaitingWorksheet[]): void;
    _createWorksheetReader(params: {
        id: number;
        iterator: AsyncIterable<unknown>;
        options: InternalWorksheetOptions;
    }): TWorksheetReader;
    _createHyperlinkReader(params: {
        id: number;
        iterator: AsyncIterable<unknown>;
        options: InternalWorksheetOptions;
    }): THyperlinkReader;
    read(input?: TInput, options?: WorkbookReaderOptions): Promise<void>;
    [Symbol.asyncIterator](): AsyncIterableIterator<TWorksheetReader>;
    parse(input?: TInput, options?: WorkbookReaderOptions): AsyncIterableIterator<ParseEvent<TWorksheetReader, THyperlinkReader>>;
    _emitEntry(payload: EntryPayload): void;
    _parseRels(entry: Parameters<typeof iterateStream>[0]): Promise<void>;
    _parseWorkbook(entry: Parameters<typeof iterateStream>[0]): Promise<void>;
    _parseSharedStrings(entry: Parameters<typeof iterateStream>[0]): AsyncIterableIterator<{
        index: number;
        text: SharedStringValue;
    }>;
    _parseStyles(entry: Parameters<typeof iterateStream>[0]): Promise<void>;
    _parseWorksheet(iterator: AsyncIterable<unknown>, sheetNo: string): IterableIterator<WorksheetReadyEvent<TWorksheetReader>>;
    protected _parseHyperlinks(iterator: AsyncIterable<unknown>, sheetNo: string): AsyncIterableIterator<HyperlinksEvent<THyperlinkReader>>;
    protected _parseEntries(stream: Readable): AsyncIterableIterator<ParseEvent<TWorksheetReader, THyperlinkReader> | WaitingWorksheetEntry>;
}
export declare const WorkbookReaderOptionsSchema: {
    readonly worksheets: readonly ["emit", "ignore"];
    readonly sharedStrings: readonly ["cache", "emit", "ignore"];
    readonly hyperlinks: readonly ["cache", "emit", "ignore"];
    readonly styles: readonly ["cache", "ignore"];
    readonly entries: readonly ["emit", "ignore"];
};
interface WaitingWorksheet {
    sheetNo: string;
    data: Uint8Array[];
}
declare class WorkbookReader extends WorkbookReaderBase<CommonInput, WorksheetReader, HyperlinkReader, WaitingWorksheet> {
    constructor(input: CommonInput, options?: WorkbookReaderOptions);
    _storeWaitingWorksheet(sheetNo: string, entry: any): Promise<WaitingWorksheet>;
    _processWaitingWorksheets(waitingWorksheets: WaitingWorksheet[]): AsyncIterableIterator<WorksheetReadyEvent<WorksheetReader>>;
}
export { WorkbookReader };
