"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MainThreadExtensionNotebook = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_connection_1 = require("@opensumi/ide-connection");
const ide_core_common_1 = require("@opensumi/ide-core-common");
const ide_editor_1 = require("@opensumi/ide-editor");
const vscode_1 = require("../../../common/vscode");
let MainThreadExtensionNotebook = class MainThreadExtensionNotebook extends ide_core_common_1.WithEventBus {
    constructor(rpcProtocol) {
        super();
        this.rpcProtocol = rpcProtocol;
        this.proxy = this.rpcProtocol.getProxy(vscode_1.ExtHostAPIIdentifier.ExtHostNotebook);
        this.docProxy = this.rpcProtocol.getProxy(vscode_1.ExtHostAPIIdentifier.ExtHostDocuments);
        this.listen();
    }
    listen() {
        this.addDispose(this.notebookService.onDidOpenNotebookDocument((notebook) => {
            this.proxy.$acceptDocumentAndEditorsDelta({ addedDocuments: [notebook] });
        }));
        this.addDispose(this.notebookService.onDidCloseNotebookDocument((uri) => {
            this.proxy.$acceptDocumentAndEditorsDelta({ removedDocuments: [uri] });
        }));
        this.addDispose(this.notebookService.onDidChangeNotebookDocument((e) => {
            this.proxy.$acceptModelChanged(e.uri, e.event, e.isDirty, e.metadata);
        }));
        this.addDispose(this.notebookService.onDidSaveNotebookDocument((doc) => {
            this.proxy.$acceptModelSaved(doc);
        }));
    }
    async $tryCreateNotebook(options) {
        const notebook = await this.notebookService.createNotebook(options.content);
        return notebook.uri;
    }
    async $tryOpenNotebook(uriComponents) {
        const notebook = await this.notebookService.openNotebook(uriComponents);
        return notebook.uri;
    }
    async $trySaveNotebook(uri) {
        return await this.notebookService.saveNotebook(uri);
    }
};
exports.MainThreadExtensionNotebook = MainThreadExtensionNotebook;
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_editor_1.INotebookService),
    tslib_1.__metadata("design:type", Object)
], MainThreadExtensionNotebook.prototype, "notebookService", void 0);
exports.MainThreadExtensionNotebook = MainThreadExtensionNotebook = tslib_1.__decorate([
    (0, di_1.Injectable)({ multiple: true }),
    tslib_1.__param(0, (0, di_1.Optional)(Symbol())),
    tslib_1.__metadata("design:paramtypes", [Object])
], MainThreadExtensionNotebook);
//# sourceMappingURL=main.thread.notebook.js.map