import { XmlStream } from "../../../utils/xml-stream.js";
import { BaseXform } from "../base-xform.js";
import type { CacheField, DataField, PivotTableSubtotal } from "../../../pivot-table.js";
/**
 * Model for generating pivot table (with live source)
 */
interface PivotTableRenderModel {
    rows: number[];
    columns: number[];
    values: number[];
    pages?: number[];
    metric: PivotTableSubtotal;
    /** Per-value metric overrides (parallel to `values` array). Falls back to `metric`. */
    valueMetrics: PivotTableSubtotal[];
    cacheFields: CacheField[];
    cacheId: string | number;
    tableNumber: number;
    applyWidthHeightFormats: "0" | "1";
}
/**
 * A single <item> element inside a pivotField's <items> collection.
 * Items can reference a shared item index (x attribute) or indicate a subtotal type (t attribute).
 */
interface PivotFieldItem {
    /** Shared item index (maps to cacheField sharedItems) */
    x?: number;
    /** Item type: "default" for subtotals, "sum", "count", "avg", "max", "min", "grand", etc. */
    t?: string;
    /** Hidden flag — "1" means item is filtered out */
    h?: string;
    /** Show details (hide details when "0") */
    sd?: string;
    /** Calculated item flag */
    f?: string;
    /** Missing flag */
    m?: string;
    /** Child items flag */
    c?: string;
    /** Drill across flag */
    d?: string;
}
/**
 * Parsed pivot field
 */
interface ParsedPivotField {
    axis?: "axisRow" | "axisCol" | "axisPage" | "axisValues";
    dataField?: boolean;
    items?: PivotFieldItem[];
    compact?: boolean;
    outline?: boolean;
    showAll?: boolean;
    defaultSubtotal?: boolean;
    numFmtId?: number;
    sortType?: string;
    autoSortScopeXml?: string;
    subtotalTop?: boolean;
    insertBlankRow?: boolean;
    multipleItemSelectionAllowed?: boolean;
    /** Bag of additional attributes not individually modeled (for roundtrip preservation) */
    extraAttrs?: Record<string, string>;
}
/**
 * Parsed page field (report filter)
 */
interface ParsedPageField {
    fld: number;
    item?: number;
    hier?: number;
    name?: string;
}
/**
 * Parsed pivot table model (loaded from file)
 */
interface ParsedPivotTableModel {
    name?: string;
    cacheId: number;
    uid?: string;
    location?: {
        ref: string;
        firstHeaderRow?: number;
        firstDataRow?: number;
        firstDataCol?: number;
        rowPageCount?: number;
        colPageCount?: number;
    };
    pivotFields: ParsedPivotField[];
    rowFields: number[];
    colFields: number[];
    pageFields: ParsedPageField[];
    dataFields: DataField[];
    applyNumberFormats?: string;
    applyBorderFormats?: string;
    applyFontFormats?: string;
    applyPatternFormats?: string;
    applyAlignmentFormats?: string;
    applyWidthHeightFormats?: string;
    dataCaption?: string;
    styleName?: string;
    /** Full pivotTableStyleInfo attributes (preserved on roundtrip) */
    styleInfo?: {
        name?: string;
        showRowHeaders?: string;
        showColHeaders?: string;
        showRowStripes?: string;
        showColStripes?: string;
        showLastColumn?: string;
    };
    updatedVersion?: string;
    minRefreshableVersion?: string;
    createdVersion?: string;
    useAutoFormatting?: string;
    itemPrintTitles?: string;
    indent?: number;
    compact?: boolean;
    compactData?: boolean;
    multipleFieldFilters?: string;
    outline?: boolean;
    outlineData?: boolean;
    chartFormat?: number;
    colGrandTotals?: string;
    rowGrandTotals?: string;
    showError?: string;
    errorCaption?: string;
    showMissing?: string;
    missingCaption?: string;
    grandTotalCaption?: string;
    rowItems?: RowColItem[];
    colItems?: RowColItem[];
    hasColFields?: boolean;
    hasRowItems?: boolean;
    hasColItems?: boolean;
    chartFormats?: ChartFormatItem[];
    extLstXml?: string;
    formatsXml?: string;
    conditionalFormatsXml?: string;
    filtersXml?: string;
    unknownElementsXml?: string;
    isLoaded?: boolean;
}
/**
 * Row or column item in pivot table
 */
interface RowColItem {
    t?: string;
    r?: number;
    i?: number;
    x: Array<{
        v: number;
    }>;
}
/**
 * Chart format item for pivot charts
 */
interface ChartFormatItem {
    chart: number;
    format: number;
    series?: boolean;
    pivotAreaXml?: string;
}
declare class PivotTableXform extends BaseXform<ParsedPivotTableModel | null> {
    private state;
    private currentPivotField;
    private currentRowItem;
    private currentColItem;
    private currentChartFormat;
    private pivotAreaXmlBuffer;
    private autoSortScopeXmlBuffer;
    private extLstCollector;
    private formatsCollector;
    private conditionalFormatsCollector;
    private filtersCollector;
    private unknownCollector;
    private unknownElementsXmlParts;
    constructor();
    get tag(): string;
    reset(): void;
    /**
     * Render pivot table XML.
     * Supports both newly created models and loaded models.
     */
    render(xmlStream: XmlStream, model: PivotTableRenderModel | ParsedPivotTableModel): void;
    /**
     * Render newly created pivot table
     */
    private renderNew;
    /**
     * Render loaded pivot table (preserving original structure)
     */
    private renderLoaded;
    /**
     * Build the root `<pivotTableDefinition>` attributes for a loaded (roundtrip) model.
     * Extracted from renderLoaded to keep the render method focused on element structure.
     */
    private buildLoadedRootAttributes;
    /**
     * Render `<chartFormats>` with preserved pivotArea XML for pivot chart roundtrip.
     */
    private renderChartFormats;
    /**
     * Render a row or column item element
     */
    private renderRowColItem;
    /**
     * Render a loaded pivot field
     */
    private renderPivotFieldLoaded;
    parseOpen(node: any): boolean;
    parseText(text: string): void;
    /** Feed a close-tag to a collector; if it completes, store the result on the model. */
    private tryCloseCollector;
    parseClose(name: string): boolean;
    static readonly PIVOT_TABLE_ATTRIBUTES: {
        xmlns: string;
    };
    static readonly EXTLST_XML: string;
}
export { PivotTableXform, type ParsedPivotTableModel };
