"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 solidity_exports = {};
__export(solidity_exports, {
  solidityResolver: () => solidityResolver
});
module.exports = __toCommonJS(solidity_exports);
const solidityResolver = {
  name: "solidity",
  detect(context) {
    if (context.fileExists("hardhat.config.ts") || context.fileExists("hardhat.config.js")) return true;
    if (context.fileExists("foundry.toml")) return true;
    if (context.fileExists("truffle-config.js")) return true;
    return context.getAllFiles().some((f) => f.endsWith(".sol"));
  },
  resolve(ref, context) {
    if (ref.referenceName.startsWith("I") && /^I[A-Z]/.test(ref.referenceName)) {
      const id = resolveInterface(ref.referenceName, context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.85, resolvedBy: "framework" };
    }
    if (/^[A-Z][a-zA-Z0-9]+$/.test(ref.referenceName)) {
      const id = resolveContract(ref.referenceName, context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.8, resolvedBy: "framework" };
    }
    if (ref.referenceKind === "function") {
      const id = resolveLibraryFunction(ref.referenceName, context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.75, resolvedBy: "framework" };
    }
    return null;
  },
  extractNodes(filePath, content) {
    return [];
  }
};
function resolveInterface(name, context) {
  const dirs = ["interfaces", "contracts/interfaces", "src/interfaces"];
  for (const file of context.getAllFiles()) {
    if (!file.endsWith(".sol")) continue;
    if (dirs.some((d) => file.includes(`/${d}/`))) {
      const node = context.getNodesInFile(file).find((n) => n.name === name && n.kind === "interface");
      if (node) return node.id;
    }
  }
  for (const file of context.getAllFiles()) {
    if (!file.endsWith(".sol")) continue;
    const node = context.getNodesInFile(file).find((n) => n.name === name && n.kind === "interface");
    if (node) return node.id;
  }
  return null;
}
function resolveContract(name, context) {
  const dirs = ["contracts", "src", "lib"];
  for (const file of context.getAllFiles()) {
    if (!file.endsWith(".sol")) continue;
    if (dirs.some((d) => file.includes(`/${d}/`))) {
      const node = context.getNodesInFile(file).find((n) => n.name === name && n.kind === "class");
      if (node) return node.id;
    }
  }
  return null;
}
function resolveLibraryFunction(name, context) {
  const dirs = ["libraries", "contracts/libraries", "lib"];
  for (const file of context.getAllFiles()) {
    if (!file.endsWith(".sol")) continue;
    if (dirs.some((d) => file.includes(`/${d}/`))) {
      const node = context.getNodesInFile(file).find((n) => n.name === name && n.kind === "function");
      if (node) return node.id;
    }
  }
  return null;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  solidityResolver
});
//# sourceMappingURL=solidity.js.map
