'use client'; import { useState } from 'react'; import { Camera, Barcode, Check, X, Sparkles, Plus } from 'lucide-react'; import { toast } from 'sonner'; interface BarcodeScannerModalProps { isOpen: boolean; onClose: () => void; onProductScanned: (product: { name: string; size: number; unit: string; priceCents: number }) => void; } const BARCODE_DATABASE: Record = { '4008234567890': { name: 'Hafermilch Barista Bio (Oatly)', size: 1, unit: 'Liter', priceCents: 149 }, '4012345678901': { name: 'Tofu Natur Bio (Taifun)', size: 200, unit: 'Gramm', priceCents: 199 }, '4023456789012': { name: 'Spaghetti 500g (Barilla)', size: 500, unit: 'Gramm', priceCents: 189 }, '4034567890123': { name: 'Bio Hefeflocken (Alnatura)', size: 200, unit: 'Gramm', priceCents: 299 }, '4045678901234': { name: 'Strauchtomaten Bio', size: 500, unit: 'Gramm', priceCents: 229 }, }; export function BarcodeScannerModal({ isOpen, onClose, onProductScanned }: BarcodeScannerModalProps) { const [barcodeInput, setBarcodeInput] = useState(''); const [scanning, setScanning] = useState(false); if (!isOpen) return null; const handleSimulateScan = (code: string) => { setScanning(true); setTimeout(() => { setScanning(false); const match = BARCODE_DATABASE[code] || { name: `Gescanntes Bio-Produkt (${code.slice(-4)})`, size: 1, unit: 'Stück', priceCents: 199, }; onProductScanned(match); toast.success(`📷 Barcode gescannt: "${match.name}" erkannt! 🌱`); onClose(); }, 800); }; return (

1-Klick Barcode Scanner

{/* Camera Scanner View Simulation */}

{scanning ? 'Barcode wird dekodiert...' : 'Halte die Kamera über den Barcode oder wähle unten ein Produkt'}

{/* Quick Scan Preset Buttons */}
{/* Manual Barcode Code Entry */}
{ e.preventDefault(); if (barcodeInput.trim()) handleSimulateScan(barcodeInput.trim()); }} className="flex gap-2" > setBarcodeInput(e.target.value)} placeholder="Barcode Nummer eingeben (z.B. 400823...)" className="flex-1 rounded-xl border border-input bg-background px-3.5 py-2.5 text-xs" />
); }