"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOrCreateNodeFromInnerUnboxedNode = exports.getOrCreateNodeFromInnerNode = void 0;
const index_js_1 = require("../../feature-libraries/index.js");
const treeNodeKernel_js_1 = require("./treeNodeKernel.js");
const unhydratedFlexTree_js_1 = require("./unhydratedFlexTree.js");
/**
 * Returns the TreeNode or TreeValue for the provided {@link InnerNode}.
 * This will allocate a new one if needed, and otherwise return one from cache.
 * @remarks
 * This supports both hydrated and unhydrated nodes.
 */
function getOrCreateNodeFromInnerNode(flexNode) {
    (0, treeNodeKernel_js_1.splitInnerNodeType)(flexNode);
    const cached = flexNode instanceof unhydratedFlexTree_js_1.UnhydratedFlexTreeNode
        ? flexNode.treeNode
        : flexNode.anchorNode.slots.get(treeNodeKernel_js_1.simpleTreeNodeSlot);
    if (cached !== undefined) {
        return cached;
    }
    return (0, treeNodeKernel_js_1.createTreeNodeFromInner)(flexNode);
}
exports.getOrCreateNodeFromInnerNode = getOrCreateNodeFromInnerNode;
/**
 * Returns the TreeNode or TreeValue for the provided {@link FlexTreeUnknownUnboxed}.
 * This will allocate a new one if needed, and otherwise return one from cache.
 * @remarks
 * This supports both hydrated and unhydrated nodes.
 */
function getOrCreateNodeFromInnerUnboxedNode(flexTree) {
    return (0, index_js_1.isFlexTreeNode)(flexTree) ? getOrCreateNodeFromInnerNode(flexTree) : flexTree;
}
exports.getOrCreateNodeFromInnerUnboxedNode = getOrCreateNodeFromInnerUnboxedNode;
//# sourceMappingURL=getOrCreateNode.js.map