/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { rootFieldKey } from "./types";
export const emptyDelta = {};
export const emptyFieldChanges = {};
export function isAttachMark(mark) {
    return mark.attach !== undefined && mark.detach === undefined;
}
export function isDetachMark(mark) {
    return mark.detach !== undefined && mark.attach === undefined;
}
export function isReplaceMark(mark) {
    return mark.detach !== undefined && mark.attach !== undefined;
}
export function isEmptyFieldChanges(fieldChanges) {
    return (fieldChanges.local === undefined &&
        fieldChanges.global === undefined &&
        fieldChanges.build === undefined &&
        fieldChanges.rename === undefined);
}
export function deltaForRootInitialization(content) {
    if (content.length === 0) {
        return emptyDelta;
    }
    const buildId = { minor: 0 };
    const delta = {
        build: [{ id: buildId, trees: content }],
        fields: new Map([
            [
                rootFieldKey,
                {
                    local: [{ count: content.length, attach: buildId }],
                },
            ],
        ]),
    };
    return delta;
}
export function deltaForSet(newNode, buildId, detachId) {
    const mark = { count: 1, attach: buildId };
    if (detachId !== undefined) {
        mark.detach = detachId;
    }
    return {
        build: [{ id: buildId, trees: [newNode] }],
        local: [mark],
    };
}
export function makeDetachedNodeId(major, minor) {
    const out = { minor };
    if (major !== undefined) {
        out.major = major;
    }
    return out;
}
export function offsetDetachId(id, offset) {
    if (id === undefined) {
        return undefined;
    }
    return {
        ...id,
        minor: id.minor + offset,
    };
}
export function areDetachedNodeIdsEqual(a, b) {
    return a.major === b.major && a.minor === b.minor;
}
//# sourceMappingURL=deltaUtil.js.map