import React, { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Sparkles, Eye, EyeOff, LogIn, User2, LogOut } from 'lucide-react'; import { toast } from 'sonner'; import apiclient from '../apiclient'; import type { JoinByCodeRequest } from '../apiclient/data-contracts'; import { useUser } from '@stackframe/react'; import { stackClientApp } from 'app/auth'; interface GameVariant { id: string; title: string; description: string; features: string[]; icon: React.ReactNode; color: string; } const gameVariants: GameVariant[] = [ { id: 'no_wildcard', title: 'No Wild Card', description: 'Pure classic rummy with printed jokers only', features: [ 'No wild joker cards', 'Only printed jokers', 'Simpler strategy', 'Perfect for beginners' ], icon: , color: 'from-blue-500 to-cyan-500' }, { id: 'open_wildcard', title: 'Open Wild Card', description: 'Traditional rummy with wild card revealed at start', features: [ 'Wild card shown immediately', 'Traditional gameplay', 'Strategic substitutions', 'Classic experience' ], icon: , color: 'from-green-500 to-emerald-500' }, { id: 'close_wildcard', title: 'Close Wild Card', description: 'Advanced variant - wild card reveals after first sequence', features: [ 'Hidden wild card initially', 'Reveals after pure sequence', 'Advanced strategy', 'Maximum challenge' ], icon: , color: 'from-purple-500 to-pink-500' } ]; export default function App() { const navigate = useNavigate(); const user = useUser(); const [roomCode, setRoomCode] = useState(''); const [playerName, setPlayerName] = useState(''); const [joining, setJoining] = useState(false); const handleSelectVariant = (variantId: string) => { navigate(`/CreateTable?variant=${variantId}`); }; const handleJoinRoom = async () => { if (!user) { toast.error('Please sign in to join a room'); return; } if (!playerName.trim() || roomCode.trim().length !== 6) { toast.error('Enter your name and a valid 6-letter code'); return; } setJoining(true); try { const body: JoinByCodeRequest = { code: roomCode.trim().toUpperCase() }; const res = await apiclient.join_table_by_code(body); // Check if response is ok if (!res.ok) { const errorData = await res.json().catch(() => ({ detail: 'Unknown error' })); const errorMsg = errorData.detail || errorData.message || 'Failed to join room'; toast.error(`Join failed: ${errorMsg}`); setJoining(false); return; } const data = await res.json(); toast.success(`Joined table! Seat ${data.seat}`); navigate(`/Table?tableId=${data.table_id}`); } catch (e: any) { console.error('Join room error:', e); const errorMsg = e.message || e.detail || 'Failed to join room. Check the code and try again.'; toast.error(errorMsg); } finally { setJoining(false); } }; const handleSignIn = () => { stackClientApp.redirectToSignIn(); }; const handleSignOut = async () => { await stackClientApp.signOut(); toast.success('Signed out successfully'); }; return (
{/* Header */}

Rummy Room

Choose your game variant

{/* Auth Section */}
{user ? (
{/* Profile Picture */}
{/* User Name */}
{user.displayName || 'Player'} {user.primaryEmail}
{/* Sign Out Button */}
) : ( )}
{/* Game Variants Grid */}
{gameVariants.map((variant) => ( handleSelectVariant(variant.id)} > {/* Gradient Background */}
{/* Icon */}
{variant.icon}
{/* Title */}

{variant.title}

{/* Description */}

{variant.description}

{/* Features */}
    {variant.features.map((feature, idx) => (
  • {feature}
  • ))}
{/* Button */}
))}
{/* Join Table Section */}

Join a Friend's Game

Enter the 6-letter room code shared by your friend

Join Room

Enter details to join the table

setPlayerName(e.target.value)} placeholder="Enter your name" className="bg-slate-900/50 border-slate-600 text-white placeholder:text-slate-500" />
setRoomCode(e.target.value.toUpperCase())} placeholder="Enter 6-letter code" maxLength={6} className="bg-slate-900/50 border-slate-600 text-white placeholder:text-slate-500 uppercase tracking-wider text-lg font-mono text-center" />
{!user && (

Please sign in to join a room

)}
); }