/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { fail } from "../../util";
import { prefixFieldPath } from "../treeCursorUtils";
import { cursorChunk, dummyRoot } from "./chunk";
/**
 * 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 = {
    pending: false,
    mode: 1 /* Fields */,
    [cursorChunk]: emptyChunk,
    nextField() {
        fail("cannot navigate above root");
    },
    exitField() {
        fail("cannot navigate above root");
    },
    skipPendingFields() {
        return true;
    },
    getFieldKey() {
        return emptyPath.field;
    },
    getFieldLength() {
        return 0;
    },
    firstNode() {
        return false;
    },
    enterNode(childIndex) {
        fail("empty cursor has no nodes");
    },
    getFieldPath(prefix) {
        return prefixFieldPath(prefix, emptyPath);
    },
    getPath() {
        fail("empty cursor has no nodes");
    },
    get fieldIndex() {
        return fail("empty cursor has no nodes");
    },
    get chunkStart() {
        return fail("empty cursor has no nodes");
    },
    get chunkLength() {
        return fail("empty cursor has no nodes");
    },
    seekNodes(offset) {
        fail("empty cursor has no nodes");
    },
    nextNode() {
        fail("empty cursor has no nodes");
    },
    exitNode() {
        fail("empty cursor has no nodes");
    },
    firstField() {
        fail("empty cursor has no nodes");
    },
    enterField(key) {
        fail("empty cursor has no nodes");
    },
    get type() {
        return fail("empty cursor has no nodes");
    },
    get value() {
        return fail("empty cursor has no nodes");
    },
    atChunkRoot() {
        return true;
    },
    fork() {
        return emptyCursor;
    },
};
//# sourceMappingURL=emptyChunk.js.map