import { AstUtils } from "langium";
import { AstNodeHoverProvider } from "langium/lsp";
import stripIndent from "strip-indent";
import { ast } from "../ast.js";
export class LikeC4HoverProvider extends AstNodeHoverProvider {
  parser;
  locator;
  constructor(services) {
    super(services);
    this.parser = services.likec4.ModelParser;
    this.locator = services.likec4.ModelLocator;
  }
  getAstNodeHoverContent(node) {
    if (ast.isTag(node)) {
      return {
        contents: {
          kind: "markdown",
          value: stripIndent(`
            tag: \`${node.name}\`
          `)
        }
      };
    }
    if (ast.isDeploymentNode(node)) {
      const doc = AstUtils.getDocument(node);
      const el = this.parser.forDocument(doc).parseDeploymentNode(node);
      const lines = [el.id + "  "];
      if (el.title !== node.name) {
        lines.push(`### ${el.title}`);
      }
      lines.push("Deployment: `" + el.kind + "` ");
      return {
        contents: {
          kind: "markdown",
          value: lines.join("\n")
        }
      };
    }
    if (ast.isDeployedInstance(node)) {
      const doc = AstUtils.getDocument(node);
      const instance = this.parser.forDocument(doc).parseDeployedInstance(node);
      const el = this.locator.getParsedElement(instance.element);
      const lines = [instance.id + "  ", `instance of \`${instance.element}\``];
      if (el) {
        lines.push(`### ${el.title}`, "Element: `" + el.kind + "` ");
      }
      return {
        contents: {
          kind: "markdown",
          value: lines.join("\n")
        }
      };
    }
    if (ast.isElement(node)) {
      const el = this.locator.getParsedElement(node);
      if (!el) {
        return;
      }
      const lines = [el.id, `### ${el.title}`, "Element: `" + el.kind + "` "];
      return {
        contents: {
          kind: "markdown",
          value: lines.join("\n")
        }
      };
    }
    return;
  }
}
