import type { AgEvent } from 'ag-stack';
import type { NamedBean } from '../context/bean';
import { BeanStub } from '../context/beanStub';
import type { AgColumn } from '../entities/agColumn';
import type { AgProvidedColumnGroup } from '../entities/agProvidedColumnGroup';
import type { ColDef, ColGroupDef, ColKey } from '../entities/colDef';
import type { GridOptions } from '../entities/gridOptions';
import type { ColumnEventType } from '../events';
import type { PropertyChangedEvent, PropertyValueChangedEvent } from '../gridOptionsService';
/** What a {@link ColumnModel.stageColChanges} call must do: `'dispatch'` only dispatches the staged service changes;
 *  `'membership'` (a role add/remove/set) rebuilds, animates and raises the legacy `columnEverythingChanged`;
 *  `'reorder'` (a same-set move) rebuilds and animates, but keeps the set so skips the legacy event. */
type ColChangeKind = 'dispatch' | 'membership' | 'reorder';
/** A column or provided column group whose events a column update queues. */
export interface QueuedEventOwner {
    /** Its last entry in the queue, or a stale index into an emptied one; never negative, to read in bounds. */
    lastQueuedEventAt: number;
    raiseQueuedEvent(event: AgEvent<string>): void;
}
/** @internal AG_GRID_INTERNAL - Not for public use. Can change / be removed at any time. */
export declare class ColumnModel extends BeanStub implements NamedBean {
    beanName: "colModel";
    pivotMode: boolean;
    ready: boolean;
    /** Suppresses row model refreshes during batch column state dispatching. */
    changeEventsDispatching: boolean;
    showingPivotResult: boolean;
    /** Set when a staged change needs a display rebuild; consumed (cleared) once by {@link performRefresh}. */
    private pendingRefresh;
    /** A `buildFromColDefs` inside an enclosing update already raised `columnEverythingChanged`; stops that update's
     *  flush re-raising it. */
    private everythingChangedInUpdate;
    /** Accumulated across an update: a change that must raise the legacy `columnEverythingChanged` (anything but a lone reorder). */
    private pendingRaiseEverything;
    /** The source of the first change staged in an update, which its flush reports. */
    private pendingChangesSource;
    colsList: AgColumn[];
    colsTree: (AgColumn | AgProvidedColumnGroup)[];
    colsTreeDepth: number;
    colDefList: AgColumn[];
    /** Invalidation key for anything memoised off the colDefs. Mutating a live colDef in place doesn't register. */
    colDefsVersion: number;
    /** >0 between {@link beginColUpdate} and {@link endColUpdate}, queueing the column events raised and deferring the
     *  role changes staged. */
    colUpdateDepth: number;
    /** Each queued column or group, its event and the index of its previous entry (`-1` for none): nothing allocated
     *  per event. */
    private readonly queuedColEvents;
    /** While the queue is raised, the index past the event being raised, so a change to an owner already told queues
     *  anew. */
    private colEventsRaisingAt;
    colDefTree: (AgColumn | AgProvidedColumnGroup)[];
    colDefTreeDepth: number;
    private colDefHasMarryChildren;
    hasMarryChildren: boolean;
    /** Single source of truth for `getCol`. Pivot result colIds are namespaced (`pivot_…`). */
    colsById: {
        [id: string]: AgColumn;
    };
    colDefGroupsById: Map<string, AgProvidedColumnGroup>;
    /** Primary cols keyed by colId / userProvidedColDef ref / field; passed back for next-build reuse. */
    private colDefColsByKey;
    /** Every primary group (padding + non-padding) — sweep uses this to find orphans whose parent's
     *  `.children` was reassigned. */
    private colDefAllGroups;
    /** Non-padding displayed groups by `groupId`. Pivot mode = pivot's groups; else = colDefGroupsById. */
    colsGroupsById: Map<string, AgProvidedColumnGroup>;
    /** Every displayed group — padding groups carry `displayInstances` */
    colsAllGroups: AgProvidedColumnGroup[];
    /**
     * User-edited group header names keyed by `groupId` — the single source of truth shared by every
     * provided-group instance (header, columns tool panel, column chooser). Persisted in grid state.
     */
    groupHeaderNameOverrides: Map<string, string>;
    /** Lazy fallback for ColDef-shaped keys not in `colsById`: by-ref (merged + user colDef) plus
     *  `field` when distinct from colId (first-write-wins). */
    private cachedColsByDef;
    private cachedAllCols;
    /** Cache for getColsInStateOrder (pivot only). Invalidated on `colsList` mutation — ref equality
     *  can't substitute, as `moveColumns` reorders in place. */
    private cachedColsInStateOrder;
    /** Prior display order per mode, as colId snapshots, so the next refresh can restore user moves. */
    private lastOrder;
    private lastPivotOrder;
    /** True when `lastPivotOrder` came from a strictly-ordered (comparator/pivotSort) refresh, so it must not
     *  be treated as a user order to restore. */
    private prevPivotStrict;
    /** Set when colsList order changes; {@link ensureColsListIndex} re-stamps `colsListIndex` lazily. */
    private colsListIndexDirty;
    /** User provided column definitions */
    colDefs: (ColDef | ColGroupDef)[] | undefined;
    private buildTokenCounter;
    /** Persistent padding-group cache for hierarchy virtual cols, handed to each column-tree build
     *  so `(col, depth)`-stable wrappers survive rebuilds. Owns the padding-group bean lifecycle. */
    private hierarchyWrapperCache;
    postConstruct(): void;
    destroy(): void;
    nextBuildToken(): number;
    isPivotActive(): boolean;
    getCols(): AgColumn[];
    /** Every column known to the grid (user, hierarchy, service, pivot result) in display (`colsList`)
     *  order, with parked pivot primaries appended. Lazily computed on first read after invalidation. */
    getAllCols(): AgColumn[];
    /** Resolve a provided group by id, falling back to parked primaries while pivoting (mirrors `getCol`). */
    getColGroup(groupId: string): AgProvidedColumnGroup | undefined;
    /** Columns in column-state order: hidden pivot primaries first, then `colsList`. Must not be mutated. */
    getColsInStateOrder(): AgColumn[];
    /** `newColDefs`: true = colDefs changed (order restored only with `maintainColumnOrder`); false =
     *  dynamic refresh with unchanged colDefs (prior order restored). */
    private buildFromColDefs;
    /** Queues the column events raised, and defers the role changes staged, until the matching {@link endColUpdate},
     *  so an update's listeners see every column it changes final. Nests: the outermost end runs them all. Active-col
     *  indexes (`*ActiveIndex`) are re-stamped only then, so they read stale inside an update that changes a role. */
    beginColUpdate(): void;
    /** Call from a `finally`, so a throw cannot leave the events queued for good. Each outermost end pass re-derives
     *  redefined filters' params, runs staged role changes and their grid events, then raises queued column events,
     *  until no listener stages more; then the layout events. A throw skips no step; the first is rethrown after. */
    endColUpdate(): void;
    /** Once raised, an owner's second event of a type (and state key) would report what its first does, so it replaces
     *  it: the owner is told once, in the first one's place, with the latest payload. */
    queueColEvent(owner: QueuedEventOwner, event: AgEvent<string>): void;
    /** Raises the queued events in order. A listener's update joins it, so an owner it changes again before being told
     *  is told once; a listener throwing stops none of the others, and its error follows them. */
    private flushColEvents;
    /** Call inside a column update: records the refresh and dispatch a role change needs, which the outermost
     *  {@link endColUpdate} runs once for the whole update. {@link ColChangeKind} selects the work: rebuild, legacy
     *  `columnEverythingChanged`, and/or a move animation. */
    stageColChanges(source: ColumnEventType, kind: ColChangeKind): void;
    private hasColChangesStaged;
    /** Refresh once (if needed) + dispatch each touched service; run by the outermost {@link endColUpdate}. */
    private runColChanges;
    refreshCols(newColDefs: boolean, source: ColumnEventType): void;
    /** True when this refresh reorders pivot columns due to an interactive pivot sort - either a sort is active,
     *  or the prior refresh was a strict pivot-sort order being cleared (desc→null) back to the default order. */
    private isPivotSortReorder;
    /** Refresh state derived from `colsList` (group + quick-filter cols) and
     *  reset displayed-col + viewport caches, ahead of `visibleCols.refresh`. Shared by full refreshCols
     *  and by a visibility-only change (which leaves `colsList` unchanged, so skips the rebuild). */
    refreshColsDerivedState(): void;
    /** Full refresh (rebuild cols + recompute visible); immediate, or deferred to the outermost {@link endColUpdate}. */
    refreshAll(source: ColumnEventType): void;
    private performRefresh;
    /** Reorder `colDefList` only — `newList` MUST be a permutation of the existing col instances
     *  (caller owns the invariant). A full refresh should follow to propagate to display cols.
     *  `colsById` unchanged; `getAllCols` is order-agnostic. */
    replaceColDefList(newList: AgColumn[]): void;
    private setPivotMode;
    recreateColumnDefs(e: PropertyChangedEvent | PropertyValueChangedEvent<keyof GridOptions>): void;
    setColumnDefs(columnDefs: (ColDef | ColGroupDef)[], source: ColumnEventType): void;
    /** Full structural rebuild from current `colDefs` + all contributors (hierarchy, calc cols, …).
     *  Used by contributors whose mutation changes tree structure (e.g. calc-col add/update/remove). */
    rebuildCols(source: ColumnEventType): void;
    /** Mark `AgColumn.colsListIndex` stale — called when `colsList`'s order changes outside a refresh
     *  (`moveColumns`, `applyColumnState` with `applyOrder`); next `ensureColsListIndex` re-stamps. */
    markColsListIndexDirty(): void;
    /** Drop all col-set/order-derived state after a structural (`colsList`) rebuild — this model's caches plus
     *  the sort service's column-derived cache. (An order-only move uses {@link markColsListIndexDirty} instead.) */
    private invalidateColsDerivedState;
    /** Lazily stamp each col's index in `colsList` onto `AgColumn.colsListIndex`, once per order change.
     *  Readers (e.g. `getColumnDefs`) call this before reading `col.colsListIndex`, so a burst of moves
     *  costs one O(N) pass on the next read, not one per move. */
    ensureColsListIndex(): void;
    /** Resolve any key (colId string, AgColumn, or ColDef) to its current AgColumn. Fast path inline:
     *  string colId, or object whose `colId` hits `colsById` (O(1)); misses delegate to `getColFallback`. */
    getCol(key: ColKey | null | undefined): AgColumn | undefined;
    /** Slow-path fallback for `getCol`: ColDef/ColGroupDef ref lookup + `field`-string fallback, building
     *  the lazy `colsByDef` map on first use. Stale AgColumn refs return `undefined` (unregistered, no `field`). */
    private getColFallback;
    /** Find a column excluding pivot result cols. `pivotKeys` (grid-set) is an O(1) discriminator
     *  standing in for a `pivotCols`-membership test, so `getColumnDefs()` doesn't round-trip them. */
    getNonPivotCol(key: ColKey): AgColumn | undefined;
    /** Like `getNonPivotCol` for hot paths where the key is a known colId string — skips the type-check + field-fallback. */
    getNonPivotColById(key: string): AgColumn | undefined;
    private loadColsByDef;
}
export {};
