"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 section_id_exports = {};
__export(section_id_exports, {
  buildAncestorChain: () => buildAncestorChain,
  generateSectionId: () => generateSectionId,
  parseSectionId: () => parseSectionId,
  slugify: () => slugify
});
module.exports = __toCommonJS(section_id_exports);
function slugify(title) {
  return title.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-+|-+$/g, "") || "untitled";
}
function buildAncestorChain(parentSlugs, currentSlug) {
  return [...parentSlugs, currentSlug].join("/");
}
function generateSectionId(filePath, ancestorSlugs, title, level) {
  const slug = slugify(title);
  const chain = buildAncestorChain(ancestorSlugs, slug);
  return `${filePath}::${chain}#${level}`;
}
function parseSectionId(id) {
  const doubleColonIdx = id.indexOf("::");
  if (doubleColonIdx === -1) return null;
  const filePath = id.slice(0, doubleColonIdx);
  const rest = id.slice(doubleColonIdx + 2);
  const hashIdx = rest.lastIndexOf("#");
  if (hashIdx === -1) return null;
  const ancestorChain = rest.slice(0, hashIdx);
  const level = parseInt(rest.slice(hashIdx + 1), 10);
  if (isNaN(level) || level < 0) return null;
  return { filePath, ancestorChain, level };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildAncestorChain,
  generateSectionId,
  parseSectionId,
  slugify
});
//# sourceMappingURL=section-id.js.map
