"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 progress_exports = {};
__export(progress_exports, {
  renderIndexProgress: () => renderIndexProgress,
  renderSyncProgress: () => renderSyncProgress,
  renderSyncProgressVerbose: () => renderSyncProgressVerbose,
  renderSyncSummary: () => renderSyncSummary
});
module.exports = __toCommonJS(progress_exports);
const _v = "\x1B[38;5;99m";
const _r = "\x1B[0m";
const _d = "\x1B[2m";
const _g = "\x1B[38;5;114m";
function _bar(pct, width = 20) {
  const filled = Math.floor(pct / (100 / width));
  return "\u2588".repeat(filled) + "\u2591".repeat(width - filled);
}
function _num(n) {
  return n.toLocaleString();
}
function renderIndexProgress(p) {
  const pct = p.total > 0 ? Math.round(p.current / p.total * 100) : 0;
  if (p.phase === "scanning") {
    process.stdout.write(`  ${_v}\u2713 scanning${_r}   ${_v}${p.current}${_r} ${_d}files found${_r}
`);
  } else if (p.phase === "parsing") {
    process.stdout.write(`\r  ${_v}parsing${_r}    [${_bar(pct)}] ${_v}${pct}%${_r}${" ".repeat(8)}`);
    if (p.current === p.total) process.stdout.write("\n");
  } else if (p.phase === "resolving") {
    if (p.current === 0 && p.total <= 1) {
      process.stdout.write(`\r  ${_v}resolving${_r}  cross-file references\u2026${" ".repeat(20)}`);
    } else if (p.total > 0) {
      const bar = _bar(pct);
      const suffix = p.current === p.total ? `${_v}${p.current}${_r}${_d}/${p.total} refs${_r}
` : `${_v}${p.current}${_r}${_d}/${p.total}${_r}${" ".repeat(10)}`;
      const prefix = p.current === p.total ? `\r  ${_v}\u2713 resolving${_r}` : `\r  ${_v}resolving${_r} `;
      process.stdout.write(`${prefix} [${bar}] ${suffix}`);
    }
  } else if (p.phase === "detecting frameworks") {
    if (p.current === 1) {
      const frameworks = p.meta?.frameworks ?? [];
      const languages = p.meta?.languages ?? [];
      const fwLabel = frameworks.length > 0 ? `${_v}${frameworks.join(", ")}${_r}` : `${_d}none${_r}`;
      const langLabel = languages.length > 0 ? `${_v}${languages.join(", ")}${_r}` : `${_d}none${_r}`;
      process.stdout.write(`  ${_v}\u2713 languages${_r}  detected: ${langLabel}
`);
      process.stdout.write(`  ${_v}\u2713 frameworks${_r} detected: ${fwLabel}
`);
    }
  } else if (p.phase === "embeddings") {
    if (p.current === -1) {
      process.stdout.write(`
  \x1B[33m\u26A0 Large codebase: ${_num(p.total)} embeddable symbols detected.\x1B[0m
`);
      process.stdout.write(`  \x1B[33m  Embedding may be slow or memory-intensive. Consider setting enableEmbeddings: false\x1B[0m
`);
      process.stdout.write(`  \x1B[33m  for codebases this large, or use a lighter model (e.g. Xenova/all-MiniLM-L6-v2).\x1B[0m

`);
    } else {
      process.stdout.write(`\r  ${_v}embeddings${_r} [${_bar(pct)}] ${_v}${pct}%${_r}${" ".repeat(10)}`);
      if (p.current === p.total && p.total > 0) process.stdout.write("\n");
    }
  } else {
    process.stdout.write(`\r  ${_v}${p.phase}${_r}  ${p.current}/${p.total}${" ".repeat(20)}`);
  }
}
function renderSyncProgress(p) {
  const pct = p.total > 0 ? Math.round(p.current / p.total * 100) : 0;
  if (p.phase === "scanning") {
    if (p.current > 0) {
      process.stdout.write(`\r  ${_v}\u2713 scanning${_r}   ${_v}${_num(p.current)}${_r} ${_d}files found${_r}
`);
    } else {
      process.stdout.write(`\r  ${_v}scanning${_r}    ${_d}detecting changes\u2026${_r}${" ".repeat(20)}`);
    }
  } else if (p.phase === "parsing") {
    process.stdout.write(`\r  ${_v}parsing${_r}    [${_bar(pct)}] ${_v}${pct}%${_r}${" ".repeat(8)}`);
    if (p.current === p.total) process.stdout.write("\n");
  } else if (p.phase === "resolving") {
    if (p.current === 0 && p.total <= 1) {
      process.stdout.write(`\r  ${_v}resolving${_r}  cross-file references\u2026${" ".repeat(20)}`);
    } else if (p.total > 0) {
      const bar = _bar(pct);
      const suffix = p.current === p.total ? `${_v}${_num(p.current)}${_r}${_d}/${_num(p.total)} refs${_r}
` : `${_v}${_num(p.current)}${_r}${_d}/${_num(p.total)}${_r}${" ".repeat(10)}`;
      const prefix = p.current === p.total ? `\r  ${_v}\u2713 resolving${_r}` : `\r  ${_v}resolving${_r} `;
      process.stdout.write(`${prefix} [${bar}] ${suffix}`);
    }
  } else if (p.phase === "embeddings") {
    if (p.current === -1) {
      process.stdout.write(`
  \x1B[33m\u26A0 Large codebase: ${_num(p.total)} embeddable symbols detected.\x1B[0m
`);
      process.stdout.write(`  \x1B[33m  Embedding may be slow or memory-intensive. Consider setting enableEmbeddings: false\x1B[0m
`);
      process.stdout.write(`  \x1B[33m  for codebases this large, or use a lighter model (e.g. Xenova/all-MiniLM-L6-v2).\x1B[0m

`);
    } else {
      process.stdout.write(`\r  ${_v}embeddings${_r} [${_bar(pct)}] ${_v}${pct}%${_r}${" ".repeat(10)}`);
      if (p.current === p.total && p.total > 0) process.stdout.write("\n");
    }
  } else {
    process.stdout.write(`\r  ${_v}${p.phase}${_r}  ${p.current}/${p.total}${" ".repeat(20)}`);
  }
}
function renderSyncProgressVerbose(p) {
  if (p.phase === "scanning") {
    if (p.meta?.excludeCleanup && p.meta.file) {
      process.stdout.write(`  ${_d}exclude${_r}  ${_d}${p.meta.file}${_r}
`);
    } else if (p.current > 0) {
      process.stdout.write(`  ${_v}\u2713 scanning${_r}   ${_v}${_num(p.current)}${_r} ${_d}files found${_r}
`);
    } else {
      process.stdout.write(`  ${_v}scanning${_r}    ${_d}detecting changes\u2026${_r}
`);
    }
  } else if (p.phase === "parsing") {
    if (p.currentFile) {
      const short = p.currentFile.length > 60 ? "\u2026" + p.currentFile.slice(p.currentFile.length - 59) : p.currentFile;
      process.stdout.write(`  ${_v}parse${_r}  ${_d}[${_num(p.current)}/${_num(p.total)}]${_r}  ${short}
`);
    }
  } else if (p.phase === "resolving") {
    if (p.current === 0 && p.total <= 1) {
      process.stdout.write(`  ${_v}resolving${_r}  cross-file references\u2026
`);
    } else if (p.total > 0 && p.current === p.total) {
      process.stdout.write(`  ${_v}\u2713 resolving${_r}  ${_v}${_num(p.current)}${_r}${_d}/${_num(p.total)} refs${_r}
`);
    }
  } else if (p.phase === "embeddings") {
    if (p.current === -1) {
      process.stdout.write(`
  \x1B[33m\u26A0 Large codebase: ${_num(p.total)} embeddable symbols detected.\x1B[0m
`);
      process.stdout.write(`  \x1B[33m  Embedding may be slow or memory-intensive. Consider setting enableEmbeddings: false\x1B[0m
`);
      process.stdout.write(`  \x1B[33m  for codebases this large, or use a lighter model (e.g. Xenova/all-MiniLM-L6-v2).\x1B[0m

`);
    } else {
      const pct = p.total > 0 ? Math.round(p.current / p.total * 100) : 0;
      process.stdout.write(`\r  ${_v}embeddings${_r} [${_bar(pct)}] ${_v}${pct}%${_r}${" ".repeat(10)}`);
      if (p.current === p.total && p.total > 0) process.stdout.write("\n");
    }
  } else if (p.phase === "architecture") {
    if (p.meta?.msg) {
      process.stdout.write(`  ${_v}architecture${_r}  ${_d}${p.meta.msg}${_r}
`);
    } else if (p.current === p.total && p.total > 0) {
      process.stdout.write(`  ${_v}\u2713 architecture${_r}
`);
    }
  } else {
    process.stdout.write(`  ${_v}${p.phase}${_r}  ${p.current}/${p.total}
`);
  }
}
function renderSyncSummary(result) {
  const secs = (result.duration / 1e3).toFixed(1);
  const filesChanged = result.added.length + result.modified.length;
  const filesDeleted = result.removed.length;
  console.log(`
  ${_g}\u2713${_r} sync complete ${_d}(${secs}s)${_r}`);
  console.log(`    ${_d}files scanned:${_r}  ${_v}${_num(result.filesScanned)}${_r}`);
  console.log(`    ${_d}files changed:${_r}  ${_v}${_num(filesChanged)}${_r}`);
  console.log(`    ${_d}files deleted:${_r}  ${_v}${_num(filesDeleted)}${_r}`);
  console.log(`    ${_d}nodes added:${_r}    ${_v}${_num(result.nodesCreated)}${_r}`);
  console.log(`    ${_d}nodes updated:${_r}  ${_v}${_num(result.nodesUpdated)}${_r}`);
  console.log(`    ${_d}nodes removed:${_r}  ${_v}${_num(result.nodesRemoved)}${_r}`);
  console.log(`    ${_d}edges added:${_r}    ${_v}${_num(result.edgesCreated)}${_r}`);
  console.log(`    ${_d}edges removed:${_r}  ${_v}${_num(result.edgesRemoved)}${_r}`);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  renderIndexProgress,
  renderSyncProgress,
  renderSyncProgressVerbose,
  renderSyncSummary
});
//# sourceMappingURL=progress.js.map
