import { createDefaultCoreModule, createDefaultSharedCoreModule } from "../../../../../langium/lib/default-module.js";
import { inject } from "../../../../../langium/lib/dependency-injection.js";
import { EmptyFileSystem } from "../../../../../langium/lib/workspace/file-system-provider.js";
import "../../../../../langium/lib/index.js";
import { AbstractMermaidTokenBuilder, AbstractMermaidValueConverter, MermaidGeneratedSharedModule, TreemapGrammarGeneratedModule, __name } from "./chunk-TCCFYFTB.js";
var TreemapTokenBuilder = class extends AbstractMermaidTokenBuilder {
	static #e = __name(this, "TreemapTokenBuilder");
	constructor() {
		super(["treemap"]);
	}
}, classDefRegex = /classDef\s+([A-Z_a-z]\w+)(?:\s+([^\n\r;]*))?;?/, TreemapValueConverter = class extends AbstractMermaidValueConverter {
	static #e = __name(this, "TreemapValueConverter");
	runCustomConverter(e, u, d) {
		if (e.name === "NUMBER2") return parseFloat(u.replace(/,/g, ""));
		if (e.name === "SEPARATOR" || e.name === "STRING2") return u.substring(1, u.length - 1);
		if (e.name === "INDENTATION") return u.length;
		if (e.name === "ClassDef") {
			if (typeof u != "string") return u;
			let e = classDefRegex.exec(u);
			if (e) return {
				$type: "ClassDefStatement",
				className: e[1],
				styleText: e[2] || void 0
			};
		}
	}
};
function registerValidationChecks(e) {
	let u = e.validation.TreemapValidator, d = e.validation.ValidationRegistry;
	if (d) {
		let e = { Treemap: u.checkSingleRoot.bind(u) };
		d.register(e, u);
	}
}
__name(registerValidationChecks, "registerValidationChecks");
var TreemapValidator = class {
	static #e = __name(this, "TreemapValidator");
	checkSingleRoot(e, u) {
		let d;
		for (let f of e.TreemapRows) f.item && (d === void 0 && f.indent === void 0 ? d = 0 : (f.indent === void 0 || d !== void 0 && d >= parseInt(f.indent, 10)) && u("error", "Multiple root nodes are not allowed in a treemap.", {
			node: f,
			property: "item"
		}));
	}
}, TreemapModule = {
	parser: {
		TokenBuilder: /* @__PURE__ */ __name(() => new TreemapTokenBuilder(), "TokenBuilder"),
		ValueConverter: /* @__PURE__ */ __name(() => new TreemapValueConverter(), "ValueConverter")
	},
	validation: { TreemapValidator: /* @__PURE__ */ __name(() => new TreemapValidator(), "TreemapValidator") }
};
function createTreemapServices(p = EmptyFileSystem) {
	let m = inject(createDefaultSharedCoreModule(p), MermaidGeneratedSharedModule), h = inject(createDefaultCoreModule({ shared: m }), TreemapGrammarGeneratedModule, TreemapModule);
	return m.ServiceRegistry.register(h), registerValidationChecks(h), {
		shared: m,
		Treemap: h
	};
}
__name(createTreemapServices, "createTreemapServices");
export { TreemapModule, createTreemapServices };
