
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
import { localize } from '../../../../nls.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import { IWorkspaceTrustEnablementService, IWorkspaceTrustManagementService } from '../../../../platform/workspace/common/workspaceTrust.service.js';
import { IWorkbenchEnvironmentService } from '../../../services/environment/common/environmentService.service.js';
import { IWorkbenchExtensionEnablementService } from '../../../services/extensionManagement/common/extensionManagement.service.js';
import { IExtensionService } from '../../../services/extensions/common/extensions.service.js';
import { IHostService } from '../../../services/host/browser/host.service.js';

let ExtensionEnablementWorkspaceTrustTransitionParticipant = class ExtensionEnablementWorkspaceTrustTransitionParticipant extends Disposable {
    constructor(
        extensionService,
        hostService,
        environmentService,
        extensionEnablementService,
        workspaceTrustEnablementService,
        workspaceTrustManagementService
    ) {
        super();
        if (workspaceTrustEnablementService.isWorkspaceTrustEnabled()) {
            workspaceTrustManagementService.workspaceTrustInitialized.then(() => {
                const workspaceTrustTransitionParticipant = new (class {
                    async participate(trusted) {
                        if (trusted) {
                            await extensionEnablementService.updateExtensionsEnablementsWhenWorkspaceTrustChanges();
                        } else {
                            if (environmentService.remoteAuthority) {
                                hostService.reload();
                            } else {
                                const stopped = await extensionService.stopExtensionHosts(( localize(9678, "Changing workspace trust")));
                                await extensionEnablementService.updateExtensionsEnablementsWhenWorkspaceTrustChanges();
                                if (stopped) {
                                    extensionService.startExtensionHosts();
                                }
                            }
                        }
                    }
                })();
                this._register(
                    workspaceTrustManagementService.addWorkspaceTrustTransitionParticipant(workspaceTrustTransitionParticipant)
                );
            });
        }
    }
};
ExtensionEnablementWorkspaceTrustTransitionParticipant = ( __decorate([( __param(0, IExtensionService)), ( __param(1, IHostService)), ( __param(2, IWorkbenchEnvironmentService)), ( __param(3, IWorkbenchExtensionEnablementService)), ( __param(4, IWorkspaceTrustEnablementService)), ( __param(5, IWorkspaceTrustManagementService))], ExtensionEnablementWorkspaceTrustTransitionParticipant));

export { ExtensionEnablementWorkspaceTrustTransitionParticipant };
