"use strict";
var _a, _b, _c;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const chunk4KMFLZZN = require("./dist-chunks-mermaid-parser.core-chunk-4KMFLZZN.cjs");
const fileSystemProvider = require("../../langium/lib-workspace-file-system-provider.cjs");
const dependencyInjection = require("../../langium/lib-dependency-injection.cjs");
const defaultModule = require("../../langium/lib-default-module.cjs");
var TreemapTokenBuilder = (_a = class extends chunk4KMFLZZN.AbstractMermaidTokenBuilder {
  constructor() {
    super(["treemap"]);
  }
}, chunk4KMFLZZN.__name(_a, "TreemapTokenBuilder"), _a);
var classDefRegex = /classDef\s+([A-Z_a-z]\w+)(?:\s+([^\n\r;]*))?;?/;
var TreemapValueConverter = (_b = class extends chunk4KMFLZZN.AbstractMermaidValueConverter {
  runCustomConverter(rule, input, _cstNode) {
    if (rule.name === "NUMBER2") {
      return parseFloat(input.replace(/,/g, ""));
    } else if (rule.name === "SEPARATOR") {
      return input.substring(1, input.length - 1);
    } else if (rule.name === "STRING2") {
      return input.substring(1, input.length - 1);
    } else if (rule.name === "INDENTATION") {
      return input.length;
    } else if (rule.name === "ClassDef") {
      if (typeof input !== "string") {
        return input;
      }
      const match = classDefRegex.exec(input);
      if (match) {
        return {
          $type: "ClassDefStatement",
          className: match[1],
          styleText: match[2] || void 0
        };
      }
    }
    return void 0;
  }
}, chunk4KMFLZZN.__name(_b, "TreemapValueConverter"), _b);
function registerValidationChecks(services) {
  const validator = services.validation.TreemapValidator;
  const registry = services.validation.ValidationRegistry;
  if (registry) {
    const checks = {
      Treemap: validator.checkSingleRoot.bind(validator)
      // Remove unused validation for TreemapRow
    };
    registry.register(checks, validator);
  }
}
chunk4KMFLZZN.__name(registerValidationChecks, "registerValidationChecks");
var TreemapValidator = (_c = class {
  /**
   * Validates that a treemap has only one root node.
   * A root node is defined as a node that has no indentation.
   */
  checkSingleRoot(doc, accept) {
    let rootNodeIndentation;
    for (const row of doc.TreemapRows) {
      if (!row.item) {
        continue;
      }
      if (rootNodeIndentation === void 0 && // Check if this is a root node (no indentation)
      row.indent === void 0) {
        rootNodeIndentation = 0;
      } else if (row.indent === void 0) {
        accept("error", "Multiple root nodes are not allowed in a treemap.", {
          node: row,
          property: "item"
        });
      } else if (rootNodeIndentation !== void 0 && rootNodeIndentation >= parseInt(row.indent, 10)) {
        accept("error", "Multiple root nodes are not allowed in a treemap.", {
          node: row,
          property: "item"
        });
      }
    }
  }
}, chunk4KMFLZZN.__name(_c, "TreemapValidator"), _c);
var TreemapModule = {
  parser: {
    TokenBuilder: /* @__PURE__ */ chunk4KMFLZZN.__name(() => new TreemapTokenBuilder(), "TokenBuilder"),
    ValueConverter: /* @__PURE__ */ chunk4KMFLZZN.__name(() => new TreemapValueConverter(), "ValueConverter")
  },
  validation: {
    TreemapValidator: /* @__PURE__ */ chunk4KMFLZZN.__name(() => new TreemapValidator(), "TreemapValidator")
  }
};
function createTreemapServices(context = fileSystemProvider.EmptyFileSystem) {
  const shared = dependencyInjection.inject(
    defaultModule.createDefaultSharedCoreModule(context),
    chunk4KMFLZZN.MermaidGeneratedSharedModule
  );
  const Treemap = dependencyInjection.inject(
    defaultModule.createDefaultCoreModule({ shared }),
    chunk4KMFLZZN.TreemapGeneratedModule,
    TreemapModule
  );
  shared.ServiceRegistry.register(Treemap);
  registerValidationChecks(Treemap);
  return { shared, Treemap };
}
chunk4KMFLZZN.__name(createTreemapServices, "createTreemapServices");
exports.TreemapModule = TreemapModule;
exports.createTreemapServices = createTreemapServices;
//# sourceMappingURL=dist-chunks-mermaid-parser.core-chunk-XRWGC2XP.cjs.map
