'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import NumberFinder from './NumberFinder'; const apiURL = process.env.NEXT_PUBLIC_API_URL || ''; export default function SinglePlayerPage() { const router = useRouter(); const [digitInput, setDigitInput] = useState(''); const [game, setGame] = useState(null); // {digitNumber, attempts} const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const handleStart = async () => { const num = parseInt(digitInput, 10); if (isNaN(num) || num <= 0) return; setLoading(true); setError(''); try { const res = await fetch( `${apiURL}/start?digitNumber=${num}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', } ); if (!res.ok) throw new Error(`Sunucu hatası (HTTP ${res.status})`); const data = await res.json(); if (typeof data.attempts !== 'number') throw new Error('Geçersiz yanıt'); setGame({ digitNumber: num, attempts: data.attempts }); } catch (err) { setError(err.message); console.error(err); setTimeout(() => router.push('/'), 2500); } finally { setLoading(false); } }; return (
Single Player Mode
{game ? ( ) : (

Digit Number [3-10]

setDigitInput(e.target.value)} /> {error && (

{error}

)}
)}
); }