import { Deferred as e } from "../utils/promise-utils.js";
import { event_exports as t } from "../utils/event.js";
//#region ../../node_modules/langium/lib/workspace/configuration.js
var n = class {
	constructor(n) {
		this._ready = new e(), this.onConfigurationSectionUpdateEmitter = new t.Emitter(), this.settings = {}, this.workspaceConfig = !1, this.serviceRegistry = n.ServiceRegistry;
	}
	get ready() {
		return this._ready.promise;
	}
	initialize(e) {
		this.workspaceConfig = e.capabilities.workspace?.configuration ?? !1;
	}
	async initialized(e) {
		if (this.workspaceConfig) {
			if (e.register) {
				let t = this.serviceRegistry.all;
				e.register({ section: t.map((e) => this.toSectionName(e.LanguageMetaData.languageId)) });
			}
			if (e.fetchConfiguration) {
				let t = this.serviceRegistry.all.map((e) => ({ section: this.toSectionName(e.LanguageMetaData.languageId) })), n = await e.fetchConfiguration(t);
				t.forEach((e, t) => {
					this.updateSectionConfiguration(e.section, n[t]);
				});
			}
		}
		this._ready.resolve();
	}
	updateConfiguration(e) {
		typeof e.settings != "object" || e.settings === null || Object.entries(e.settings).forEach(([e, t]) => {
			this.updateSectionConfiguration(e, t), this.onConfigurationSectionUpdateEmitter.fire({
				section: e,
				configuration: t
			});
		});
	}
	updateSectionConfiguration(e, t) {
		this.settings[e] = t;
	}
	async getConfiguration(e, t) {
		await this.ready;
		let n = this.toSectionName(e);
		if (this.settings[n]) return this.settings[n][t];
	}
	toSectionName(e) {
		return `${e}`;
	}
	get onConfigurationSectionUpdate() {
		return this.onConfigurationSectionUpdateEmitter.event;
	}
};
//#endregion
export { n as DefaultConfigurationProvider };
