import { Button, TextInput, Stack, Group, Text, Flex, Divider, NumberInput } from "@mantine/core"; import { useForm } from "@mantine/form"; import { Match } from "@/features/matches/types"; import { Trans, useLingui } from "@lingui/react/macro"; interface MatchFormProps { match: Match; onSubmit: (data: { home_cups: number; away_cups: number; ot_count: number; }) => void; onCancel: () => void; loading?: boolean; } export const MatchForm: React.FC = ({ match, onSubmit, onCancel, loading = false, }) => { const { t } = useLingui(); const form = useForm({ initialValues: { home_cups: match.home_cups || 10, away_cups: match.away_cups || 10, ot_count: match.ot_count || 0, }, validate: { home_cups: (value, values) => { if (value === null || value === undefined) return t`Home cups is required`; if (values.ot_count > 0) return null; const homeCups = Number(value); const awayCups = Number(values.away_cups); if (homeCups !== 10 && awayCups !== 10) { return t`At least one team must have 10 cups`; } if (homeCups === 10 && awayCups === 10) { return t`Both teams cannot have 10 cups`; } return null; }, away_cups: (value, values) => { if (value === null || value === undefined) return t`Away cups is required`; if (values.ot_count > 0) return null; const awayCups = Number(value); const homeCups = Number(values.home_cups); if (homeCups !== 10 && awayCups !== 10) { return t`At least one team must have 10 cups`; } if (homeCups === 10 && awayCups === 10) { return t`Both teams cannot have 10 cups`; } return null; }, ot_count: (value) => value === null || value === undefined ? t`Overtime count is required` : null, }, transformValues: (values) => ({ home_cups: Number(values.home_cups), away_cups: Number(values.away_cups), ot_count: Number(values.ot_count), }), }); const handleSubmit = form.onSubmit(() => { const transformedValues = form.getTransformedValues(); onSubmit(transformedValues); }); return (
{match.home?.name} Cups { match.home?.players?.map(p => ( {p.first_name} {p.last_name} )) } {match.away?.name} Cups { match.away?.players?.map(p => ( {p.first_name} {p.last_name} )) } OT Count
); };