export type ProgressAction = "analyze" | "confirm" | "optimize";

export interface ProgressStage {
  label: string;
}

const progressStages: Record<ProgressAction, ProgressStage[]> = {
  analyze: [
    { label: "读取文章输入" },
    { label: "提取事实卡" },
    { label: "生成待确认信息" },
  ],
  confirm: [
    { label: "校验事实卡" },
    { label: "保存品牌事实" },
  ],
  optimize: [
    { label: "生成优化稿" },
    { label: "质量检查" },
    { label: "等待后端步骤更新" },
    { label: "整理结果" },
  ],
};

export function formatElapsedSeconds(seconds: number) {
  const safeSeconds = Math.max(0, Math.floor(seconds));
  if (safeSeconds < 60) return `${safeSeconds} 秒`;
  const minutes = Math.floor(safeSeconds / 60);
  const remainingSeconds = safeSeconds % 60;
  return `${minutes} 分 ${remainingSeconds} 秒`;
}

export function getElapsedNotice(seconds: number) {
  if (seconds >= 60) return "耗时较长，仍在等待服务返回。";
  if (seconds >= 40) return "仍在处理中，请保持页面打开。";
  return "通常需要 10-40 秒，请保持页面打开。";
}

export function getProgressStages(action: ProgressAction) {
  return progressStages[action];
}
