"use client"; import { Check, Sparkles } from "lucide-react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { useTranslations } from "@/lib/i18n/context"; import { CycleDisclaimer } from "./cycle-disclaimer"; import { FERTILE_HUE, FLOW_HUE, OVULATION_HUE } from "./phase-tokens"; import type { CyclePrediction, CycleHistoryResponse } from "./types"; /** * v1.15.0 — the predictions panel. * * Shows the next-period RANGE (a window, with a confidence pill), the fertile * window (already goal-gated server-side — the API nulls it unless TTC, so we * just render what is present), the "still learning" state for < 3 cycles or * raw-chart mode, the cycle-history stats, and the fixed non-medical * disclaimer. Never a single dated next-period claim — always the range. */ function formatDate(d: string): string { // Render at noon UTC so the YYYY-MM-DD never rolls a day across tz. return new Date(`${d}T12:00:00Z`).toLocaleDateString(undefined, { month: "short", day: "numeric", }); } function confidenceTone(c: number): { labelKey: string; variant: "default" | "secondary" | "outline"; } { if (c >= 0.66) return { labelKey: "cycle.predictions.confidenceHigh", variant: "default" }; if (c >= 0.33) return { labelKey: "cycle.predictions.confidenceMedium", variant: "secondary", }; return { labelKey: "cycle.predictions.confidenceLow", variant: "outline" }; } export interface PredictionsPanelProps { prediction: CyclePrediction | null; rawChartMode: boolean; history: CycleHistoryResponse | undefined; /** Fallback disclaimer when no prediction carries one. */ fallbackDisclaimer?: string; /** The active cycle goal — only AVOID_PREGNANCY surfaces the (deliberate) * contraceptive-safety caveat here; every other goal drops the generic * "predictions are estimates" line so it does not repeat under every graph. */ goal?: string; } export function PredictionsPanel({ prediction, rawChartMode, history, fallbackDisclaimer, goal, }: PredictionsPanelProps) { const { t } = useTranslations(); // Only the AVOID_PREGNANCY goal shows a disclaimer here: it surfaces the // fertile window, so the stronger "not a contraceptive method" caveat is a // deliberate medical safety note. For all other goals the generic // estimate-caveat is suppressed (it already lives once with the data). const disclaimer = goal === "AVOID_PREGNANCY" ? (prediction?.disclaimer ?? fallbackDisclaimer ?? "") : ""; return (
{t("cycle.predictions.none")}
) : prediction.stillLearning ? ( <>{title}
{body}
{t("cycle.history.none")}
) : ({t("cycle.history.recentCycles")}