import type { Outcome, Match, AIPrediction, Team } from "./types"; import { type Lang, teamShort, dayName, monthEn, dict } from "./i18n"; export function outcomeLabel(match: Match, o: Outcome, lang: Lang = "ko"): string { const d = dict(lang); if (o === "TEAM_A_WIN") return `${teamShort(match.teamA, lang)} ${d.win}`; if (o === "TEAM_B_WIN") return `${teamShort(match.teamB, lang)} ${d.win}`; return d.drawLabel; } // D3: 확률 = 이긴다고 예측한 팀의 승리 확률. 라벨은 호출부에서 dict로 구성. export function winProb( match: Match, p: Pick, ): { team: Team | null; pct: number } { if (p.outcome === "TEAM_A_WIN") return { team: match.teamA, pct: p.confidencePct }; if (p.outcome === "TEAM_B_WIN") return { team: match.teamB, pct: p.confidencePct }; return { team: null, pct: p.confidencePct }; } // "6월 12일 (금)" / "Jun 12 (Fri)" — 대시보드 날짜 그룹 헤더 export function dateHeading(iso: string, lang: Lang = "ko"): string { const dm = iso.match(/(\d{4})-(\d{2})-(\d{2})/); if (!dm) return iso; const [, y, mo, d] = dm; const dow = dayName(lang, new Date(Date.UTC(+y, +mo - 1, +d)).getUTCDay()); return lang === "en" ? `${monthEn(+mo)} ${+d} (${dow})` : `${+mo}월 ${+d}일 (${dow})`; } // "11:00" — 경기 카드 시간 export function timeOnly(iso: string): string { const m = iso.match(/T(\d{2}):(\d{2})/); return m ? `${m[1]}:${m[2]}` : ""; } // "2026-06-12" — 날짜 그룹 키 export function dateKey(iso: string): string { const m = iso.match(/(\d{4}-\d{2}-\d{2})/); return m ? m[1] : iso; } // "6.12(금) 11:00 KST" — 요일명만 로케일 적용 export function kickoffDisplay(iso: string, lang: Lang = "ko"): string { const dm = iso.match(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/); if (!dm) return iso; const [, y, mo, d, hh, mm] = dm; const dow = dayName(lang, new Date(Date.UTC(+y, +mo - 1, +d)).getUTCDay()); return `${+mo}.${+d}(${dow}) ${hh}:${mm} KST`; } export function pct(part: number, total: number): number { if (!total) return 0; return Math.round((part / total) * 100); }