"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var typescript_exports = {};
__export(typescript_exports, {
  typescriptLayerDetector: () => typescriptLayerDetector
});
module.exports = __toCommonJS(typescript_exports);
var import_picomatch = __toESM(require("picomatch"));
const LAYER_PATTERNS = [
  // API / Controller layer
  ["api", "**/routes/**", 0.9],
  ["api", "**/controllers/**", 0.9],
  ["api", "**/handlers/**", 0.85],
  ["api", "**/*.route.ts", 0.9],
  ["api", "**/*.route.js", 0.9],
  ["api", "**/*.controller.ts", 0.9],
  ["api", "**/*.controller.js", 0.9],
  ["api", "**/*.handler.ts", 0.85],
  ["api", "**/api/**", 0.75],
  ["api", "**/endpoints/**", 0.85],
  // Service / Business logic layer
  ["service", "**/services/**", 0.9],
  ["service", "**/*.service.ts", 0.9],
  ["service", "**/*.service.js", 0.9],
  ["service", "**/usecases/**", 0.85],
  ["service", "**/use-cases/**", 0.85],
  ["service", "**/interactors/**", 0.8],
  ["service", "**/domain/**", 0.8],
  // Data / Repository layer
  ["data", "**/repositories/**", 0.9],
  ["data", "**/repository/**", 0.9],
  ["data", "**/models/**", 0.85],
  ["data", "**/entities/**", 0.85],
  ["data", "**/dao/**", 0.9],
  ["data", "**/store/**", 0.8],
  ["data", "**/*.repository.ts", 0.9],
  ["data", "**/*.repository.js", 0.9],
  ["data", "**/*.model.ts", 0.85],
  ["data", "**/*.model.js", 0.85],
  ["data", "**/*.entity.ts", 0.85],
  ["data", "**/db/**", 0.8],
  ["data", "**/database/**", 0.8],
  ["data", "**/migrations/**", 0.85],
  ["data", "**/schema/**", 0.8],
  // UI / Frontend layer
  ["ui", "**/components/**", 0.9],
  ["ui", "**/pages/**", 0.9],
  ["ui", "**/views/**", 0.85],
  ["ui", "**/screens/**", 0.9],
  ["ui", "**/layouts/**", 0.85],
  ["ui", "**/*.component.ts", 0.9],
  ["ui", "**/*.component.tsx", 0.9],
  ["ui", "**/*.page.tsx", 0.9],
  ["ui", "**/*.screen.tsx", 0.9],
  ["ui", "**/ui/**", 0.8],
  // Shared / Infrastructure layer
  ["shared", "**/utils/**", 0.85],
  ["shared", "**/helpers/**", 0.85],
  ["shared", "**/lib/**", 0.8],
  ["shared", "**/common/**", 0.8],
  ["shared", "**/shared/**", 0.85],
  ["shared", "**/constants/**", 0.8],
  ["shared", "**/config/**", 0.8],
  ["shared", "**/middleware/**", 0.8],
  ["shared", "**/plugins/**", 0.75],
  ["shared", "**/hooks/**", 0.8],
  ["shared", "**/*.util.ts", 0.85],
  ["shared", "**/*.util.js", 0.85],
  ["shared", "**/*.helper.ts", 0.85]
];
const SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".svelte"]);
const typescriptLayerDetector = {
  language: "typescript",
  async detect(files, _projectRoot, configLayers) {
    const results = [];
    const configMatchers = _buildConfigMatchers(configLayers ?? {});
    for (const file of files) {
      const ext = file.slice(file.lastIndexOf("."));
      if (!SUPPORTED_EXTENSIONS.has(ext)) continue;
      const configMatch = _matchConfig(file, configMatchers);
      if (configMatch) {
        results.push({ ...configMatch, filePath: file });
        continue;
      }
      let best = null;
      for (const [layerName, pattern, confidence] of LAYER_PATTERNS) {
        if ((0, import_picomatch.default)(pattern)(file)) {
          if (!best || confidence > best.confidence) {
            best = { layerName, filePath: file, confidence, matchedPattern: pattern };
          }
        }
      }
      if (best) results.push(best);
    }
    return results;
  }
};
function _buildConfigMatchers(configLayers) {
  const matchers = [];
  for (const [layerName, patterns] of Object.entries(configLayers)) {
    for (const pattern of patterns) {
      matchers.push([layerName, (0, import_picomatch.default)(pattern), pattern]);
    }
  }
  return matchers;
}
function _matchConfig(file, matchers) {
  for (const [layerName, matcher, pattern] of matchers) {
    if (matcher(file)) return { layerName, confidence: 1, matchedPattern: `config:${pattern}` };
  }
  return null;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  typescriptLayerDetector
});
//# sourceMappingURL=typescript.js.map
