export type BreathState = {
  word: "静" | "吸" | "顿" | "呼" | "定";
  phase: "prepare" | "inhale" | "pause" | "exhale" | "complete";
  progress: number;
};

export function breathState(elapsedMs: number): BreathState {
  const elapsed = Math.max(0, elapsedMs);
  const progress = Math.min(elapsed / 46_000, 1);
  if (elapsed < 1_000) return { word: "静", phase: "prepare", progress };
  if (elapsed >= 46_000) return { word: "定", phase: "complete", progress: 1 };
  const within = (elapsed - 1_000) % 9_000;
  if (within < 3_000) return { word: "吸", phase: "inhale", progress };
  if (within < 5_000) return { word: "顿", phase: "pause", progress };
  return { word: "呼", phase: "exhale", progress };
}
