"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.HydratedContext = exports.Context = exports.SimpleContextSlot = void 0;
const index_js_1 = require("../../core/index.js");
const index_js_2 = require("../../util/index.js");
const walkSchema_js_1 = require("./walkSchema.js");
/**
 * Creating multiple simple tree contexts for the same branch, and thus with the same underlying AnchorSet does not work due to how TreeNode caching works.
 * This slot is used to detect if one already exists and error if creating a second.
 * @remarks
 * See also {@link ContextSlot} in which the flex-tree context is stored.
 */
exports.SimpleContextSlot = (0, index_js_1.anchorSlot)();
/**
 * Additional information about a collection of {@link TreeNode}s.
 * @remarks
 * Each TreeNode provides a way to navigate to a context for it with additional information.
 *
 * For unhydrated nodes, this information is rather limited since the node doesn't know what tree it might get inserted into (if any),
 * and thus is limited to information derived about that particular unhydrated tree and its schema.
 *
 * Hydrated nodes have more contextual information, and thus can provide a single {@link HydratedContext} for all nodes in the document which can have additional information.
 *
 * @privateRemarks
 * This design is the same as {@link FlexTreeContext} with its base type and {@link FlexTreeHydratedContext} extending it.
 */
class Context {
    /**
     * Builds the context.
     * @remarks
     * Since this walks the schema, it must not be invoked during schema declaration or schema forward references could fail to be resolved.
     */
    constructor(rootSchema, flexContext) {
        this.flexContext = flexContext;
        const schema = new Map();
        (0, walkSchema_js_1.walkAllowedTypes)(rootSchema, {
            node(nodeSchema) {
                schema.set((0, index_js_2.brand)(nodeSchema.identifier), nodeSchema);
            },
        });
        this.schema = schema;
    }
}
exports.Context = Context;
/**
 * Extends {@link Context} with additional information from the view and/or tree which becomes known when a {@link TreeNode} is hydrated,
 * associating it with the containing {@link TreeView}.
 */
class HydratedContext extends Context {
    constructor(rootSchema, flexContext) {
        super(rootSchema, flexContext);
        this.flexContext = flexContext;
    }
}
exports.HydratedContext = HydratedContext;
//# sourceMappingURL=context.js.map