/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { DoublyLinkedList, walkList } from "./collections/index.mjs";
/**
 * @alpha
 */
export class SegmentGroupCollection {
    constructor(segment) {
        this.segment = segment;
        // eslint-disable-next-line import/no-deprecated
        this.segmentGroups = new 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) {
        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]);
            }
        }
    }
}
//# sourceMappingURL=segmentGroupCollection.mjs.map