"use client"; import * as React from "react"; import { cn } from "./lib/utils"; export interface CountdownStartProps extends React.HTMLAttributes { from?: number; onGo?: () => void; } /** Countdown start: 3-2-1-GO match opener with auto tick. */ export function CountdownStart({ from = 3, onGo, className, ...props }: CountdownStartProps) { const [n, setN] = React.useState(from); React.useEffect(() => { setN(from); }, [from]); React.useEffect(() => { if (n <= 0) { onGo?.(); return; } const t = setTimeout(() => setN((v) => v - 1), 900); return () => clearTimeout(t); }, [n, onGo]); return (
0 ? `Match starts in ${n}` : "Go"} className={cn("flex min-h-11 touch-none select-none flex-col items-center gap-1 rounded-md border-2 border-foreground bg-card px-6 py-3", className)} style={{ touchAction: "none" }} {...props} > Match Start
); }