
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
import { PickerQuickAccessProvider } from '../../../../platform/quickinput/browser/pickerQuickAccess.js';
import { localize } from '../../../../nls.js';
import { IExtensionGalleryService, IExtensionManagementService } from '../../../../platform/extensionManagement/common/extensionManagement.service.js';
import { INotificationService } from '../../../../platform/notification/common/notification.service.js';
import { ILogService } from '../../../../platform/log/common/log.service.js';
import { IExtensionsWorkbenchService } from '../common/extensions.service.js';

var InstallExtensionQuickAccessProvider_1, ManageExtensionsQuickAccessProvider_1;
let InstallExtensionQuickAccessProvider = class InstallExtensionQuickAccessProvider extends PickerQuickAccessProvider {
    static {
        InstallExtensionQuickAccessProvider_1 = this;
    }
    static {
        this.PREFIX = "ext install ";
    }
    constructor(
        extensionsWorkbenchService,
        galleryService,
        extensionsService,
        notificationService,
        logService
    ) {
        super(InstallExtensionQuickAccessProvider_1.PREFIX);
        this.extensionsWorkbenchService = extensionsWorkbenchService;
        this.galleryService = galleryService;
        this.extensionsService = extensionsService;
        this.notificationService = notificationService;
        this.logService = logService;
    }
    _getPicks(filter, disposables, token) {
        if (!filter) {
            return [{
                label: ( localize(10059, "Type an extension name to install or search."))
            }];
        }
        const genericSearchPickItem = {
            label: ( localize(10060, "Press Enter to search for extension '{0}'.", filter)),
            accept: () => this.extensionsWorkbenchService.openSearch(filter)
        };
        if (/\./.test(filter)) {
            return this.getPicksForExtensionId(filter, genericSearchPickItem, token);
        }
        return [genericSearchPickItem];
    }
    async getPicksForExtensionId(filter, fallback, token) {
        try {
            const [galleryExtension] = await this.galleryService.getExtensions([{
                id: filter
            }], token);
            if (token.isCancellationRequested) {
                return [];
            }
            if (!galleryExtension) {
                return [fallback];
            }
            return [{
                label: ( localize(10061, "Press Enter to install extension '{0}'.", filter)),
                accept: () => this.installExtension(galleryExtension, filter)
            }];
        } catch (error) {
            if (token.isCancellationRequested) {
                return [];
            }
            this.logService.error(error);
            return [fallback];
        }
    }
    async installExtension(extension, name) {
        try {
            await this.extensionsWorkbenchService.openSearch(`@id:${name}`);
            await this.extensionsService.installFromGallery(extension);
        } catch (error) {
            this.notificationService.error(error);
        }
    }
};
InstallExtensionQuickAccessProvider = InstallExtensionQuickAccessProvider_1 = ( __decorate([( __param(0, IExtensionsWorkbenchService)), ( __param(1, IExtensionGalleryService)), ( __param(2, IExtensionManagementService)), ( __param(3, INotificationService)), ( __param(4, ILogService))], InstallExtensionQuickAccessProvider));
let ManageExtensionsQuickAccessProvider = class ManageExtensionsQuickAccessProvider extends PickerQuickAccessProvider {
    static {
        ManageExtensionsQuickAccessProvider_1 = this;
    }
    static {
        this.PREFIX = "ext ";
    }
    constructor(extensionsWorkbenchService) {
        super(ManageExtensionsQuickAccessProvider_1.PREFIX);
        this.extensionsWorkbenchService = extensionsWorkbenchService;
    }
    _getPicks() {
        return [{
            label: ( localize(10062, "Press Enter to manage your extensions.")),
            accept: () => this.extensionsWorkbenchService.openSearch("")
        }];
    }
};
ManageExtensionsQuickAccessProvider = ManageExtensionsQuickAccessProvider_1 = ( __decorate([( __param(0, IExtensionsWorkbenchService))], ManageExtensionsQuickAccessProvider));

export { InstallExtensionQuickAccessProvider, ManageExtensionsQuickAccessProvider };
