import type { Table } from "./table.js";
/**
 * Interface representing the source data abstraction for pivot tables.
 * This allows both Worksheet and Table to be used as pivot table data sources.
 */
export interface PivotTableSource {
    /** Name of the worksheet containing the source data (used in pivotCacheDefinition) */
    name: string;
    /** Get row values by 1-indexed row number */
    getRow(rowNumber: number): {
        values: any[];
    };
    /** Get column values by 1-indexed column number */
    getColumn(columnNumber: number): {
        values: any[];
    };
    /** Get all sheet values as a sparse 2D array */
    getSheetValues(): any[][];
    /** Dimensions with short range reference (e.g., "A1:E10") */
    dimensions: {
        shortRange: string;
    };
}
/**
 * Model for creating a new pivot table.
 * Pass this to worksheet.addPivotTable() to create a pivot table.
 */
export interface PivotTableModel {
    /**
     * Source worksheet for the pivot table data.
     * Either sourceSheet or sourceTable must be provided (mutually exclusive).
     */
    sourceSheet?: PivotTableSource;
    /**
     * Source table for the pivot table data.
     * Either sourceSheet or sourceTable must be provided (mutually exclusive).
     * The table must have headerRow=true and contain at least one data row.
     */
    sourceTable?: Table;
    /** Column names to use as row fields in the pivot table */
    rows: string[];
    /**
     * Column names to use as column fields in the pivot table.
     * If omitted or empty, Excel will use "Values" as the column field.
     * @default []
     */
    columns?: string[];
    /** Column names to aggregate as values in the pivot table */
    values: string[];
    /**
     * Aggregation metric for the pivot table values.
     * - 'sum': Sum of values (default)
     * - 'count': Count of values
     * @default 'sum'
     */
    metric?: "sum" | "count";
    /**
     * Controls whether pivot table style overrides worksheet column widths.
     * - '0': Preserve worksheet column widths (useful for custom sizing)
     * - '1': Apply pivot table style width/height (default Excel behavior)
     * @default '1'
     */
    applyWidthHeightFormats?: "0" | "1";
}
/**
 * Represents a cache field in a pivot table.
 * Cache fields store unique values from source columns for row/column grouping.
 */
export interface CacheField {
    /** Name of the field (column header from source) */
    name: string;
    /** Unique values for row/column fields, null for value fields */
    sharedItems: any[] | null;
    /** Minimum value for numeric fields */
    minValue?: number;
    /** Maximum value for numeric fields */
    maxValue?: number;
}
/** Aggregation function types for pivot table data fields */
export type PivotTableSubtotal = "sum" | "count" | "average" | "max" | "min" | "product" | "countNums" | "stdDev" | "stdDevP" | "var" | "varP";
/**
 * Data field configuration for pivot table aggregation.
 * Defines how values are aggregated in the pivot table.
 */
export interface DataField {
    /** Display name for the data field (e.g., "Sum of Sales") */
    name: string;
    /** Index of the source field in cacheFields */
    fld: number;
    /** Base field index for calculated fields */
    baseField?: number;
    /** Base item index for calculated fields */
    baseItem?: number;
    /** Aggregation function (default: 'sum') */
    subtotal?: PivotTableSubtotal;
}
/**
 * Internal pivot table representation used by the library.
 * This is the processed model after calling makePivotTable().
 */
export interface PivotTable {
    /** Source data adapter (always present for new pivot tables) */
    source?: PivotTableSource;
    /** Field indices for row fields */
    rows: number[];
    /** Field indices for column fields */
    columns: number[];
    /** Field indices for value fields */
    values: number[];
    /** Aggregation metric */
    metric: "sum" | "count";
    /** Cache fields with shared items */
    cacheFields: CacheField[];
    /** Cache ID for linking to pivot cache */
    cacheId: string;
    /** Width/height format setting */
    applyWidthHeightFormats: "0" | "1";
    /** 1-indexed table number for file naming (pivotTable1.xml, pivotTable2.xml, etc.) */
    tableNumber: number;
    /** Flag indicating this pivot table was loaded from file (not newly created) */
    isLoaded?: boolean;
    /** Data fields for loaded pivot tables */
    dataFields?: DataField[];
    /** Cache definition for loaded pivot tables */
    cacheDefinition?: ParsedCacheDefinition;
    /** Cache records for loaded pivot tables */
    cacheRecords?: ParsedCacheRecords;
}
/**
 * Parsed cache definition from loaded pivot table files.
 */
export interface ParsedCacheDefinition {
    sourceRef?: string;
    sourceSheet?: string;
    cacheFields: CacheField[];
    recordCount?: number;
    rId?: string;
    isLoaded?: boolean;
}
/**
 * Parsed cache records from loaded pivot table files.
 */
export interface ParsedCacheRecords {
    records: Array<Array<{
        type: string;
        value?: any;
    }>>;
    count: number;
    isLoaded?: boolean;
}
declare function makePivotTable(worksheet: any, model: PivotTableModel): PivotTable;
export { makePivotTable };
