export const dynamic = 'force-dynamic'; import { createClient } from '@/lib/supabase/server'; import { redirect } from 'next/navigation'; import { checkIsAdmin } from '@/services/track-api-usage'; import { getOcrLogs, getOcrStats } from '@/services/save-ocr-log'; import { Eye, Camera, TrendingUp, CheckCircle, AlertCircle, Calendar, Clock, Percent } from 'lucide-react'; import Link from 'next/link'; import Image from 'next/image'; export default async function OcrLogsPage() { const supabase = await createClient(); const { data: { user } } = await supabase.auth.getUser(); if (!user) { redirect('/'); } const isAdmin = await checkIsAdmin(user.id); if (!isAdmin) { redirect('/'); } // Fetch OCR data const [logsResult, stats] = await Promise.all([ getOcrLogs(100), getOcrStats(), ]); const logs = logsResult.data || []; return (
{/* Header */}

OCR Dashboard

Mobile OCR Scan Results

← Back to Admin
{/* Stats Cards */}
Total Scans
{stats.totalScans}
All time
Today
{stats.todayScans}
Scans today
Avg Confidence
{stats.avgConfidence}%
Recognition quality
Top Distillery
{stats.topDistilleries[0]?.name || '-'}
{stats.topDistilleries[0] ? `${stats.topDistilleries[0].count} scans` : 'No data'}
{/* Top Distilleries */} {stats.topDistilleries.length > 0 && (

Most Scanned Distilleries

{stats.topDistilleries.map((d, i) => ( {d.name} ({d.count}) ))}
)} {/* OCR Logs Grid */}

Recent OCR Scans

{logs.length === 0 ? (

No OCR scans recorded yet

Scans from mobile devices will appear here

) : (
{logs.map((log: any) => (
{/* Image Preview */}
{log.image_thumbnail ? ( Scan ) : log.image_url ? ( Scan ) : (
)} {/* Confidence Badge */}
= 70 ? 'bg-green-500 text-white' : log.confidence >= 40 ? 'bg-amber-500 text-white' : 'bg-red-500 text-white' }`}> {log.confidence}%
{/* Detected Fields */}
{log.distillery && (
{log.distillery} {log.distillery_source && ( {log.distillery_source} )}
)} {log.bottle_name && (
{log.bottle_name}
)}
{log.abv && ( {log.abv}% )} {log.age && ( {log.age}y )} {log.vintage && ( {log.vintage} )} {log.volume && ( {log.volume} )}
{/* Raw Text (Collapsible) */} {log.raw_text && (
Raw Text
                                                {log.raw_text}
                                            
)} {/* Meta */}
{new Date(log.created_at).toLocaleString('de-DE', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit', })}
{log.profiles?.username || 'Unknown'}
{log.processing_time_ms && (
{log.processing_time_ms}ms
)}
))}
)}
); }