"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/index.cjs");
/**
 * @alpha
 */
class SegmentGroupCollection {
    constructor(segment) {
        this.segment = segment;
        // eslint-disable-next-line import/no-deprecated
        this.segmentGroups = new collections_1.DoublyLinkedList();
    }
    get size() {
        return this.segmentGroups.length;
    }
    get empty() {
        return this.segmentGroups.empty;
    }
    // eslint-disable-next-line import/no-deprecated
    enqueue(segmentGroup) {
        this.segmentGroups.push(segmentGroup);
        segmentGroup.segments.push(this.segment);
    }
    // eslint-disable-next-line import/no-deprecated
    dequeue() {
        return this.segmentGroups.shift()?.data;
    }
    // eslint-disable-next-line import/no-deprecated
    remove(segmentGroup) {
        const found = this.segmentGroups.find((v) => v.data === segmentGroup);
        if (found === undefined) {
            return false;
        }
        this.segmentGroups.remove(found);
        return true;
    }
    // eslint-disable-next-line import/no-deprecated
    pop() {
        return this.segmentGroups.pop ? this.segmentGroups.pop()?.data : undefined;
    }
    copyTo(segment) {
        (0, collections_1.walkList)(this.segmentGroups, (sg) => segment.segmentGroups.enqueueOnCopy(sg.data, this.segment));
    }
    // eslint-disable-next-line import/no-deprecated
    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.cjs.map