/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { fail } from "@fluidframework/core-utils/internal";
import { CursorMarker, cursorChunk, dummyRoot, } from "../../core/index.js";
import { prefixFieldPath } from "../treeCursorUtils.js";
/**
 * Chunk that is empty.
 *
 * Since all emptiness is the same, this is a singleton.
 *
 * Useful for when a chunk or cursor is needed for an empty field or detached sequence.
 */
export const emptyChunk = {
    topLevelLength: 0,
    cursor() {
        return emptyCursor;
    },
    referenceAdded() { },
    referenceRemoved() { },
    isShared() {
        return false; // Immutable, so sharing does not matter.
    },
};
const emptyPath = {
    parent: undefined,
    field: dummyRoot,
};
/**
 * Cursor over an empty field.
 * Contains no nodes and is stateless.
 */
export const emptyCursor = {
    [CursorMarker]: true,
    pending: false,
    mode: 1 /* CursorLocationType.Fields */,
    [cursorChunk]: emptyChunk,
    nextField() {
        fail(0xafb /* cannot navigate above root */);
    },
    exitField() {
        fail(0xafc /* cannot navigate above root */);
    },
    skipPendingFields() {
        return true;
    },
    getFieldKey() {
        return emptyPath.field;
    },
    getFieldLength() {
        return 0;
    },
    firstNode() {
        return false;
    },
    enterNode(childIndex) {
        fail(0xafd /* empty cursor has no nodes */);
    },
    getFieldPath(prefix) {
        return prefixFieldPath(prefix, emptyPath);
    },
    getPath() {
        fail(0xafe /* empty cursor has no nodes */);
    },
    get fieldIndex() {
        return fail(0xaff /* empty cursor has no nodes */);
    },
    get chunkStart() {
        return fail(0xb00 /* empty cursor has no nodes */);
    },
    get chunkLength() {
        return fail(0xb01 /* empty cursor has no nodes */);
    },
    seekNodes(offset) {
        fail(0xb02 /* empty cursor has no nodes */);
    },
    nextNode() {
        fail(0xb03 /* empty cursor has no nodes */);
    },
    exitNode() {
        fail(0xb04 /* empty cursor has no nodes */);
    },
    firstField() {
        fail(0xb05 /* empty cursor has no nodes */);
    },
    enterField(key) {
        fail(0xb06 /* empty cursor has no nodes */);
    },
    get type() {
        return fail(0xb07 /* empty cursor has no nodes */);
    },
    get value() {
        return fail(0xb08 /* empty cursor has no nodes */);
    },
    atChunkRoot() {
        return true;
    },
    fork() {
        return emptyCursor;
    },
};
//# sourceMappingURL=emptyChunk.js.map