"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var angular_exports = {};
__export(angular_exports, {
  angularResolver: () => angularResolver
});
module.exports = __toCommonJS(angular_exports);
const angularResolver = {
  name: "angular",
  detect(context) {
    if (context.fileExists("angular.json") || context.fileExists(".angular.json")) return true;
    const pkg = context.readFile("package.json");
    if (pkg) {
      try {
        const parsed = JSON.parse(pkg);
        const deps = { ...parsed.dependencies, ...parsed.devDependencies };
        if ("@angular/core" in deps) return true;
      } catch {
      }
    }
    return false;
  },
  resolve(ref, context) {
    if (ref.referenceName.endsWith("Service")) {
      const id = resolveByConvention(ref.referenceName, "service", context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.9, resolvedBy: "framework" };
    }
    if (ref.referenceName.endsWith("Component")) {
      const id = resolveByConvention(ref.referenceName, "component", context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.9, resolvedBy: "framework" };
    }
    if (ref.referenceName.endsWith("Module")) {
      const id = resolveByConvention(ref.referenceName, "module", context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.85, resolvedBy: "framework" };
    }
    if (ref.referenceName.endsWith("Guard")) {
      const id = resolveByConvention(ref.referenceName, "guard", context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.85, resolvedBy: "framework" };
    }
    if (ref.referenceName.endsWith("Pipe")) {
      const id = resolveByConvention(ref.referenceName, "pipe", context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.85, resolvedBy: "framework" };
    }
    if (ref.referenceName.endsWith("Directive")) {
      const id = resolveByConvention(ref.referenceName, "directive", context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.85, resolvedBy: "framework" };
    }
    if (ref.referenceName.endsWith("Interceptor")) {
      const id = resolveByConvention(ref.referenceName, "interceptor", context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.85, resolvedBy: "framework" };
    }
    if (/^[A-Z][a-zA-Z]+$/.test(ref.referenceName)) {
      const id = resolveAngularClass(ref.referenceName, context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.7, resolvedBy: "framework" };
    }
    return null;
  },
  extractNodes(filePath, content) {
    const nodes = [];
    const now = Date.now();
    if (filePath.includes("routing") || filePath.includes("routes") || filePath.includes(".routes.")) {
      const routePattern = /path:\s*['"]([^'"]*)['"]/g;
      let match;
      while ((match = routePattern.exec(content)) !== null) {
        const line = content.slice(0, match.index).split("\n").length;
        const routePath = `/${match[1]}`;
        const name = `ROUTE ${routePath}`;
        nodes.push({
          id: `route:${filePath}:ROUTE:${routePath}:${line}`,
          kind: "route",
          name,
          qualifiedName: `${filePath}::${name}`,
          filePath,
          startLine: line,
          endLine: line,
          startColumn: 0,
          endColumn: match[0].length,
          language: "typescript",
          updatedAt: now
        });
      }
    }
    return nodes;
  }
};
function resolveByConvention(name, suffix, context) {
  const baseName = name.replace(new RegExp(`${suffix}$`, "i"), "");
  const kebab = baseName.replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^-/, "");
  const expectedFile = `${kebab}.${suffix}.ts`;
  for (const file of context.getAllFiles()) {
    if (!file.endsWith(".ts")) continue;
    if (file.endsWith(expectedFile) || file.includes(`/${expectedFile}`)) {
      const node = context.getNodesInFile(file).find((n) => n.name === name);
      if (node) return node.id;
    }
  }
  for (const file of context.getAllFiles()) {
    if (!file.endsWith(".ts")) continue;
    const node = context.getNodesInFile(file).find((n) => n.name === name && n.kind === "class");
    if (node) return node.id;
  }
  return null;
}
function resolveAngularClass(name, context) {
  for (const file of context.getAllFiles()) {
    if (!file.endsWith(".ts")) continue;
    const node = context.getNodesInFile(file).find((n) => n.name === name && n.kind === "class");
    if (node) return node.id;
  }
  return null;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  angularResolver
});
//# sourceMappingURL=angular.js.map
