export declare interface AggregateExportConfig {
    groupByColumns: GroupByField[];
    pivotSchema: PivotColumnSchema[];
    rowAggregates?: RowAggregate[];
    includeSubtotals: boolean;
    includeGrandTotal: boolean;
}

export declare interface AggregateRowData extends Record<string, unknown> {
    isSubtotal?: boolean;
    isGrandTotal?: boolean;
    subtotalLevel?: string;
    subtotalContext?: {
        groupByValues?: Record<string, unknown>;
    };
    aggregate?: string;
}

/**
 * Convert a 2D array to CSV string
 */
export declare function arrayToCSV(rows: (string | number | null | undefined)[][], options?: Partial<CSVExportOptions>): string;

/**
 * Convert an array of values to a CSV row
 */
export declare function arrayToCSVRow(values: (string | number | null | undefined)[], delimiter?: string): string;

export declare interface ColorRange {
    min: number;
    max: number;
    color: string;
    applyTo: 'cell' | 'row';
}

export declare interface ColumnHeaderNode {
    name: string;
    level: number;
    colspan: number;
    children?: ColumnHeaderNode[];
    columnKey?: string;
}

export declare interface ColumnSettings {
    type: 'none' | 'text' | 'number' | 'date' | 'badge' | 'link' | 'progress';
    textAlign?: 'left' | 'center' | 'right';
    width?: number;
    numberFormat?: {
        style: 'decimal' | 'currency' | 'percent' | 'scientific';
        currency: string;
        locale: string;
        minimumFractionDigits: number;
        maximumFractionDigits: number;
        useGrouping?: boolean;
        percentValueMode?: 'fraction' | 'whole';
        showDataBar?: boolean;
        dataBarColor?: string;
        dataBarMinValue?: number;
        dataBarMaxValue?: number;
    };
    dateFormat?: {
        format: string;
        useCustomFormat: boolean;
        customFormat: string;
        useRelativeTime: boolean;
        timezone?: string;
        sourceTimezone?: string;
    };
    linkFormat?: {
        urlTemplate: string;
        labelType: 'value' | 'static' | 'column';
        staticLabel?: string;
        labelColumn?: string;
        openInNewTab: boolean;
    };
    colorRanges?: ColorRange[];
}

export declare type ColumnSettingsMap = Record<string, ColumnSettings>;

export declare interface ColumnSubtotalMeta {
    columnKey: string;
    label: string;
    level: number;
}

export declare interface CSVExportOptions {
    delimiter: ',' | ';' | '\t';
    includeHeaders: boolean;
    lineEnding: '\n' | '\r\n';
}

export declare interface DateFormatOptions {
    /** date-fns format pattern (e.g., "MM/dd/yyyy") */
    format: string;
    /** Use custom format instead of preset */
    useCustomFormat?: boolean;
    /** Custom format pattern */
    customFormat?: string;
    /** Display timezone (e.g., "America/New_York") */
    timezone?: string;
    /** How to interpret source dates: 'auto' | 'UTC' | specific timezone */
    sourceTimezone?: string;
    /** Use relative time (e.g., "2 days ago") */
    useRelativeTime?: boolean;
    /** Locale for date formatting */
    locale?: string;
}

export declare type DurationDisplayStyle = 'compact' | 'digital' | 'long';

export declare interface DurationFormatOptions {
    /** Unit represented by the raw numeric value. */
    inputUnit?: DurationUnit;
    /** Display style, e.g. "6min 32s", "06:32", or "6 minutes 32 seconds". */
    outputStyle?: DurationDisplayStyle;
    /** Largest unit to show. Defaults to day. */
    largestUnit?: DurationUnit;
    /** Smallest unit to show. Defaults to second. */
    smallestUnit?: DurationUnit;
    /** Maximum non-zero unit parts to show for compact/long output. */
    maxUnits?: number;
    /** Add prefix string before the formatted duration. */
    prefix?: string;
    /** Add suffix string after the formatted duration. */
    suffix?: string;
    /** Show negative durations in parentheses instead of a minus sign. */
    negativeInParentheses?: boolean;
}

export declare type DurationUnit = 'millisecond' | 'second' | 'minute' | 'hour' | 'day';

/**
 * Escape a value for CSV output (RFC 4180 compliant)
 * Wraps in quotes if value contains delimiter, quotes, or newlines
 */
export declare function escapeCSVValue(value: string | number | null | undefined, delimiter?: string): string;

