"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SegmentGroupCollection = void 0;
const collections_1 = require("./collections");
class SegmentGroupCollection {
    constructor(segment) {
        this.segment = segment;
        this.segmentGroups = new collections_1.List();
    }
    get size() {
        return this.segmentGroups.length;
    }
    get empty() {
        return this.segmentGroups.empty;
    }
    enqueue(segmentGroup) {
        this.segmentGroups.push(segmentGroup);
        segmentGroup.segments.push(this.segment);
    }
    dequeue() {
        var _a;
        return (_a = this.segmentGroups.shift()) === null || _a === void 0 ? void 0 : _a.data;
    }
    pop() {
        var _a;
        return this.segmentGroups.pop ? (_a = this.segmentGroups.pop()) === null || _a === void 0 ? void 0 : _a.data : undefined;
    }
    /**
     * @deprecated - method is unused and will be removed.
     */
    clear() {
        while (!this.segmentGroups.empty) {
            this.segmentGroups.remove(this.segmentGroups.first);
        }
    }
    copyTo(segment) {
        (0, collections_1.walkList)(this.segmentGroups, (sg) => segment.segmentGroups.enqueueOnCopy(sg.data, this.segment));
    }
    enqueueOnCopy(segmentGroup, sourceSegment) {
        this.enqueue(segmentGroup);
        if (segmentGroup.previousProps) {
            // duplicate the previousProps for this segment
            const index = segmentGroup.segments.indexOf(sourceSegment);
            if (index !== -1) {
                segmentGroup.previousProps.push(segmentGroup.previousProps[index]);
            }
        }
    }
}
exports.SegmentGroupCollection = SegmentGroupCollection;
//# sourceMappingURL=segmentGroupCollection.js.map