"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MainThreadWindow = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_connection_1 = require("@opensumi/ide-connection");
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
const ide_overlay_1 = require("@opensumi/ide-overlay");
const vscode_1 = require("../../../common/vscode");
let MainThreadWindow = class MainThreadWindow {
    constructor(rpcProtocol) {
        this.rpcProtocol = rpcProtocol;
        this.proxy = this.rpcProtocol.getProxy(vscode_1.ExtHostAPIIdentifier.ExtHostWindow);
    }
    getDefaultDialogOptions(options) {
        return {
            ...options,
            defaultUri: options.defaultUri ? ide_core_browser_1.URI.from(options.defaultUri) : undefined,
        };
    }
    async $showOpenDialog(id, options = {}) {
        const op = this.getDefaultDialogOptions(options);
        const res = await this.windowDialogService.showOpenDialog(op);
        this.proxy.$onOpenDialogResult(id, res ? res.map((r) => r.codeUri) : res);
    }
    async $showSaveDialog(id, options = {}) {
        const op = this.getDefaultDialogOptions(options);
        const res = await this.windowDialogService.showSaveDialog(op);
        this.proxy.$onSaveDialogResult(id, res ? res.codeUri : res);
    }
    dispose() { }
};
exports.MainThreadWindow = MainThreadWindow;
tslib_1.__decorate([
    (0, di_1.Autowired)(di_1.INJECTOR_TOKEN),
    tslib_1.__metadata("design:type", di_1.Injector)
], MainThreadWindow.prototype, "injector", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_overlay_1.IDialogService),
    tslib_1.__metadata("design:type", Object)
], MainThreadWindow.prototype, "dialogService", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_overlay_1.IWindowDialogService),
    tslib_1.__metadata("design:type", Object)
], MainThreadWindow.prototype, "windowDialogService", void 0);
exports.MainThreadWindow = MainThreadWindow = tslib_1.__decorate([
    (0, di_1.Injectable)({ multiple: true }),
    tslib_1.__param(0, (0, di_1.Optional)(Symbol())),
    tslib_1.__metadata("design:paramtypes", [Object])
], MainThreadWindow);
//# sourceMappingURL=main.thread.window.js.map