export declare interface ExportFormattingConfig {
    /** Whether to apply formatting or export raw values */
    useFormattedValues: boolean;
    /** Context timezone for date formatting (calendarContext) */
    timezone: string;
    /** Viewer/browser timezone for SQL card defaults */
    browserTimezone?: string;
    /** Whether the export is for a raw SQL card */
    isSqlCard?: boolean;
    /** Locale for number/date formatting */
    locale: string;
    /** CSV delimiter */
    delimiter: ',' | ';' | '\t';
    /** Include header row */
    includeHeaders: boolean;
    /** Per-column formatting settings */
    columnSettings: ColumnSettingsMap;
    /** Ordered list of columns to include */
    visibleColumns: string[];
}

/**
 * Format an aggregate table row for CSV export
 */
export declare function formatAggregateRow(row: AggregateRowData, aggregateConfig: AggregateExportConfig, formattingConfig: ExportFormattingConfig): string[];

/**
 * Format aggregate table data for CSV export
 */
export declare function formatAggregateTableForCSV(data: AggregateRowData[], aggregateConfig: AggregateExportConfig, formattingConfig: ExportFormattingConfig): string[];

/**
 * Format a cell value for export based on column settings
 * This is the main entry point for formatting individual cells
 */
export declare function formatCellValue(value: unknown, columnSettings: ColumnSettings | undefined, config: {
    useFormattedValues: boolean;
    timezone: string;
    locale: string;
    browserTimezone?: string;
    isSqlCard?: boolean;
}): string;

/**
 * Format a number as currency
 */
export declare function formatCurrency(value: number | null | undefined, options?: NumberFormatOptions): string;

/**
 * Format a date with custom format and optional timezone
 * This is the production implementation used by data-table and pivot-table.
 *
 * @param dateString - The date string to format
 * @param formatPattern - The format pattern (e.g., 'MM/dd/yyyy', 'yyyy-MM-dd HH:mm')
 *   Defaults to MM/dd/yyyy when missing or empty.
 * @param displayTimezone - Optional timezone to display the date in (e.g., 'America/Chicago')
 * @param sourceTimezone - How to interpret the input date (default: 'auto')
 * @returns Formatted date string
 *
 * @example
 * // Basic formatting
 * formatDate('2024-01-15T10:30:00Z', 'MM/dd/yyyy') // '01/15/2024'
 *
 * // With display timezone
 * formatDate('2024-01-15T10:30:00Z', 'MM/dd/yyyy HH:mm', 'America/Chicago') // '01/15/2024 04:30'
 */
export declare const formatDate: (dateString: string | null | undefined, formatPattern: string | undefined, displayTimezone?: string, sourceTimezone?: string) => string;

export declare function formatDuration(value: number | string | null | undefined, options?: DurationFormatOptions): string;

/**
 * Format a number with locale-aware formatting
 */
export declare function formatNumber(value: number | null | undefined, options?: NumberFormatOptions): string;

/**
 * Legacy wrapper for backward compatibility with existing code
 * @deprecated Use formatNumber, formatCurrency, or formatPercent directly
 */
export declare function formatNumberCustom(value: number, type: 'number' | 'currency' | 'percent' | 'scientific', options?: FormatOptions): string;

/**
 * Format a number value based on ColumnSettings.numberFormat
 * Used for export formatting
 */
export declare function formatNumberWithColumnSettings(value: number | null | undefined, numberFormat: {
    style?: 'decimal' | 'currency' | 'percent' | 'scientific';
    currency?: string;
    locale?: string;
    minimumFractionDigits?: number;
    maximumFractionDigits?: number;
    useGrouping?: boolean;
    percentValueMode?: 'fraction' | 'whole';
} | undefined, defaultLocale?: string): string;

export declare interface FormatOptions {
    decimalPlaces?: number;
    useSuffix?: boolean;
    currency?: string;
    locale?: string;
    prefix?: string;
    suffix?: string;
    negativeInParentheses?: boolean;
    multiplyBy?: number;
}

/**
 * Format a number as percentage
 * Note: Intl.NumberFormat percent style multiplies by 100, so we may need to divide
 */
export declare function formatPercent(value: number | null | undefined, options?: NumberFormatOptions & {
    alreadyPercent?: boolean;
}): string;

/**
 * Format a pivot table data row for CSV export
 */
export declare function formatPivotDataRow(row: PivotRowData, pivotConfig: PivotExportConfig, formattingConfig: ExportFormattingConfig): string[];

/**
 * Format pivot table data for CSV export
 */
export declare function formatPivotTableForCSV(data: PivotRowData[], pivotConfig: PivotExportConfig, formattingConfig: ExportFormattingConfig): string[];

/**
 * Format relative time using date-fns (e.g., "2 days ago")
 *
 * @param dateString - The date string to format
 * @param sourceTimezone - How to interpret the input date (default: 'auto')
 * @returns Relative time string
 */
export declare const formatRelativeTime: (dateString: string | null | undefined, sourceTimezone?: string) => string;

