"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.emptyCursor = exports.emptyChunk = void 0;
const core_1 = require("../../core");
const util_1 = require("../../util");
const treeCursorUtils_1 = require("../treeCursorUtils");
const chunk_1 = require("./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.
 */
exports.emptyChunk = {
    topLevelLength: 0,
    cursor() {
        return exports.emptyCursor;
    },
    referenceAdded() { },
    referenceRemoved() { },
    isShared() {
        return false; // Immutable, so sharing does not matter.
    },
};
const emptyPath = {
    parent: undefined,
    field: chunk_1.dummyRoot,
};
/**
 * Cursor over an empty field.
 * Contains no nodes and is stateless.
 */
exports.emptyCursor = {
    [core_1.CursorMarker]: true,
    pending: false,
    mode: 1 /* Fields */,
    [chunk_1.cursorChunk]: exports.emptyChunk,
    nextField() {
        (0, util_1.fail)("cannot navigate above root");
    },
    exitField() {
        (0, util_1.fail)("cannot navigate above root");
    },
    skipPendingFields() {
        return true;
    },
    getFieldKey() {
        return emptyPath.field;
    },
    getFieldLength() {
        return 0;
    },
    firstNode() {
        return false;
    },
    enterNode(childIndex) {
        (0, util_1.fail)("empty cursor has no nodes");
    },
    getFieldPath(prefix) {
        return (0, treeCursorUtils_1.prefixFieldPath)(prefix, emptyPath);
    },
    getPath() {
        (0, util_1.fail)("empty cursor has no nodes");
    },
    get fieldIndex() {
        return (0, util_1.fail)("empty cursor has no nodes");
    },
    get chunkStart() {
        return (0, util_1.fail)("empty cursor has no nodes");
    },
    get chunkLength() {
        return (0, util_1.fail)("empty cursor has no nodes");
    },
    seekNodes(offset) {
        (0, util_1.fail)("empty cursor has no nodes");
    },
    nextNode() {
        (0, util_1.fail)("empty cursor has no nodes");
    },
    exitNode() {
        (0, util_1.fail)("empty cursor has no nodes");
    },
    firstField() {
        (0, util_1.fail)("empty cursor has no nodes");
    },
    enterField(key) {
        (0, util_1.fail)("empty cursor has no nodes");
    },
    get type() {
        return (0, util_1.fail)("empty cursor has no nodes");
    },
    get value() {
        return (0, util_1.fail)("empty cursor has no nodes");
    },
    atChunkRoot() {
        return true;
    },
    fork() {
        return exports.emptyCursor;
    },
};
//# sourceMappingURL=emptyChunk.js.map