/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { getTreeContext, } from "../feature-libraries/index.js";
import { disposeSymbol } from "../util/index.js";
/**
 * Implementation of FlexTreeView wrapping a ITreeCheckout.
 */
export class CheckoutFlexTreeView {
    constructor(checkout, schema, nodeKeyManager, onDispose) {
        this.checkout = checkout;
        this.schema = schema;
        this.nodeKeyManager = nodeKeyManager;
        this.onDispose = onDispose;
        this.context = getTreeContext(schema, this.checkout, nodeKeyManager);
        contextToTreeView.set(this.context, this);
        this.flexTree = this.context.root;
    }
    [disposeSymbol]() {
        this.context[disposeSymbol]();
        this.onDispose?.();
    }
    fork() {
        const branch = this.checkout.fork();
        return new CheckoutFlexTreeView(branch, this.schema, this.nodeKeyManager);
    }
}
/**
 * Maps the context of every {@link CheckoutFlexTreeView} to the view.
 * In practice, this allows the view or checkout to be obtained from a flex node by first getting the context from the flex node and then using this map.
 */
// TODO: use something other than `any`
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const contextToTreeView = new WeakMap();
//# sourceMappingURL=treeView.js.map