// App.jsx — Ana uygulama const { useState, useEffect } = React; function Clock({ lang }) { const [now, setNow] = useState(new Date()); useEffect(() => { const id = setInterval(() => setNow(new Date()), 1000); return () => clearInterval(id); }, []); const locale = lang === 'tr' ? 'tr-TR' : 'en-GB'; const timeStr = now.toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit', second: '2-digit' }); const dateStr = now.toLocaleDateString(locale, { weekday: 'long', day: 'numeric', month: 'long' }); return (
{timeStr}
{dateStr}
); } function TableCard({ table, onClick }) { const [elapsed, setElapsed] = useState(''); useEffect(() => { if (!table.occupied || !table.openedAt) return; const update = () => { setElapsed(window.elapsed(table.openedAt)); }; update(); const id = setInterval(update, 10000); return () => clearInterval(id); }, [table.openedAt, table.occupied]); const total = (table.orders || []).reduce((s, o) => s + o.price * o.qty, 0); return ( ); } function App({ user: initialUser, onLogout }) { const [lang, setLang] = useState(Store.getSettings().lang); const [tables, setTables] = useState(Store.getTables()); const [selectedTableId, setSelectedTableId] = useState(null); const [showAdmin, setShowAdmin] = useState(false); const [revenue, setRevenue] = useState(Store.getDailyRevenue()); const [user, setUser] = useState(initialUser); const T = window.TRANS[lang]; const isAdmin = user && user.role === 'admin'; useEffect(() => { const onUpdate = () => { setTables(Store.getTables()); setRevenue(Store.getDailyRevenue()); }; const onUnauth = () => onLogout(); window.addEventListener('store-updated', onUpdate); window.addEventListener('store-unauth', onUnauth); return () => { window.removeEventListener('store-updated', onUpdate); window.removeEventListener('store-unauth', onUnauth); }; }, []); const handleTableUpdate = (updatedTables) => { setTables(updatedTables); setRevenue(Store.getDailyRevenue()); }; const handleLangChange = async (l) => { await Store.setLang(l); setLang(l); if (showAdmin) { setShowAdmin(false); setTimeout(() => setShowAdmin(true), 50); } }; const occupiedCount = tables.filter(t => t.occupied).length; const emptyCount = tables.length - occupiedCount; return (
adisyon
kafe pos
{occupiedCount} {T.occupiedTables}
{emptyCount} {T.emptyTables}
{T.dailyRevenue}
{fmt(revenue)}
{isAdmin && ( )}
{isAdmin ? '🔒' : '👤'} {isAdmin ? 'Yönetici' : user.name}
{tables.map(table => ( setSelectedTableId(table.id)} /> ))}
{selectedTableId !== null && ( setSelectedTableId(null)} onUpdate={(updated) => { handleTableUpdate(updated); }} /> )} {showAdmin && isAdmin && ( setShowAdmin(false)} onLangChange={handleLangChange} currentUser={user} /> )}
); } function Root() { // 'booting' | 'setup' | 'login' | 'app' const [phase, setPhase] = useState('booting'); const [user, setUser] = useState(null); const [bootError, setBootError] = useState(null); useEffect(() => { (async () => { try { const status = await Store.checkSetup(); if (status.needsSetup) { setPhase('setup'); return; } const ok = await Store.init(); if (ok) { setUser(Store.getUser()); setPhase('app'); } else { setPhase('login'); } } catch (e) { setBootError(e.message || 'Bilinmeyen hata'); } })(); }, []); const handleAuthed = () => { setUser(Store.getUser()); setPhase('app'); }; const handleLogout = () => { setUser(null); setPhase('login'); }; if (bootError) { return (

Sunucuya bağlanılamadı

{bootError}

); } if (phase === 'booting') { return (
adisyon
Yükleniyor…
); } if (phase === 'setup') { return ; } if (phase === 'login') { return ; } return ; } ReactDOM.createRoot(document.getElementById('root')).render();