/**
 * XLSX - Abstract base class for XLSX operations
 *
 * Contains all platform-agnostic logic shared between Node.js and Browser versions:
 * - reconcile: Reconcile model after parsing
 * - _process*Entry: Process individual ZIP entries
 * - add*: Add content to ZIP during writing
 * - prepareModel: Prepare model for writing
 * - loadFromFiles: Load from pre-extracted ZIP data
 */
import type { PivotTableSubtotal } from "../pivot-table.js";
import { type IEventEmitter } from "../../stream/index.js";
import type { Workbook } from "../workbook.js";
import type { ZipTimestampMode } from "../../archive/utils/timestamps.js";
type StreamListener = Parameters<IEventEmitter["on"]>[1];
interface EmitterLike {
    on(event: string, listener: StreamListener): this;
    once(event: string, listener: StreamListener): this;
    off(event: string, listener: StreamListener): this;
}
export interface IParseStream extends EmitterLike {
    pipe(dest: any): any;
    [Symbol.asyncIterator]?: () => AsyncIterator<Uint8Array | string>;
}
export interface IStreamBuf extends EmitterLike {
    write(data: any): void;
    end(): void;
    read(): any;
    toBuffer?(): any;
    pipe?(dest: any): any;
}
export interface IZipWriter extends EmitterLike {
    append(data: any, options: {
        name: string;
        base64?: boolean;
    }): void;
    pipe(stream: any): void;
    finalize(): void;
}
export interface XlsxReadOptions {
    base64?: boolean;
    [key: string]: unknown;
}
export interface ZipWriterOptions {
    level?: number;
    /** ZIP entry modification time (optional). If omitted, defaults to current time. */
    modTime?: Date;
    /** Timestamp writing strategy for ZIP entry metadata (optional). */
    timestamps?: ZipTimestampMode;
}
export interface XlsxWriteOptions {
    zip?: ZipWriterOptions;
    [key: string]: unknown;
}
export type XlsxOptions = XlsxReadOptions & XlsxWriteOptions;
export interface WorkbookMediaLike {
    type: string;
    extension: string;
    name?: string;
    filename?: string;
    buffer?: Uint8Array;
    base64?: string;
}
export interface MediaModel {
    media: WorkbookMediaLike[];
}
interface ZipEntryLike {
    name: string;
    type: "Directory" | "File";
    stream: IParseStream;
    drain: () => Promise<void>;
}
/**
 * XLSX class - handles Excel file operations
 * Works in both Node.js and Browser environments
 */
