export class CellPageStore {
    cells;
    keyForLocation;
    rebuildSource;
    pagesDirty = false;
    keyForParts;
    constructor(cells, keyForLocation, rebuildSource, keyForParts) {
        this.cells = cells;
        this.keyForLocation = keyForLocation;
        this.rebuildSource = rebuildSource;
        this.keyForParts = keyForParts ?? ((sheetId, rowId, colId) => this.keyForLocation({ sheetId, rowId, colId }));
    }
    key(location) {
        return this.keyForLocation(location);
    }
    get(location) {
        this.ensurePages();
        return this.cells.get(this.key(location));
    }
    set(location, cellIndex) {
        this.ensurePages();
        this.cells.set(this.key(location), cellIndex);
    }
    setDeferred(location, cellIndex) {
        this.cells.set(this.key(location), cellIndex);
    }
    setDeferredParts(sheetId, rowId, colId, cellIndex) {
        this.cells.set(this.keyForParts(sheetId, rowId, colId), cellIndex);
    }
    deferRebuild() {
        this.pagesDirty = true;
    }
    delete(location) {
        this.ensurePages();
        return this.cells.delete(this.key(location));
    }
    ensurePages() {
        if (!this.pagesDirty) {
            return;
        }
        this.cells.clear();
        this.rebuildSource?.((location, cellIndex) => {
            this.cells.set(this.key(location), cellIndex);
        });
        this.pagesDirty = false;
    }
}
//# sourceMappingURL=cell-page-store.js.map