'use client'; import React, { useState } from 'react'; import { updateBottleStatus } from '@/services/update-bottle-status'; import { Loader2, Package, Play, CheckCircle, FlaskConical } from 'lucide-react'; interface StatusSwitcherProps { bottleId: string; currentStatus: 'sealed' | 'open' | 'sampled' | 'empty'; } export default function StatusSwitcher({ bottleId, currentStatus }: StatusSwitcherProps) { const [status, setStatus] = useState(currentStatus); const [loading, setLoading] = useState(false); const handleStatusChange = async (newStatus: 'sealed' | 'open' | 'sampled' | 'empty') => { if (newStatus === status || loading) return; setLoading(true); try { const result = await updateBottleStatus(bottleId, newStatus); if (result.success) { setStatus(newStatus); } else { alert(result.error || 'Fehler beim Aktualisieren des Status'); } } catch (err) { alert('Ein unerwarteter Fehler ist aufgetreten'); } finally { setLoading(false); } }; const options = [ { id: 'sealed', label: 'Versiegelt', icon: Package, color: 'hover:bg-blue-500' }, { id: 'open', label: 'Offen', icon: Play, color: 'hover:bg-amber-500' }, { id: 'sampled', label: 'Sampled', icon: FlaskConical, color: 'hover:bg-purple-500' }, { id: 'empty', label: 'Leer', icon: CheckCircle, color: 'hover:bg-zinc-500' }, ] as const; return (
{loading && }
{options.map((opt) => { const Icon = opt.icon; const isActive = status === opt.id; return ( ); })}
); }