"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 index_js_1 = require("../../core/index.js");
const index_js_2 = require("../../util/index.js");
const treeCursorUtils_js_1 = require("../treeCursorUtils.js");
const chunk_js_1 = require("./chunk.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.
 */
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_js_1.dummyRoot,
};
/**
 * Cursor over an empty field.
 * Contains no nodes and is stateless.
 */
exports.emptyCursor = {
    [index_js_1.CursorMarker]: true,
    pending: false,
    mode: 1 /* CursorLocationType.Fields */,
    [chunk_js_1.cursorChunk]: exports.emptyChunk,
    nextField() {
        (0, index_js_2.fail)("cannot navigate above root");
    },
    exitField() {
        (0, index_js_2.fail)("cannot navigate above root");
    },
    skipPendingFields() {
        return true;
    },
    getFieldKey() {
        return emptyPath.field;
    },
    getFieldLength() {
        return 0;
    },
    firstNode() {
        return false;
    },
    enterNode(childIndex) {
        (0, index_js_2.fail)("empty cursor has no nodes");
    },
    getFieldPath(prefix) {
        return (0, treeCursorUtils_js_1.prefixFieldPath)(prefix, emptyPath);
    },
    getPath() {
        (0, index_js_2.fail)("empty cursor has no nodes");
    },
    get fieldIndex() {
        return (0, index_js_2.fail)("empty cursor has no nodes");
    },
    get chunkStart() {
        return (0, index_js_2.fail)("empty cursor has no nodes");
    },
    get chunkLength() {
        return (0, index_js_2.fail)("empty cursor has no nodes");
    },
    seekNodes(offset) {
        (0, index_js_2.fail)("empty cursor has no nodes");
    },
    nextNode() {
        (0, index_js_2.fail)("empty cursor has no nodes");
    },
    exitNode() {
        (0, index_js_2.fail)("empty cursor has no nodes");
    },
    firstField() {
        (0, index_js_2.fail)("empty cursor has no nodes");
    },
    enterField(key) {
        (0, index_js_2.fail)("empty cursor has no nodes");
    },
    get type() {
        return (0, index_js_2.fail)("empty cursor has no nodes");
    },
    get value() {
        return (0, index_js_2.fail)("empty cursor has no nodes");
    },
    atChunkRoot() {
        return true;
    },
    fork() {
        return exports.emptyCursor;
    },
};
//# sourceMappingURL=emptyChunk.js.map