import { useState } from 'react'; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; interface SetupProps { onComplete: () => void; } export function Setup({ onComplete, className, ...props }: SetupProps & React.ComponentPropsWithoutRef<"div">) { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); // Client-side validation if (password !== confirmPassword) { setError('Passwords do not match'); return; } if (username.length < 3) { setError('Username must be at least 3 characters'); return; } if (password.length < 6) { setError('Password must be at least 6 characters'); return; } setIsLoading(true); try { const response = await fetch('/api/auth/setup', { method: 'POST', headers: { 'Content-Type': 'application/json', }, credentials: 'include', body: JSON.stringify({ username, password, confirmPassword }), }); const data = await response.json(); if (response.ok && data.success) { onComplete(); } else { setError(data.error || 'Setup failed'); } } catch { setError('Network error. Please try again.'); } finally { setIsLoading(false); } }; return (