/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { isFlexTreeNode } from "../../feature-libraries/index.js";
import { simpleTreeNodeSlot, createTreeNodeFromInner, splitInnerNodeType, } from "./treeNodeKernel.js";
import { UnhydratedFlexTreeNode } from "./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.
 */
export function getOrCreateNodeFromInnerNode(flexNode) {
    splitInnerNodeType(flexNode);
    const cached = flexNode instanceof UnhydratedFlexTreeNode
        ? flexNode.treeNode
        : flexNode.anchorNode.slots.get(simpleTreeNodeSlot);
    if (cached !== undefined) {
        return cached;
    }
    return createTreeNodeFromInner(flexNode);
}
/**
 * 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.
 */
export function getOrCreateNodeFromInnerUnboxedNode(flexTree) {
    return isFlexTreeNode(flexTree) ? getOrCreateNodeFromInnerNode(flexTree) : flexTree;
}
//# sourceMappingURL=getOrCreateNode.js.map