export class WorkbookIdAllocator {
    nextRowAxisId = 1;
    nextColumnAxisId = 1;
    nextLogicalRowAxisId = 1;
    nextLogicalColumnAxisId = 1;
    nextStyleId = 1;
    nextFormatId = 1;
    reset() {
        this.nextRowAxisId = 1;
        this.nextColumnAxisId = 1;
        this.nextLogicalRowAxisId = 1;
        this.nextLogicalColumnAxisId = 1;
        this.nextStyleId = 1;
        this.nextFormatId = 1;
    }
    bumpStyleId(id) {
        const match = /^style-(\d+)$/.exec(id);
        if (!match) {
            return;
        }
        const numericId = Number.parseInt(match[1], 10);
        if (Number.isFinite(numericId)) {
            this.nextStyleId = Math.max(this.nextStyleId, numericId + 1);
        }
    }
    bumpFormatId(id) {
        const match = /^format-(\d+)$/.exec(id);
        if (!match) {
            return;
        }
        const numericId = Number.parseInt(match[1], 10);
        if (Number.isFinite(numericId)) {
            this.nextFormatId = Math.max(this.nextFormatId, numericId + 1);
        }
    }
    bumpAxisId(axis, id) {
        const prefix = axis === 'row' ? 'row' : 'column';
        const match = new RegExp(`^${prefix}-(\\d+)$`).exec(id);
        if (!match) {
            return;
        }
        const numericId = Number.parseInt(match[1], 10);
        if (!Number.isFinite(numericId)) {
            return;
        }
        if (axis === 'row') {
            this.nextRowAxisId = Math.max(this.nextRowAxisId, numericId + 1);
            return;
        }
        this.nextColumnAxisId = Math.max(this.nextColumnAxisId, numericId + 1);
    }
    createAxisEntry(axis) {
        return {
            id: this.createAxisId(axis),
            size: null,
            hidden: null,
            filterHidden: null,
        };
    }
    createLogicalAxisId(axis) {
        return axis === 'row' ? `lr${this.nextLogicalRowAxisId++}` : `lc${this.nextLogicalColumnAxisId++}`;
    }
    createLogicalAxisIds(axis, count) {
        if (count <= 0) {
            return [];
        }
        const ids = [];
        ids.length = count;
        if (axis === 'row') {
            let next = this.nextLogicalRowAxisId;
            this.nextLogicalRowAxisId += count;
            for (let index = 0; index < count; index += 1) {
                ids[index] = `lr${next++}`;
            }
            return ids;
        }
        let next = this.nextLogicalColumnAxisId;
        this.nextLogicalColumnAxisId += count;
        for (let index = 0; index < count; index += 1) {
            ids[index] = `lc${next++}`;
        }
        return ids;
    }
    createAxisId(axis) {
        return axis === 'row' ? `row-${this.nextRowAxisId++}` : `column-${this.nextColumnAxisId++}`;
    }
}
//# sourceMappingURL=workbook-id-allocator.js.map