import { CellStore } from './cell-store.js';
import { createWorkbookMetadataService, runWorkbookMetadataEffect } from './workbook-metadata-service.js';
import { createWorkbookMetadataRecord, } from './workbook-metadata-types.js';
import { coalesceStyleRanges as coalesceWorkbookStyleRanges, getCellStyle as readCellStyle, getCellNumberFormat as readCellNumberFormat, getRangeFormatId as readRangeFormatId, getStyleId as readStyleId, internCellNumberFormat as internWorkbookCellNumberFormat, internCellStyle as internWorkbookCellStyle, listCellNumberFormats as listWorkbookCellNumberFormats, listCellStyles as listWorkbookCellStyles, listFormatRanges as listWorkbookFormatRanges, listStyleRanges as listWorkbookStyleRanges, setFormatRange as storeFormatRange, setFormatRanges as replaceFormatRanges, setStyleRange as storeStyleRange, setStyleRanges as replaceStyleRanges, upsertCellNumberFormat as storeCellNumberFormat, upsertCellStyle as storeCellStyle, } from './workbook-style-format-store.js';
import { WORKBOOK_DEFAULT_FORMAT_ID, WORKBOOK_DEFAULT_STYLE_ID, ensureWorkbookDefaultStyleFormat } from './workbook-default-style-format.js';
import { createCellKeyIndexMap } from './workbook-cell-key-index.js';
import { WorkbookCellRecordStore } from './workbook-cell-record-store.js';
import { WorkbookAxisEntryStore } from './workbook-axis-entry-store.js';
import { WorkbookAxisMetadataStore } from './workbook-axis-metadata-store.js';
import { WorkbookColumnVersionStore } from './workbook-column-version-store.js';
import { WorkbookIdAllocator } from './workbook-id-allocator.js';
import { WorkbookSheetRegistryStore } from './workbook-sheet-registry-store.js';
import { WorkbookStructuralCellStore } from './workbook-structural-cell-store.js';
import { WorkbookStructuralAxisOperations } from './workbook-structural-axis-operations.js';
import { hasStructuralMetadataForSheetRecord, hasWorkbookMetadataForSheetRename } from './workbook-store-metadata-presence.js';
import { WorkbookStoreCommentAccessors } from './workbook-store-comment-accessors.js';
export { makeCellKey, makeLogicalCellKey } from './workbook-cell-key-index.js';
export { normalizeDefinedName, normalizeWorkbookObjectName, imageKey, pivotKey, shapeKey } from './workbook-metadata-types.js';
export class WorkbookStore extends WorkbookStoreCommentAccessors {
    counters;
    static defaultStyleId = WORKBOOK_DEFAULT_STYLE_ID;
    static defaultFormatId = WORKBOOK_DEFAULT_FORMAT_ID;
    cellStore = new CellStore();
    sheetsByName = new Map();
    sheetsById = new Map();
    cellKeyToIndex;
    cellFormats = new Map();
    cellStyles = new Map();
    styleKeys = new Map();
    cellNumberFormats = new Map();
    numberFormatKeys = new Map();
    metadata = createWorkbookMetadataRecord();
    idAllocator = new WorkbookIdAllocator();
    metadataServiceValue;
    sheetRegistry;
    cellRecordStore;
    axisEntryStore;
    axisMetadataStore;
    columnVersionStore;
    structuralCellStore;
    structuralAxisOperations;
    workbookName;
    constructor(workbookName = 'Workbook', counters) {
        super();
        this.counters = counters;
        this.workbookName = workbookName;
        this.cellKeyToIndex = createCellKeyIndexMap((sheetId, row, col) => this.getCellIndexAt(sheetId, row, col));
        this.sheetRegistry = new WorkbookSheetRegistryStore({
            sheetsByName: this.sheetsByName,
            sheetsById: this.sheetsById,
            metadata: this.metadata,
            counters: this.counters,
            cellKeyToIndex: this.cellKeyToIndex,
            cellFormats: this.cellFormats,
            getCellPosition: (cellIndex) => this.getCellPosition(cellIndex),
            deleteSheetRecords: (sheetName, context) => {
                runWorkbookMetadataEffect(this.metadataService.deleteSheetRecords(sheetName, context));
            },
            reorderSheetRecords: (context) => {
                runWorkbookMetadataEffect(this.metadataService.reorderSheetRecords(context));
            },
            renameSheetRecords: (oldName, nextName) => {
                if (!hasWorkbookMetadataForSheetRename(this.metadata)) {
                    return;
                }
                runWorkbookMetadataEffect(this.metadataService.renameSheet(oldName, nextName));
            },
        });
        this.cellRecordStore = new WorkbookCellRecordStore({
            cellStore: this.cellStore,
            cellKeyToIndex: this.cellKeyToIndex,
            cellFormats: this.cellFormats,
            getSheet: (sheetName) => this.getSheet(sheetName),
            getOrCreateSheet: (sheetName) => this.getOrCreateSheet(sheetName),
            getSheetById: (sheetId) => this.getSheetById(sheetId),
            getSheetNameById: (sheetId) => this.getSheetNameById(sheetId),
            createLogicalAxisId: (axis) => this.createLogicalAxisId(axis),
            createLogicalAxisIds: (axis, count) => this.createLogicalAxisIds(axis, count),
        });
        this.axisEntryStore = new WorkbookAxisEntryStore({
            counters: this.counters,
            createAxisEntry: (axis) => this.idAllocator.createAxisEntry(axis),
        });
        this.axisMetadataStore = new WorkbookAxisMetadataStore({
            axisEntryStore: this.axisEntryStore,
            metadata: this.metadata,
            getSheet: (sheetName) => this.getSheet(sheetName),
            getOrCreateSheet: (sheetName) => this.getOrCreateSheet(sheetName),
        });
        this.columnVersionStore = new WorkbookColumnVersionStore({
            cellStore: this.cellStore,
            getSheetById: (sheetId) => this.getSheetById(sheetId),
        });
        this.structuralCellStore = new WorkbookStructuralCellStore({
            counters: this.counters,
            cellStore: this.cellStore,
            cellKeyToIndex: this.cellKeyToIndex,
            getSheet: (sheetName) => this.getSheet(sheetName),
            createLogicalAxisId: (axis) => this.createLogicalAxisId(axis),
        });
        this.structuralAxisOperations = new WorkbookStructuralAxisOperations({
            axisEntryStore: this.axisEntryStore,
            getOrCreateSheet: (sheetName) => this.getOrCreateSheet(sheetName),
            bumpSheetStructureVersion: (sheet) => this.bumpSheetStructureVersion(sheet),
        });
        this.cellStore.onSetValue = (index) => {
            this.notifyCellValueWritten(index);
        };
        ensureWorkbookDefaultStyleFormat(this);
    }
    get metadataService() {
        return (this.metadataServiceValue ??= createWorkbookMetadataService(this.metadata));
    }
    hasStructuralMetadataForSheet(sheetName) {
        return (hasStructuralMetadataForSheetRecord(this.metadata, sheetName, this.getSheet(sheetName)) ||
            [...this.sheetsByName.values()].some((sheet) => sheet.sparklines !== undefined));
    }
    hasProtectionMetadataForSheet(sheetName) {
        if (this.metadata.sheetProtections.has(sheetName)) {
            return true;
        }
        for (const protection of this.metadata.rangeProtections.values()) {
            if (protection.range.sheetName === sheetName) {
                return true;
            }
        }
        return false;
    }
    createSheet(name, order = this.sheetsByName.size, id) {
        return this.sheetRegistry.createSheet(name, order, id);
    }
    moveSheet(name, order) {
        return this.sheetRegistry.moveSheet(name, order);
    }
    deleteSheet(name) {
        this.sheetRegistry.deleteSheet(name);
    }
    renameSheet(oldName, nextName) {
        return this.sheetRegistry.renameSheet(oldName, nextName);
    }
    renameSheetById(sheetId, trimmedName) {
        return this.sheetRegistry.renameSheetById(sheetId, trimmedName);
    }
    renameSheetByIdTrustedPrevalidated(sheetId, oldName, trimmedName) {
        return this.sheetRegistry.renameSheetByIdTrustedPrevalidated(sheetId, oldName, trimmedName);
    }
    getSheet(name) {
        return this.sheetRegistry.getSheet(name);
    }
    getSheetColumnVersion(sheetName, col) {
        return this.sheetRegistry.getSheetColumnVersion(sheetName, col);
    }
    getSheetStructureVersion(sheetName) {
        return this.sheetRegistry.getSheetStructureVersion(sheetName);
    }
    getSheetById(id) {
        return this.sheetRegistry.getSheetById(id);
    }
    getOrCreateSheet(name) {
        return this.getSheet(name) ?? this.createSheet(name);
    }
    ensureCell(sheetName, address) {
        return this.cellRecordStore.ensureCell(sheetName, address);
    }
    ensureCellRecord(sheetName, address) {
        return this.cellRecordStore.ensureCellRecord(sheetName, address);
    }
    ensureCellAt(sheetId, row, col) {
        return this.cellRecordStore.ensureCellAt(sheetId, row, col);
    }
    attachAllocatedCell(sheetId, row, col, cellIndex) {
        this.cellRecordStore.attachAllocatedCell(sheetId, row, col, cellIndex);
    }
    ensureLogicalAxisId(sheetId, axis, index) {
        return this.cellRecordStore.ensureLogicalAxisId(sheetId, axis, index);
    }
    createLogicalAxisIdEnsurer(sheetId, axis) {
        return this.cellRecordStore.createLogicalAxisIdEnsurer(sheetId, axis);
    }
    createDenseLogicalAxisIds(sheetId, axis, start, count) {
        return this.cellRecordStore.createDenseLogicalAxisIds(sheetId, axis, start, count);
    }
    attachAllocatedCellWithLogicalAxisIds(sheetId, row, col, cellIndex, rowId, colId) {
        this.cellRecordStore.attachAllocatedCellWithLogicalAxisIds(sheetId, row, col, cellIndex, rowId, colId);
    }
    withBatchedColumnVersionUpdates(execute) {
        return this.columnVersionStore.withBatchedColumnVersionUpdates(execute);
    }
    notifyCellValueWritten(cellIndex) {
        this.columnVersionStore.notifyCellValueWritten(cellIndex);
    }
    notifyColumnsWritten(sheetId, columns) {
        this.columnVersionStore.notifyColumnsWritten(sheetId, columns);
    }
    notifyColumnWritten(sheetId, col) {
        this.columnVersionStore.notifyColumnWritten(sheetId, col);
    }
    notifyColumnPairWritten(sheetId, firstCol, secondCol) {
        this.columnVersionStore.notifyColumnPairWritten(sheetId, firstCol, secondCol);
    }
    getCellIndex(sheetName, address) {
        return this.cellRecordStore.getCellIndex(sheetName, address);
    }
    getCellIndexAt(sheetId, row, col) {
        return this.cellRecordStore.getCellIndexAt(sheetId, row, col);
    }
    getFreshCellIndexAt(sheetId, row, col) {
        return this.cellRecordStore.getFreshCellIndexAt(sheetId, row, col);
    }
    getSheetNameById(id) {
        return this.sheetRegistry.getSheetNameById(id);
    }
    getAddress(index) {
        return this.cellRecordStore.getAddress(index);
    }
    getQualifiedAddress(index) {
        return this.cellRecordStore.getQualifiedAddress(index);
    }
    getCellPosition(index) {
        return this.cellRecordStore.getCellPosition(index);
    }
    getCellAxisIndex(index, axis) {
        return this.cellRecordStore.getCellAxisIndex(index, axis);
    }
    detachCellIndex(index) {
        return this.cellRecordStore.detachCellIndex(index);
    }
    pruneCellIfEmpty(index) {
        return this.cellRecordStore.pruneCellIfEmpty(index);
    }
    setCellFormat(index, format) {
        if (format === undefined || format === null || format === '') {
            this.cellFormats.delete(index);
            return;
        }
        this.internCellNumberFormat(format);
        this.cellFormats.set(index, format);
    }
    getCellFormat(index) {
        return this.cellFormats.get(index);
    }
    upsertCellStyle(style) {
        return storeCellStyle(this, style, (id) => this.idAllocator.bumpStyleId(id));
    }
    internCellStyle(style) {
        return internWorkbookCellStyle(this, style, WorkbookStore.defaultStyleId);
    }
    getCellStyle(id) {
        return readCellStyle(this, id, WorkbookStore.defaultStyleId);
    }
    getCellStyleProtection(sheetName, row, col) {
        return this.getCellStyle(this.getStyleId(sheetName, row, col))?.protection;
    }
    listCellStyles() {
        return listWorkbookCellStyles(this);
    }
    upsertCellNumberFormat(format) {
        return storeCellNumberFormat(this, format, (id) => this.idAllocator.bumpFormatId(id));
    }
    internCellNumberFormat(format) {
        return internWorkbookCellNumberFormat(this, format, WorkbookStore.defaultFormatId);
    }
    getCellNumberFormat(id) {
        return readCellNumberFormat(this, id, WorkbookStore.defaultFormatId);
    }
    listCellNumberFormats() {
        return listWorkbookCellNumberFormats(this);
    }
    setStyleRange(range, styleId) {
        return storeStyleRange(this, this.getOrCreateSheet(range.sheetName), range, styleId, WorkbookStore.defaultStyleId);
    }
    coalesceStyleRanges(sheetName) {
        const sheet = this.getSheet(sheetName);
        if (!sheet) {
            return [];
        }
        return coalesceWorkbookStyleRanges(sheet);
    }
    listStyleRanges(sheetName) {
        return listWorkbookStyleRanges(this.getSheet(sheetName));
    }
    setStyleRanges(sheetName, ranges) {
        return replaceStyleRanges(this, this.getOrCreateSheet(sheetName), ranges);
    }
    getStyleId(sheetName, row, col) {
        return readStyleId(this.getSheet(sheetName), row, col, WorkbookStore.defaultStyleId);
    }
    setFormatRange(range, formatId) {
        return storeFormatRange(this, this.getOrCreateSheet(range.sheetName), range, formatId, WorkbookStore.defaultFormatId);
    }
    listFormatRanges(sheetName) {
        return listWorkbookFormatRanges(this.getSheet(sheetName));
    }
    setFormatRanges(sheetName, ranges) {
        return replaceFormatRanges(this, this.getOrCreateSheet(sheetName), ranges);
    }
    getRangeFormatId(sheetName, row, col) {
        return readRangeFormatId(this.getSheet(sheetName), row, col, WorkbookStore.defaultFormatId);
    }
    setWorkbookProperty(key, value) {
        return runWorkbookMetadataEffect(this.metadataService.setWorkbookProperty(key, value));
    }
    getWorkbookProperty(key) {
        return runWorkbookMetadataEffect(this.metadataService.getWorkbookProperty(key));
    }
    listWorkbookProperties() {
        return runWorkbookMetadataEffect(this.metadataService.listWorkbookProperties());
    }
    setWorkbookProtection(record) {
        return runWorkbookMetadataEffect(this.metadataService.setWorkbookProtection(record));
    }
    getWorkbookProtection() {
        return runWorkbookMetadataEffect(this.metadataService.getWorkbookProtection());
    }
    setMacroPayload(record) {
        return runWorkbookMetadataEffect(this.metadataService.setMacroPayload(record));
    }
    listMacroPayloads() {
        return runWorkbookMetadataEffect(this.metadataService.listMacroPayloads());
    }
    setCalculationSettings(settings) {
        return runWorkbookMetadataEffect(this.metadataService.setCalculationSettings(settings));
    }
    getCalculationSettings() {
        return runWorkbookMetadataEffect(this.metadataService.getCalculationSettings());
    }
    setVolatileContext(context) {
        return runWorkbookMetadataEffect(this.metadataService.setVolatileContext(context));
    }
    getVolatileContext() {
        return runWorkbookMetadataEffect(this.metadataService.getVolatileContext());
    }
    setDrawingArtifacts(artifacts) {
        return runWorkbookMetadataEffect(this.metadataService.setDrawingArtifacts(artifacts));
    }
    getDrawingArtifacts() {
        return runWorkbookMetadataEffect(this.metadataService.getDrawingArtifacts());
    }
    clearDrawingArtifacts() {
        return runWorkbookMetadataEffect(this.metadataService.clearDrawingArtifacts());
    }
    setExternalLinkArtifacts(artifacts) {
        return runWorkbookMetadataEffect(this.metadataService.setExternalLinkArtifacts(artifacts));
    }
    getExternalLinkArtifacts() {
        return runWorkbookMetadataEffect(this.metadataService.getExternalLinkArtifacts());
    }
    clearExternalLinkArtifacts() {
        return runWorkbookMetadataEffect(this.metadataService.clearExternalLinkArtifacts());
    }
    setDefinedName(name, value, scopeSheetName) {
        return runWorkbookMetadataEffect(this.metadataService.setDefinedName(name, value, scopeSheetName));
    }
    getDefinedName(name, scopeSheetName) {
        return runWorkbookMetadataEffect(this.metadataService.getDefinedName(name, scopeSheetName));
    }
    deleteDefinedName(name, scopeSheetName) {
        return runWorkbookMetadataEffect(this.metadataService.deleteDefinedName(name, scopeSheetName));
    }
    listDefinedNames() {
        return runWorkbookMetadataEffect(this.metadataService.listDefinedNames());
    }
    setTable(record) {
        return runWorkbookMetadataEffect(this.metadataService.setTable(record));
    }
    getTable(name) {
        return runWorkbookMetadataEffect(this.metadataService.getTable(name));
    }
    deleteTable(name) {
        return runWorkbookMetadataEffect(this.metadataService.deleteTable(name));
    }
    hasTables() {
        return this.metadata.tables.size > 0;
    }
    listTables() {
        return runWorkbookMetadataEffect(this.metadataService.listTables());
    }
    setRowMetadata(sheetName, start, count, size, hidden, geometry, filterHidden) {
        return this.axisMetadataStore.setRowMetadata(sheetName, start, count, size, hidden, geometry, filterHidden);
    }
    getRowMetadata(sheetName, start, count) {
        return this.axisMetadataStore.getRowMetadata(sheetName, start, count);
    }
    listRowMetadata(sheetName) {
        return this.axisMetadataStore.listRowMetadata(sheetName);
    }
    setColumnMetadata(sheetName, start, count, size, hidden, geometry, filterHidden) {
        return this.axisMetadataStore.setColumnMetadata(sheetName, start, count, size, hidden, geometry, filterHidden);
    }
    getColumnMetadata(sheetName, start, count) {
        return this.axisMetadataStore.getColumnMetadata(sheetName, start, count);
    }
    listColumnMetadata(sheetName) {
        return this.axisMetadataStore.listColumnMetadata(sheetName);
    }
    setSheetFormatPr(sheetName, sheetFormatPr) {
        this.getOrCreateSheet(sheetName).sheetFormatPr = structuredClone(sheetFormatPr);
    }
    getSheetFormatPr(sheetName) {
        const sheetFormatPr = this.getSheet(sheetName)?.sheetFormatPr;
        return sheetFormatPr ? structuredClone(sheetFormatPr) : undefined;
    }
    setSheetVisibility(sheetName, visibility) {
        const sheet = this.getOrCreateSheet(sheetName);
        if (visibility === undefined) {
            delete sheet.visibility;
            return;
        }
        sheet.visibility = visibility;
    }
    getSheetVisibility(sheetName) {
        return this.getSheet(sheetName)?.visibility;
    }
    listRowAxisEntries(sheetName) {
        return this.axisEntryStore.listAxisEntries(this.getSheet(sheetName), 'row');
    }
    listColumnAxisEntries(sheetName) {
        return this.axisEntryStore.listAxisEntries(this.getSheet(sheetName), 'column');
    }
    snapshotRowAxisEntries(sheetName, start, count) {
        return this.axisEntryStore.snapshotAxisEntriesInRange(this.getSheet(sheetName), 'row', start, count);
    }
    snapshotColumnAxisEntries(sheetName, start, count) {
        return this.axisEntryStore.snapshotAxisEntriesInRange(this.getSheet(sheetName), 'column', start, count);
    }
    materializeRowAxisEntries(sheetName, start, count) {
        return this.axisEntryStore.materializeAxisEntries(this.getOrCreateSheet(sheetName), 'row', start, count);
    }
    materializeColumnAxisEntries(sheetName, start, count) {
        return this.axisEntryStore.materializeAxisEntries(this.getOrCreateSheet(sheetName), 'column', start, count);
    }
    bumpProvidedAxisEntryIds(axis, entries) {
        entries?.forEach((entry) => {
            this.idAllocator.bumpAxisId(axis, entry.id);
        });
    }
    insertRows(sheetName, start, count, entries) {
        this.bumpProvidedAxisEntryIds('row', entries);
        this.structuralAxisOperations.insert('row', sheetName, start, count, entries);
    }
    deleteRows(sheetName, start, count) {
        return this.structuralAxisOperations.delete('row', sheetName, start, count);
    }
    moveRows(sheetName, start, count, target) {
        this.structuralAxisOperations.move('row', sheetName, start, count, target);
    }
    insertColumns(sheetName, start, count, entries) {
        this.bumpProvidedAxisEntryIds('column', entries);
        this.structuralAxisOperations.insert('column', sheetName, start, count, entries);
    }
    deleteColumns(sheetName, start, count) {
        return this.structuralAxisOperations.delete('column', sheetName, start, count);
    }
    moveColumns(sheetName, start, count, target) {
        this.structuralAxisOperations.move('column', sheetName, start, count, target);
    }
    setFreezePane(sheetName, rows, cols, options) {
        return runWorkbookMetadataEffect(this.metadataService.setFreezePane(sheetName, rows, cols, options));
    }
    getFreezePane(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.getFreezePane(sheetName));
    }
    clearFreezePane(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.clearFreezePane(sheetName));
    }
    setSheetTabColor(sheetName, tabColor) {
        return runWorkbookMetadataEffect(this.metadataService.setSheetTabColor(sheetName, tabColor));
    }
    getSheetTabColor(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.getSheetTabColor(sheetName));
    }
    clearSheetTabColor(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.clearSheetTabColor(sheetName));
    }
    setMergeRange(range) {
        return runWorkbookMetadataEffect(this.metadataService.setMergeRange(range));
    }
    setMergeRanges(sheetName, ranges) {
        return runWorkbookMetadataEffect(this.metadataService.setMergeRanges(sheetName, ranges));
    }
    getMergeRange(sheetName, address) {
        return runWorkbookMetadataEffect(this.metadataService.getMergeRange(sheetName, address));
    }
    getMergeRangeByRange(range) {
        return runWorkbookMetadataEffect(this.metadataService.getMergeRangeByRange(range));
    }
    clearMergeRanges(range) {
        return runWorkbookMetadataEffect(this.metadataService.clearMergeRanges(range));
    }
    listMergeRanges(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.listMergeRanges(sheetName));
    }
    setSheetProtection(record) {
        return runWorkbookMetadataEffect(this.metadataService.setSheetProtection(record));
    }
    getSheetProtection(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.getSheetProtection(sheetName));
    }
    clearSheetProtection(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.clearSheetProtection(sheetName));
    }
    setFilter(sheetName, range) {
        return runWorkbookMetadataEffect(this.metadataService.setFilter(sheetName, range));
    }
    getFilter(sheetName, range) {
        return runWorkbookMetadataEffect(this.metadataService.getFilter(sheetName, range));
    }
    deleteFilter(sheetName, range) {
        return runWorkbookMetadataEffect(this.metadataService.deleteFilter(sheetName, range));
    }
    listFilters(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.listFilters(sheetName));
    }
    setSort(sheetName, range, keys) {
        return runWorkbookMetadataEffect(this.metadataService.setSort(sheetName, range, keys));
    }
    getSort(sheetName, range) {
        return runWorkbookMetadataEffect(this.metadataService.getSort(sheetName, range));
    }
    deleteSort(sheetName, range) {
        return runWorkbookMetadataEffect(this.metadataService.deleteSort(sheetName, range));
    }
    listSorts(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.listSorts(sheetName));
    }
    setDataValidation(record) {
        return runWorkbookMetadataEffect(this.metadataService.setDataValidation(record));
    }
    getDataValidation(sheetName, range) {
        return runWorkbookMetadataEffect(this.metadataService.getDataValidation(sheetName, range));
    }
    deleteDataValidation(sheetName, range) {
        return runWorkbookMetadataEffect(this.metadataService.deleteDataValidation(sheetName, range));
    }
    listDataValidations(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.listDataValidations(sheetName));
    }
    setConditionalFormat(record) {
        return runWorkbookMetadataEffect(this.metadataService.setConditionalFormat(record));
    }
    getConditionalFormat(id) {
        return runWorkbookMetadataEffect(this.metadataService.getConditionalFormat(id));
    }
    deleteConditionalFormat(id) {
        return runWorkbookMetadataEffect(this.metadataService.deleteConditionalFormat(id));
    }
    listConditionalFormats(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.listConditionalFormats(sheetName));
    }
    setConditionalFormatArtifacts(sheetName, artifacts) {
        return runWorkbookMetadataEffect(this.metadataService.setConditionalFormatArtifacts(sheetName, artifacts));
    }
    getConditionalFormatArtifacts(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.getConditionalFormatArtifacts(sheetName));
    }
    deleteConditionalFormatArtifacts(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.deleteConditionalFormatArtifacts(sheetName));
    }
    setSheetDrawingArtifacts(sheetName, artifacts) {
        return runWorkbookMetadataEffect(this.metadataService.setSheetDrawingArtifacts(sheetName, artifacts));
    }
    getSheetDrawingArtifacts(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.getSheetDrawingArtifacts(sheetName));
    }
    deleteSheetDrawingArtifacts(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.deleteSheetDrawingArtifacts(sheetName));
    }
    setRangeProtection(record) {
        return runWorkbookMetadataEffect(this.metadataService.setRangeProtection(record));
    }
    getRangeProtection(id) {
        return runWorkbookMetadataEffect(this.metadataService.getRangeProtection(id));
    }
    deleteRangeProtection(id) {
        return runWorkbookMetadataEffect(this.metadataService.deleteRangeProtection(id));
    }
    listRangeProtections(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.listRangeProtections(sheetName));
    }
    setNote(record) {
        return runWorkbookMetadataEffect(this.metadataService.setNote(record));
    }
    getNote(sheetName, address) {
        return runWorkbookMetadataEffect(this.metadataService.getNote(sheetName, address));
    }
    deleteNote(sheetName, address) {
        return runWorkbookMetadataEffect(this.metadataService.deleteNote(sheetName, address));
    }
    listNotes(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.listNotes(sheetName));
    }
    setHyperlink(record) {
        return runWorkbookMetadataEffect(this.metadataService.setHyperlink(record));
    }
    getHyperlink(sheetName, address) {
        return runWorkbookMetadataEffect(this.metadataService.getHyperlink(sheetName, address));
    }
    deleteHyperlink(sheetName, address) {
        return runWorkbookMetadataEffect(this.metadataService.deleteHyperlink(sheetName, address));
    }
    listHyperlinks(sheetName) {
        return runWorkbookMetadataEffect(this.metadataService.listHyperlinks(sheetName));
    }
    setSpill(sheetName, address, rows, cols) {
        return runWorkbookMetadataEffect(this.metadataService.setSpill(sheetName, address, rows, cols));
    }
    getSpill(sheetName, address) {
        return runWorkbookMetadataEffect(this.metadataService.getSpill(sheetName, address));
    }
    deleteSpill(sheetName, address) {
        return runWorkbookMetadataEffect(this.metadataService.deleteSpill(sheetName, address));
    }
    listSpills() {
        return runWorkbookMetadataEffect(this.metadataService.listSpills());
    }
    setPivot(record) {
        return runWorkbookMetadataEffect(this.metadataService.setPivot(record));
    }
    getPivot(sheetName, address) {
        return runWorkbookMetadataEffect(this.metadataService.getPivot(sheetName, address));
    }
    getPivotByKey(key) {
        return runWorkbookMetadataEffect(this.metadataService.getPivotByKey(key));
    }
    deletePivot(sheetName, address) {
        return runWorkbookMetadataEffect(this.metadataService.deletePivot(sheetName, address));
    }
    hasPivots() {
        return this.metadata.pivots.size > 0;
    }
    listPivots() {
        return runWorkbookMetadataEffect(this.metadataService.listPivots());
    }
    setChart(record) {
        return runWorkbookMetadataEffect(this.metadataService.setChart(record));
    }
    getChart(id) {
        return runWorkbookMetadataEffect(this.metadataService.getChart(id));
    }
    deleteChart(id) {
        return runWorkbookMetadataEffect(this.metadataService.deleteChart(id));
    }
    listCharts() {
        return runWorkbookMetadataEffect(this.metadataService.listCharts());
    }
    setImage(record) {
        return runWorkbookMetadataEffect(this.metadataService.setImage(record));
    }
    getImage(id) {
        return runWorkbookMetadataEffect(this.metadataService.getImage(id));
    }
    deleteImage(id) {
        return runWorkbookMetadataEffect(this.metadataService.deleteImage(id));
    }
    listImages() {
        return runWorkbookMetadataEffect(this.metadataService.listImages());
    }
    setShape(record) {
        return runWorkbookMetadataEffect(this.metadataService.setShape(record));
    }
    getShape(id) {
        return runWorkbookMetadataEffect(this.metadataService.getShape(id));
    }
    deleteShape(id) {
        return runWorkbookMetadataEffect(this.metadataService.deleteShape(id));
    }
    listShapes() {
        return runWorkbookMetadataEffect(this.metadataService.listShapes());
    }
    remapSheetCells(sheetName, axis, remapIndex, scope) {
        return this.structuralCellStore.remapSheetCells(sheetName, axis, remapIndex, scope);
    }
    planStructuralAxisTransform(sheetName, transform) {
        return this.structuralCellStore.planStructuralAxisTransform(sheetName, transform);
    }
    applyPlannedStructuralTransaction(transaction) {
        return this.structuralCellStore.applyPlannedStructuralTransaction(transaction);
    }
    applyStructuralAxisTransform(sheetName, transform) {
        return this.structuralCellStore.applyStructuralAxisTransform(sheetName, transform);
    }
    reset(workbookName = 'Workbook') {
        this.workbookName = workbookName;
        this.sheetRegistry.reset();
        this.cellKeyToIndex.clear();
        this.cellFormats.clear();
        this.cellStyles.clear();
        this.styleKeys.clear();
        this.cellNumberFormats.clear();
        this.numberFormatKeys.clear();
        runWorkbookMetadataEffect(this.metadataService.reset());
        this.idAllocator.reset();
        this.cellStore.reset();
        ensureWorkbookDefaultStyleFormat(this);
    }
    releaseReusableBuffers() {
        for (const sheet of this.sheetsById.values()) {
            sheet.grid.releaseBlocksToPool();
        }
        this.cellStore.releaseBuffersToPool();
    }
    bumpSheetStructureVersion(sheet) {
        sheet.structureVersion += 1;
    }
    createLogicalAxisId(axis) {
        return this.idAllocator.createLogicalAxisId(axis);
    }
    createLogicalAxisIds(axis, count) {
        return this.idAllocator.createLogicalAxisIds(axis, count);
    }
}
//# sourceMappingURL=workbook-store.js.map