"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SequenceChunk = void 0;
const index_js_1 = require("../../util/index.js");
const basicChunk_js_1 = require("./basicChunk.js");
const chunk_js_1 = require("./chunk.js");
/**
 * General purpose multi-node sequence chunk.
 */
class SequenceChunk extends index_js_1.ReferenceCountedBase {
    get topLevelLength() {
        let total = 0;
        for (const child of this.subChunks) {
            total += child.topLevelLength;
        }
        return total;
    }
    /**
     * Create a tree chunk with ref count 1.
     *
     * @param fields - provides exclusive deep ownership of this map to this object (which might mutate it in the future).
     * The caller must have already accounted for this reference to the children in this map (via `referenceAdded`),
     * and any edits to this must update child reference counts.
     * @param value - the value on this node, if any.
     */
    constructor(subChunks) {
        super();
        this.subChunks = subChunks;
    }
    clone() {
        const subChunks = this.subChunks.map((child) => {
            child.referenceAdded();
            return child;
        });
        return new SequenceChunk(subChunks);
    }
    cursor() {
        return new basicChunk_js_1.BasicChunkCursor(this.subChunks, [], [], [], [], [chunk_js_1.dummyRoot], 0, 0, 0, undefined);
    }
    onUnreferenced() {
        for (const child of this.subChunks) {
            child.referenceRemoved();
        }
    }
}
exports.SequenceChunk = SequenceChunk;
//# sourceMappingURL=sequenceChunk.js.map