/**
 * Format a row of data for export
 * Returns values in the order specified by visibleColumns
 */
export declare function formatRowForExport(row: Record<string, unknown>, config: ExportFormattingConfig): string[];

/**
 * Format a number in scientific notation
 */
export declare function formatScientific(value: number | null | undefined, options?: NumberFormatOptions): string;

/**
 * Format table data for CSV export
 * Returns array of CSV rows (strings)
 */
export declare function formatTableForCSV(data: Record<string, unknown>[], config: ExportFormattingConfig): string[];

/**
 * Generate headers for aggregate table export
 */
export declare function generateAggregateHeaders(aggregateConfig: AggregateExportConfig): string[];

/**
 * Generate multi-level headers for pivot table
 */
export declare function generatePivotHeaders(config: PivotExportConfig): string[][];

/**
 * Generate complete CSV content for a table
 */
export declare function generateTableCSV(data: Record<string, unknown>[], config: ExportFormattingConfig, lineEnding?: '\n' | '\r\n'): string;

/**
 * Get timezone abbreviation (e.g., "EST", "PST")
 */
export declare function getTimezoneAbbreviation(timezone: string, date?: Date): string;

/**
 * Get friendly timezone name (e.g., "Eastern Time")
 */
export declare function getTimezoneName(timezone: string): string;

export declare interface GroupByField {
    name: string;
    alias: string;
    label?: string;
}

/**
 * Shared format types for export system
 * IMPORTANT: No React imports allowed in this file
 *
 * These types are used by:
 * - react-semaphor (browser) for client-side exports
 * - semaphor-app (Next.js) for API routes
 * - Lambda (Node.js) for async export processing
 */
export declare interface NumberFormatOptions {
    style: 'decimal' | 'currency' | 'percent' | 'scientific';
    locale?: string;
    currency?: string;
    minimumFractionDigits?: number;
    maximumFractionDigits?: number;
    useGrouping?: boolean;
    percentValueMode?: 'fraction' | 'whole';
    /** Multiply value before formatting (e.g., 100 for percent) */
    multiplyBy?: number;
    /** Add prefix string (e.g., "$") */
    prefix?: string;
    /** Add suffix string (e.g., " USD") */
    suffix?: string;
    /** Show negative numbers in parentheses instead of minus sign */
    negativeInParentheses?: boolean;
    /** Use magnitude suffixes (K, M, B) */
    useSuffix?: boolean;
}

/**
 * Convert an array of objects to CSV string
 */
export declare function objectsToCSV(data: Record<string, unknown>[], options?: Partial<CSVExportOptions> & {
    columns?: string[];
}): string;

/**
 * Parse a date string with source timezone interpretation
 *
 * @param dateString - The date string to parse
 * @param sourceTimezone - How to interpret the date:
 *   - 'auto': If date has Z/offset, use it; otherwise assume UTC
 *   - 'UTC': Always interpret as UTC
 *   - specific TZ: Use explicit timezone if present, otherwise assume source TZ
 */
export declare function parseWithSourceTimezone(dateString: string, sourceTimezone?: string): Date;

export declare interface PivotByColumn {
    name: string;
    alias: string;
    label?: string;
}

export declare interface PivotCellData {
    value: unknown;
    formatted?: string;
}

export declare interface PivotColumnSchema {
    alias: string;
    displayLabel?: string;
    metricLabel?: string;
    metricName?: string;
    isMetricColumn: boolean;
}

export declare interface PivotExportConfig {
    groupByColumns: GroupByField[];
    pivotByColumns: PivotByColumn[];
    columnHeadersTree: ColumnHeaderNode[];
    columnHeaders: string[];
    columnSubtotalMeta?: ColumnSubtotalMeta[];
    includeSubtotals: boolean;
    includeGrandTotal: boolean;
    showRowTotals: boolean;
}

export declare interface PivotRowData {
    fieldValues: string[];
    cells: Record<string, PivotCellData>;
    isSubtotal?: boolean;
    isGrandTotal?: boolean;
}

/**
 * Date formatting utilities with timezone support
 * IMPORTANT: No React imports allowed in this file
 *
 * Uses date-fns and date-fns-tz for consistent behavior in browser and Node.js
 *
 * This module provides the canonical date formatting functions used by:
 * - data-table component
 * - pivot-table component
 * - aggregated-table component
 * - Lambda CSV export (chunk-processor)
 */
/**
 * Resolve which timezone to use for formatting
 * Priority: column-specific > context timezone
 */
export declare function resolveTimezone(columnTimezone: string | undefined, contextTimezone: string): string;

export declare interface RowAggregate {
    function: 'SUM' | 'COUNT' | 'AVG' | 'MIN' | 'MAX';
    groupLevel?: string;
    label?: string;
}

export { }
