// @bun
import {
  __esm
} from "./chunk-hhsxm2yr.js";

// src/services/progress/ProgressTracker.ts
class ProgressTracker {
  steps = new Map;
  callback = null;
  stepOrder = [];
  constructor(callback) {
    this.callback = callback || null;
  }
  addStep(id, label) {
    if (this.steps.has(id))
      return;
    this.steps.set(id, {
      id,
      label,
      status: "pending"
    });
    this.stepOrder.push(id);
    this.notifyChange();
  }
  startStep(id, message) {
    const step = this.steps.get(id);
    if (!step)
      return;
    step.status = "running";
    step.startTime = Date.now();
    if (message)
      step.message = message;
    this.notifyChange();
  }
  updateStep(id, progress, message) {
    const step = this.steps.get(id);
    if (!step)
      return;
    step.progress = Math.max(0, Math.min(100, progress));
    if (message)
      step.message = message;
    this.notifyChange();
  }
  completeStep(id, message) {
    const step = this.steps.get(id);
    if (!step)
      return;
    step.status = "completed";
    step.progress = 100;
    step.endTime = Date.now();
    if (message)
      step.message = message;
    this.notifyChange();
  }
  failStep(id, message) {
    const step = this.steps.get(id);
    if (!step)
      return;
    step.status = "failed";
    step.endTime = Date.now();
    if (message)
      step.message = message;
    this.notifyChange();
  }
  getSteps() {
    return this.stepOrder.map((id) => this.steps.get(id)).filter(Boolean);
  }
  getCurrentStep() {
    for (const id of this.stepOrder) {
      const step = this.steps.get(id);
      if (step?.status === "running")
        return step;
    }
    return null;
  }
  getOverallProgress() {
    const steps = this.getSteps();
    if (steps.length === 0)
      return 0;
    let total = 0;
    for (const step of steps) {
      if (step.status === "completed")
        total += 100;
      else if (step.status === "running")
        total += step.progress || 0;
    }
    return Math.round(total / steps.length);
  }
  getStats() {
    const steps = this.getSteps();
    const completed = steps.filter((s) => s.status === "completed").length;
    const failed = steps.filter((s) => s.status === "failed").length;
    const running = steps.filter((s) => s.status === "running").length;
    const pending = steps.filter((s) => s.status === "pending").length;
    return {
      total: steps.length,
      completed,
      failed,
      running,
      pending
    };
  }
  reset() {
    this.steps.clear();
    this.stepOrder = [];
    this.notifyChange();
  }
  notifyChange() {
    if (this.callback) {
      this.callback(this.getSteps());
    }
  }
}
function formatProgress(tracker) {
  const steps = tracker.getSteps();
  if (steps.length === 0)
    return "";
  const lines = [];
  const overall = tracker.getOverallProgress();
  lines.push(`\u23F3 \u6574\u4F53\u8FDB\u5EA6: ${overall}%`);
  lines.push("");
  const icons = {
    pending: "\u26AA",
    running: "\uD83D\uDD35",
    completed: "\u2705",
    failed: "\u274C"
  };
  for (const step of steps) {
    const icon = icons[step.status];
    const progressBar = step.progress !== undefined ? ` [${step.progress}%]` : "";
    const elapsed = step.startTime && step.endTime ? ` (${((step.endTime - step.startTime) / 1000).toFixed(1)}s)` : step.startTime ? ` (${((Date.now() - step.startTime) / 1000).toFixed(1)}s)` : "";
    lines.push(`${icon} ${step.label}${progressBar}${elapsed}`);
    if (step.message) {
      lines.push(`   ${step.message}`);
    }
  }
  const stats = tracker.getStats();
  lines.push("");
  lines.push(`\uD83D\uDCCA ${stats.completed}/${stats.total} \u5DF2\u5B8C\u6210`);
  return lines.join(`
`);
}
var init_ProgressTracker = () => {};

export { ProgressTracker, formatProgress, init_ProgressTracker };

//# debugId=FB620F3C2E5E6C2064756E2164756E21
//# sourceMappingURL=chunk-psc8avjs.js.map
