"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);

// src/map-catalog-to-astro.js
var map_catalog_to_astro_exports = {};
__export(map_catalog_to_astro_exports, {
  mapCatalogToAstro: () => mapCatalogToAstro
});
module.exports = __toCommonJS(map_catalog_to_astro_exports);
var import_node_path = __toESM(require("path"), 1);
var COLLECTION_KEYS = [
  "events",
  "commands",
  "services",
  "domains",
  "flows",
  "pages",
  "changelogs",
  "queries",
  "channels",
  "ubiquitousLanguages",
  "dependencies"
];
function mapCatalogToAstro({ filePath, astroDir, projectDir }) {
  const relativeFilePath = removeBasePath(filePath, projectDir);
  if (!isCatalogRelated(relativeFilePath)) {
    return [];
  }
  const baseTargetPaths = getBaseTargetPaths(relativeFilePath);
  const relativeTargetPath = getRelativeTargetPath(relativeFilePath);
  return baseTargetPaths.map((base) => import_node_path.default.join(astroDir, base, relativeTargetPath));
}
function removeBasePath(fullPath, basePath) {
  const relativePath = import_node_path.default.relative(basePath, fullPath);
  return relativePath.startsWith("..") ? fullPath : relativePath;
}
function isCollectionKey(key) {
  return COLLECTION_KEYS.includes(key);
}
function isCatalogRelated(filePath) {
  const filePathArr = filePath.split(import_node_path.default.sep).filter(Boolean);
  if ([
    "eventcatalog.config.js",
    // config file at root
    "eventcatalog.styles.css",
    // custom styles file at root
    "components",
    // custom components
    "snippets",
    // custom snippets
    "public",
    // public assets
    ".env",
    // env file
    ...COLLECTION_KEYS
  ].includes(filePathArr[0])) {
    return true;
  }
  return false;
}
function getBaseTargetPaths(filePath) {
  const filePathArr = filePath.split(import_node_path.default.sep).filter(Boolean);
  if (isCollectionKey(filePathArr[0])) {
    const hasExtension = (str) => /\.[a-zA-Z0-9]{2,}$/.test(str);
    if (hasExtension(filePath)) {
      return [import_node_path.default.join("public", "generated")];
    }
    return [import_node_path.default.join("public", "generated")];
  }
  if (filePathArr[0] == "components") {
    return [import_node_path.default.join("src", "custom-defined-components")];
  }
  if (filePathArr[0] == "snippets") {
    return [import_node_path.default.join("src")];
  }
  if (filePathArr[0] == "public") {
    return [import_node_path.default.join("public")];
  }
  return [import_node_path.default.join("/")];
}
function getRelativeTargetPath(filePath) {
  const filePathArr = filePath.split(import_node_path.default.sep).filter(Boolean);
  if (filePathArr[0] == "public" || filePathArr[0] == "components") {
    filePathArr.shift();
  }
  if (filePathArr[0] == "snippets") {
    return import_node_path.default.join("snippets", ...filePathArr.slice(1));
  }
  const relativePath = [];
  for (let i = filePathArr.length - 1; i >= 0; i--) {
    relativePath.unshift(filePathArr[i]);
    if (isCollectionKey(filePathArr[i]) && filePathArr[i] != "snippets") break;
  }
  return import_node_path.default.join(...relativePath);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  mapCatalogToAstro
});
