"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.contextToTreeView = exports.CheckoutFlexTreeView = void 0;
const index_js_1 = require("../feature-libraries/index.js");
const index_js_2 = require("../util/index.js");
/**
 * Implementation of FlexTreeView wrapping a ITreeCheckout.
 */
class CheckoutFlexTreeView {
    constructor(checkout, schema, nodeKeyManager, nodeKeyFieldKey, onDispose) {
        this.checkout = checkout;
        this.schema = schema;
        this.nodeKeyManager = nodeKeyManager;
        this.nodeKeyFieldKey = nodeKeyFieldKey;
        this.onDispose = onDispose;
        this.context = (0, index_js_1.getTreeContext)(schema, this.checkout.forest, this.checkout.editor, nodeKeyManager, nodeKeyFieldKey);
        exports.contextToTreeView.set(this.context, this);
        this.flexTree = this.context.root;
    }
    [index_js_2.disposeSymbol]() {
        this.context[index_js_2.disposeSymbol]();
        this.onDispose?.();
    }
    fork() {
        const branch = this.checkout.fork();
        return new CheckoutFlexTreeView(branch, this.schema, this.nodeKeyManager, this.nodeKeyFieldKey);
    }
}
exports.CheckoutFlexTreeView = CheckoutFlexTreeView;
/**
 * 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.
 */
exports.contextToTreeView = new WeakMap();
//# sourceMappingURL=treeView.js.map