"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.tryGetTreeNodeForField = void 0;
const internal_1 = require("@fluidframework/core-utils/internal");
const index_js_1 = require("../feature-libraries/index.js");
const index_js_2 = require("./core/index.js");
/**
 * Retrieve the associated {@link TreeNode} for the given field's content.
 */
function tryGetTreeNodeForField(field) {
    function tryToUnboxLeaves(flexField) {
        const maybeContent = flexField.content;
        return (0, index_js_1.isFlexTreeNode)(maybeContent)
            ? (0, index_js_2.getOrCreateNodeFromInnerNode)(maybeContent)
            : maybeContent;
    }
    switch (field.schema) {
        case index_js_1.FieldKinds.required.identifier: {
            const typedField = field;
            return tryToUnboxLeaves(typedField);
        }
        case index_js_1.FieldKinds.optional.identifier: {
            const typedField = field;
            return tryToUnboxLeaves(typedField);
        }
        case index_js_1.FieldKinds.identifier.identifier: {
            // Identifier fields are just value fields that hold strings
            return field.content;
        }
        default:
            (0, internal_1.fail)(0xadf /* invalid field kind */);
    }
}
exports.tryGetTreeNodeForField = tryGetTreeNodeForField;
//# sourceMappingURL=getTreeNodeForField.js.map