/** 瀏覽器爬蟲子步驟（供進度 UI 顯示） */
export type BrowserCrawlStep =
  | "session_check"
  | "open_page"
  | "landing_pause"
  | "wait_content"
  | "scroll"
  | "parse_network"
  | "parse_scripts"
  | "parse_dom"
  | "between_pages"
  | "done";

export const BROWSER_STEP_LABELS: Record<BrowserCrawlStep, string> = {
  session_check: "檢查 Threads 登入",
  open_page: "開啟頁面",
  landing_pause: "模擬真人停留",
  wait_content: "等待貼文載入",
  scroll: "滾動載入更多",
  parse_network: "解析 API 回應",
  parse_scripts: "解析頁面資料",
  parse_dom: "解析 DOM 貼文",
  between_pages: "任務間隔（防爆量）",
  done: "完成",
};

export type BrowserProgressCallback = (
  step: BrowserCrawlStep,
  detail?: string
) => void | Promise<void>;

export function formatBrowserStep(step: BrowserCrawlStep, detail?: string): string {
  const label = BROWSER_STEP_LABELS[step] ?? step;
  return detail ? `${label} · ${detail}` : label;
}