"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 elixir_exports = {};
__export(elixir_exports, {
  elixirLayerDetector: () => elixirLayerDetector
});
module.exports = __toCommonJS(elixir_exports);
var import_picomatch = __toESM(require("picomatch"));
const LAYER_PATTERNS = [
  // API / web layer
  ["api", "**/controllers/**", 0.95],
  ["api", "**/*_controller.ex", 0.95],
  ["api", "**/channels/**", 0.9],
  ["api", "**/*_channel.ex", 0.9],
  ["api", "**/router.ex", 0.95],
  ["api", "**/endpoint.ex", 0.85],
  ["api", "**/plugs/**", 0.8],
  ["api", "**/*_plug.ex", 0.8],
  // Service / context layer (Phoenix contexts)
  ["service", "**/contexts/**", 0.95],
  ["service", "**/context/**", 0.9],
  ["service", "**/workers/**", 0.85],
  ["service", "**/jobs/**", 0.85],
  ["service", "**/*_worker.ex", 0.85],
  // Data layer
  ["data", "**/schemas/**", 0.95],
  ["data", "**/*_schema.ex", 0.95],
  ["data", "**/repo.ex", 0.9],
  ["data", "**/migrations/**", 0.9],
  ["data", "**/priv/repo/migrations/**", 0.95],
  ["data", "**/models/**", 0.85],
  // UI / LiveView layer
  ["ui", "**/live/**", 0.95],
  ["ui", "**/*_live.ex", 0.95],
  ["ui", "**/*_live_view.ex", 0.95],
  ["ui", "**/components/**", 0.9],
  ["ui", "**/*_component.ex", 0.9],
  ["ui", "**/views/**", 0.85],
  ["ui", "**/*_view.ex", 0.85],
  ["ui", "**/templates/**", 0.8],
  // Shared / infrastructure
  ["shared", "**/helpers/**", 0.8],
  ["shared", "**/lib/**", 0.75],
  ["shared", "**/config/**", 0.75],
  ["shared", "**/mailers/**", 0.8],
  ["shared", "**/*_mailer.ex", 0.8]
];
const elixirLayerDetector = {
  language: "elixir",
  async detect(files, _projectRoot, configLayers) {
    const results = [];
    const configMatchers = _buildConfigMatchers(configLayers ?? {});
    for (const file of files) {
      if (!file.endsWith(".ex") && !file.endsWith(".exs")) 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) {
  return Object.entries(configLayers).flatMap(
    ([layerName, patterns]) => patterns.map(
      (pattern) => [layerName, (0, import_picomatch.default)(pattern), pattern]
    )
  );
}
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 = {
  elixirLayerDetector
});
//# sourceMappingURL=elixir.js.map
