diff --git a/packages/client/src/components/predictions-form.tsx b/packages/client/src/components/predictions-form.tsx new file mode 100644 index 0000000..71d0d79 --- /dev/null +++ b/packages/client/src/components/predictions-form.tsx @@ -0,0 +1,127 @@ +import { useState } from "react" +import type { Country, Prediction } from "@celebrate-esc/shared" +import { Button } from "@/components/ui/button" +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" + +interface PredictionsFormProps { + countries: Country[] + existingPrediction: Prediction | null + locked: boolean + onSubmit: (prediction: { predictedWinner: string; top3: string[]; nulPointsPick: string }) => void +} + +export function PredictionsForm({ countries, existingPrediction, locked, onSubmit }: PredictionsFormProps) { + const [winner, setWinner] = useState(existingPrediction?.predictedWinner ?? "") + const [top3, setTop3] = useState(existingPrediction?.top3 ?? []) + const [nulPoints, setNulPoints] = useState(existingPrediction?.nulPointsPick ?? "") + + if (locked) { + if (!existingPrediction) { + return ( + + + Predictions are locked. You didn't submit one in time. + + + ) + } + return ( + + + Your Predictions (locked) + + +

+ Winner:{" "} + {countries.find((c) => c.code === existingPrediction.predictedWinner)?.name} +

+

+ Top 3:{" "} + {existingPrediction.top3.map((code) => countries.find((c) => c.code === code)?.name).join(", ")} +

+

+ Nul Points:{" "} + {countries.find((c) => c.code === existingPrediction.nulPointsPick)?.name} +

+
+
+ ) + } + + function toggleTop3(code: string) { + setTop3((prev) => { + if (prev.includes(code)) return prev.filter((c) => c !== code) + if (prev.length >= 3) return prev + return [...prev, code] + }) + } + + const canSubmit = winner && top3.length === 3 && nulPoints && !top3.includes(winner) + + return ( + + + Predictions + + +
+ + +
+ +
+ +
+ {countries + .filter((c) => c.code !== winner) + .map((c) => ( + + ))} +
+
+ +
+ + +
+ + +
+
+ ) +}