"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 laravel_exports = {};
__export(laravel_exports, {
  FACADE_MAPPINGS: () => FACADE_MAPPINGS,
  laravelResolver: () => laravelResolver
});
module.exports = __toCommonJS(laravel_exports);
const FACADE_MAPPINGS = {
  Auth: "Illuminate\\Auth\\AuthManager",
  Cache: "Illuminate\\Cache\\CacheManager",
  Config: "Illuminate\\Config\\Repository",
  DB: "Illuminate\\Database\\DatabaseManager",
  Event: "Illuminate\\Events\\Dispatcher",
  File: "Illuminate\\Filesystem\\Filesystem",
  Gate: "Illuminate\\Auth\\Access\\Gate",
  Hash: "Illuminate\\Hashing\\HashManager",
  Log: "Illuminate\\Log\\LogManager",
  Mail: "Illuminate\\Mail\\Mailer",
  Queue: "Illuminate\\Queue\\QueueManager",
  Redis: "Illuminate\\Redis\\RedisManager",
  Request: "Illuminate\\Http\\Request",
  Response: "Illuminate\\Http\\Response",
  Route: "Illuminate\\Routing\\Router",
  Session: "Illuminate\\Session\\SessionManager",
  Storage: "Illuminate\\Filesystem\\FilesystemManager",
  URL: "Illuminate\\Routing\\UrlGenerator",
  Validator: "Illuminate\\Validation\\Factory",
  View: "Illuminate\\View\\Factory"
};
const LARAVEL_HELPERS = /* @__PURE__ */ new Set(["route", "view", "config", "env", "app", "abort", "redirect", "response", "request", "session", "url", "asset", "mix"]);
const laravelResolver = {
  name: "laravel",
  detect(context) {
    return context.fileExists("artisan") || context.fileExists("app/Http/Kernel.php");
  },
  resolve(ref, context) {
    const modelMatch = ref.referenceName.match(/^([A-Z][a-zA-Z]+)::(\w+)$/);
    if (modelMatch) {
      const id = resolveModelCall(modelMatch[1], modelMatch[2], context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.85, resolvedBy: "framework" };
    }
    if (LARAVEL_HELPERS.has(ref.referenceName)) return null;
    const controllerMatch = ref.referenceName.match(/^([A-Z][a-zA-Z]+Controller)@(\w+)$/);
    if (controllerMatch) {
      const id = resolveControllerMethod(controllerMatch[1], controllerMatch[2], context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.9, resolvedBy: "framework" };
    }
    return null;
  },
  extractNodes(filePath, content) {
    const nodes = [];
    const now = Date.now();
    const routePattern = /Route::(get|post|put|patch|delete|options|any)\(\s*['"]([^'"]+)['"]/g;
    const resourcePattern = /Route::(?:api)?[Rr]esource\(\s*['"]([^'"]+)['"]/g;
    let match;
    while ((match = routePattern.exec(content)) !== null) {
      const [, method, path] = match;
      const line = content.slice(0, match.index).split("\n").length;
      nodes.push({ id: `route:${filePath}:${method.toUpperCase()}:${path}:${line}`, kind: "route", name: `${method.toUpperCase()} ${path}`, qualifiedName: `${filePath}::${method.toUpperCase()}:${path}`, filePath, startLine: line, endLine: line, startColumn: 0, endColumn: match[0].length, language: "php", updatedAt: now });
    }
    while ((match = resourcePattern.exec(content)) !== null) {
      const [, name] = match;
      const line = content.slice(0, match.index).split("\n").length;
      nodes.push({ id: `route:${filePath}:resource:${name}:${line}`, kind: "route", name: `resource:${name}`, qualifiedName: `${filePath}::resource:${name}`, filePath, startLine: line, endLine: line, startColumn: 0, endColumn: match[0].length, language: "php", updatedAt: now });
    }
    return nodes;
  }
};
function resolveModelCall(className, methodName, context) {
  for (const modelPath of [`app/Models/${className}.php`, `app/${className}.php`]) {
    if (context.fileExists(modelPath)) {
      const nodes = context.getNodesInFile(modelPath);
      const node = nodes.find((n) => n.kind === "method" && n.name === methodName) ?? nodes.find((n) => n.kind === "class" && n.name === className);
      if (node) return node.id;
    }
  }
  return null;
}
function resolveControllerMethod(controller, method, context) {
  const controllerPath = `app/Http/Controllers/${controller}.php`;
  if (context.fileExists(controllerPath)) {
    const node = context.getNodesInFile(controllerPath).find((n) => n.kind === "method" && n.name === method);
    if (node) return node.id;
  }
  for (const file of context.getAllFiles()) {
    if (file.endsWith(`${controller}.php`) && file.includes("Controllers")) {
      const node = context.getNodesInFile(file).find((n) => n.kind === "method" && n.name === method);
      if (node) return node.id;
    }
  }
  return null;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FACADE_MAPPINGS,
  laravelResolver
});
//# sourceMappingURL=laravel.js.map
