type DrawTranslate = (
  key: string,
  options?: { ns?: string; index?: number },
) => string;

/** 大厅展示态是否与库内期号状态不同（仅 open 等 tick 修正时可能不同） */
export function hallPreviewDiffersFromDbStatus(
  dbStatus: string,
  hallPreviewStatus: string,
): boolean {
  return dbStatus !== hallPreviewStatus;
}

/** 期号状态文案（draws.statusOptions） */
export function drawStatusLabel(status: string, t: DrawTranslate): string {
  const key = `statusOptions.${status}`;
  const translated = t(key, { ns: "draws" });
  return translated === key ? status : translated;
}

/** 开奖结果来源（draws.resultSourceOptions） */
export function drawResultSourceLabel(
  source: string | null | undefined,
  t: DrawTranslate,
): string {
  if (source == null || source === "") {
    return "—";
  }
  const key = `resultSourceOptions.${source}`;
  const translated = t(key, { ns: "draws" });
  return translated === key ? source : translated;
}

/** 开奖结果批次状态（draws.batchStatusOptions） */
export function drawBatchStatusLabel(status: string, t: DrawTranslate): string {
  const key = `batchStatusOptions.${status}`;
  const translated = t(key, { ns: "draws" });
  return translated === key ? status : translated;
}

/** 结算批次状态（settlement.statusOptions） */
export function settlementBatchStatusLabel(status: string, t: DrawTranslate): string {
  const key = `statusOptions.${status}`;
  const translated = t(key, { ns: "settlement" });
  return translated === key ? status : translated;
}

/** 奖项类型 + 序号 → 展示名（draws.resultSlots） */
export function drawPrizeTypeLabel(
  prizeType: string,
  prizeIndex: number,
  t: DrawTranslate,
): string {
  if (prizeType === "first") {
    return t("resultSlots.first", { ns: "draws" });
  }
  if (prizeType === "second") {
    return t("resultSlots.second", { ns: "draws" });
  }
  if (prizeType === "third") {
    return t("resultSlots.third", { ns: "draws" });
  }
  if (prizeType === "starter") {
    return t("resultSlots.starter", { ns: "draws", index: prizeIndex + 1 });
  }
  if (prizeType === "consolation") {
    return t("resultSlots.consolation", { ns: "draws", index: prizeIndex + 1 });
  }
  return prizeType;
}
