export type DrawStatusHud = {
  labelKey: string;
  /** Tailwind 颜色类：状态圆点 */
  dotClass: string;
  /** 文案条（如「距封盘」） */
  countdownKind: "start" | "close" | "draw" | "cooldown" | "none";
};

/**
 * 界面文档 §4.2「封盘」展示：`closing`（封盘中）与 `closed`（待开奖）——
 * 倒计时区域使用错误色 #ff4d4f，并提示「请选择下一期」。
 */
export function isHallSealedCountdownUi(status: string): boolean {
  return status === "closing" || status === "closed";
}

/** 不可下注时展示阻断提示条 */
export function isHallBlockedForBetting(status: string): boolean {
  return status !== "open";
}

/** 已到计划开奖时刻、但调度尚未把期号推进到冷静期（closed → drawing → cooldown） */
export function isHallAwaitingDrawProcessing(
  status: string,
  drawTimeIso: string | null | undefined,
  secondsToDraw: number | null | undefined,
  nowMs: number,
): boolean {
  if (!["closing", "closed", "drawing", "review"].includes(status)) {
    return false;
  }
  if (secondsToDraw !== null && secondsToDraw !== undefined && secondsToDraw <= 0) {
    return true;
  }
  if (!drawTimeIso) {
    return false;
  }
  const drawMs = Date.parse(drawTimeIso);
  return !Number.isNaN(drawMs) && drawMs <= nowMs;
}

/** 对齐界面文档 §4.2 状态文案与 PRD 期号状态 */
export function drawStatusHud(status: string): DrawStatusHud {
  switch (status) {
    case "pending":
      return { labelKey: "draw.status.pending", dotClass: "bg-muted-foreground", countdownKind: "start" };
    case "open":
      return { labelKey: "draw.status.open", dotClass: "bg-emerald-500", countdownKind: "close" };
    case "closing":
      return { labelKey: "draw.status.closing", dotClass: "bg-rose-500", countdownKind: "draw" };
    case "closed":
      return { labelKey: "draw.status.closed", dotClass: "bg-amber-500", countdownKind: "draw" };
    case "drawing":
      return { labelKey: "draw.status.drawing", dotClass: "bg-sky-500", countdownKind: "none" };
    case "review":
      return { labelKey: "draw.status.review", dotClass: "bg-violet-500", countdownKind: "none" };
    case "cooldown":
      return { labelKey: "draw.status.cooldown", dotClass: "bg-cyan-500", countdownKind: "cooldown" };
    case "settling":
      return { labelKey: "draw.status.settling", dotClass: "bg-blue-600", countdownKind: "none" };
    case "settled":
      return { labelKey: "draw.status.settled", dotClass: "bg-muted-foreground", countdownKind: "none" };
    case "cancelled":
      return { labelKey: "draw.status.cancelled", dotClass: "bg-muted-foreground", countdownKind: "none" };
    default:
      return { labelKey: status, dotClass: "bg-muted-foreground", countdownKind: "none" };
  }
}