declare class XLSX {
    workbook: Workbook;
    static RelType: {
        OfficeDocument: string;
        Worksheet: string;
        CalcChain: string;
        SharedStrings: string;
        Styles: string;
        Theme: string;
        Hyperlink: string;
        Image: string;
        CoreProperties: string;
        ExtenderProperties: string;
        Comments: string;
        VmlDrawing: string;
        Table: string;
        PivotCacheDefinition: string;
        PivotCacheRecords: string;
        PivotTable: string;
        FeaturePropertyBag: string;
        CtrlProp: string;
    };
    constructor(workbook: Workbook);
    /**
     * Create a stream from binary data (for media/themes)
     */
    protected createBinaryStream(data: Uint8Array): IParseStream;
    /**
     * Create a stream from string content (for XML parsing)
     */
    protected createTextStream(content: string): IParseStream;
    /**
     * Create a StreamBuf instance for buffering data
     */
    protected createStreamBuf(): IStreamBuf;
    /**
     * Convert buffer/Uint8Array to string
     */
    protected bufferToString(data: string | ArrayBuffer | Uint8Array): string;
    /**
     * Create a ZIP writer adapter.
     * Can be overridden by subclasses for platform-specific implementations.
     */
    protected createZipWriter(options?: XlsxWriteOptions["zip"]): IZipWriter;
    /**
     * Write all workbook content to a ZIP writer
     * Shared by both Node.js write() and browser writeBuffer()
     */
    protected writeToZip(zip: IZipWriter, options?: XlsxWriteOptions): Promise<void>;
    /**
     * Read workbook from a stream
     */
    read(stream: IParseStream, options?: XlsxReadOptions): Promise<any>;
    /**
     * Write workbook to a stream
     */
    write(stream: any, options?: XlsxWriteOptions): Promise<XLSX>;
    /**
     * Load workbook from buffer/ArrayBuffer/Uint8Array
     */
    load(data: any, options?: XlsxReadOptions): Promise<any>;
    /**
     * Internal: Load from Uint8Array buffer
     */
    protected loadBuffer(buffer: Uint8Array, options?: XlsxReadOptions): Promise<any>;
    /**
     * Internal: Load workbook from an async stream of ZIP entries.
     *
     * This is the foundation for TRUE streaming reads on platforms that have a
     * streaming ZIP parser (e.g. Node.js `modules/archive` Parse).
     */
    /**
     * Create an empty model for parsing XLSX files.
     * Shared by loadFromZipEntries and loadFromFiles.
     */
    private createEmptyModel;
    /**
     * Collect all data from a stream into a single Uint8Array.
     * Reusable helper for passthrough and drawing processing.
     */
    protected collectStreamData(stream: IParseStream): Promise<Uint8Array>;
    /**
     * Check if a drawing has chart references in its relationships
     */
    private drawingHasChartReference;
    /**
     * Check if a drawing rels list references charts.
     * Used to decide whether we need to keep raw drawing XML for passthrough.
     */
    private drawingRelsHasChartReference;
    /**
     * Process a known OOXML entry (workbook, styles, shared strings, etc.)
     * Returns true if handled, false if should be passed to _processDefaultEntry
     */
    protected _processKnownEntry(stream: IParseStream, model: any, entryName: string, options?: XlsxOptions): Promise<boolean>;
    protected loadFromZipEntries(entries: AsyncIterable<ZipEntryLike>, options?: XlsxOptions): Promise<any>;
    /**
     * Write workbook to buffer
     */
    writeBuffer(options?: XlsxWriteOptions): Promise<Uint8Array>;
    /**
     * Add media files to ZIP
     * Supports buffer, base64, and filename (if readFileAsync is provided)
     */
    addMedia(zip: IZipWriter, model: MediaModel): Promise<void>;
    /**
     * Optional file reader - can be overridden by subclasses (e.g., Node.js version)
     */
    protected readFileAsync?: (filename: string) => Promise<Uint8Array>;
    parseRels(stream: IParseStream): Promise<any>;
    parseWorkbook(stream: IParseStream): Promise<any>;
    parseSharedStrings(stream: IParseStream): Promise<any>;
    reconcile(model: any, options?: XlsxOptions): void;
    /**
     * Reconcile pivot tables by linking them to worksheets and their cache data.
     */
    protected _reconcilePivotTables(model: any): void;
    protected _extractTableNumber(name: string): number;
    protected _buildCacheIdMap(model: any): Map<string, number>;
    protected _buildDefinitionToCacheIdMap(model: any): Map<string, number>;
    protected _determineMetric(dataFields: Array<{
        subtotal?: string;
    }>): PivotTableSubtotal;
    protected _determineValueMetrics(dataFields: Array<{
        subtotal?: string;
    }>, defaultMetric: PivotTableSubtotal): PivotTableSubtotal[];
    _processWorksheetEntry(stream: IParseStream, model: any, sheetNo: number, options: XlsxOptions | undefined, path: string): Promise<void>;
    _processCommentEntry(stream: IParseStream, model: any, name: string): Promise<void>;
    _processTableEntry(stream: IParseStream, model: any, name: string): Promise<void>;
    _processWorksheetRelsEntry(stream: IParseStream, model: any, sheetNo: number): Promise<void>;
    _processMediaEntry(stream: IParseStream, model: any, filename: string): Promise<void>;
    /**
     * Process a drawing XML entry.
     *
     * @param stream - Stream to read from (used in loadFromZipEntries path)
     * @param model - Model to populate
     * @param name - Drawing name (e.g., "drawing1")
     * @param rawData - Pre-read raw data (used in loadFromFiles path to avoid re-reading stream)
     */
    _processDrawingEntry(stream: IParseStream, model: any, name: string, rawData?: Uint8Array): Promise<void>;
    _processDrawingRelsEntry(entry: any, model: any, name: string): Promise<void>;
    _processVmlDrawingEntry(entry: any, model: any, name: string): Promise<void>;
    _processThemeEntry(stream: IParseStream, model: any, name: string): Promise<void>;
    _processPivotTableEntry(stream: IParseStream, model: any, name: string): Promise<void>;
    _processPivotTableRelsEntry(stream: IParseStream, model: any, name: string): Promise<void>;
    _processPivotCacheDefinitionEntry(stream: IParseStream, model: any, name: string): Promise<void>;
    _processPivotCacheRecordsEntry(stream: IParseStream, model: any, name: string): Promise<void>;
    loadFromFiles(zipData: Record<string, Uint8Array>, options?: any): Promise<any>;
    /**
     * Process default entries (drawings, comments, tables, etc.)
     * @param rawData Optional raw entry data for passthrough preservation (used by loadFromFiles)
     */
    protected _processDefaultEntry(stream: IParseStream, model: any, entryName: string, rawData?: Uint8Array): Promise<boolean>;
    /**
     * Store a passthrough file for preservation during read/write cycles.
     * These files are not parsed but stored as raw bytes to be written back unchanged.
     */
    _processPassthroughEntry(stream: IParseStream, model: any, entryName: string): Promise<void>;
    addContentTypes(zip: IZipWriter, model: any): Promise<void>;
    addApp(zip: IZipWriter, model: any): Promise<void>;
    addCore(zip: IZipWriter, model: any): Promise<void>;
    addThemes(zip: IZipWriter, model: any): Promise<void>;
    addOfficeRels(zip: IZipWriter, _model: any): Promise<void>;
    addWorkbookRels(zip: IZipWriter, model: any): Promise<void>;
    addFeaturePropertyBag(zip: IZipWriter, model: any): Promise<void>;
    addSharedStrings(zip: IZipWriter, model: any): Promise<void>;
    addStyles(zip: IZipWriter, model: any): Promise<void>;
    addWorkbook(zip: IZipWriter, model: any): Promise<void>;
    addWorksheets(zip: IZipWriter, model: any): Promise<void>;
    addDrawings(zip: IZipWriter, model: any): void;
    addTables(zip: IZipWriter, model: any): void;
    /**
     * Write passthrough files (charts, etc.) that were preserved during read.
     * These files are written back unchanged to preserve unsupported features.
     */
    addPassthrough(zip: IZipWriter, model: any): void;
    addPivotTables(zip: IZipWriter, model: any): void;
    _finalize(zip: IZipWriter): Promise<this>;
    prepareModel(model: any, options: any): void;
}
export { XLSX };
