'use client'; import React from 'react'; import Link from 'next/link'; import { ChevronLeft, Calendar, Award, Droplets, MapPin, Tag, ExternalLink, Package, Info, Loader2, WifiOff, CircleDollarSign, Wine, CheckCircle2, Circle, ChevronDown, Plus, Share2 } from 'lucide-react'; import { motion, AnimatePresence } from 'framer-motion'; import { updateBottle } from '@/services/update-bottle'; import { getStorageUrl } from '@/lib/supabase'; import TastingNoteForm from '@/components/TastingNoteForm'; import TastingList from '@/components/TastingList'; import DeleteBottleButton from '@/components/DeleteBottleButton'; import EditBottleForm from '@/components/EditBottleForm'; import { useBottleData } from '@/hooks/useBottleData'; import { useI18n } from '@/i18n/I18nContext'; interface BottleDetailsProps { bottleId: string; sessionId?: string; userId?: string; } export default function BottleDetails({ bottleId, sessionId, userId }: BottleDetailsProps) { const { t, locale } = useI18n(); const { bottle, tastings, loading, error, isOffline } = useBottleData(bottleId); // Quick Collection States const [price, setPrice] = React.useState(''); const [status, setStatus] = React.useState('sealed'); const [isUpdating, setIsUpdating] = React.useState(false); const [isFormVisible, setIsFormVisible] = React.useState(false); React.useEffect(() => { if (bottle) { setPrice(bottle.purchase_price?.toString() || ''); setStatus((bottle as any).status || 'sealed'); } }, [bottle]); const handleQuickUpdate = async (newPrice?: string, newStatus?: string) => { if (isOffline) return; setIsUpdating(true); try { await updateBottle(bottleId, { purchase_price: newPrice !== undefined ? (newPrice ? parseFloat(newPrice) : null) : (price ? parseFloat(price) : null), status: newStatus !== undefined ? newStatus : status } as any); } catch (err) { console.error('Quick update failed:', err); } finally { setIsUpdating(false); } }; if (loading) { return (

{t('common.loading')}

); } if (!bottle && !loading) { return (

Flasche nicht verfügbar

Inhalte konnten nicht geladen werden. Bitte stelle eine Internetverbindung her, um diese Flasche zum ersten Mal zu laden.

Zurück zum Vault
); } if (!bottle) return null; // Should not happen due to check above return (
{/* Back Button */} Zurück zur Sammlung {isOffline && (

Offline-Modus: Daten aus dem Cache

)} {/* Hero Section */}
{bottle.name}

{bottle.name}

{bottle.distillery}

{bottle.whiskybase_id && ( )}
Kategorie
{bottle.category || '-'}
Alkoholgehalt
{bottle.abv}% Vol.
Alter
{bottle.age ? `${bottle.age} J.` : '-'}
{bottle.distilled_at && (
Destilliert
{bottle.distilled_at}
)} {bottle.bottled_at && (
Abgefüllt
{bottle.bottled_at}
)} {/* Quick Collection Card */}

Sammlungs-Status

{isUpdating && }
{/* Price */}
setPrice(e.target.value)} onBlur={() => handleQuickUpdate(price)} placeholder="0.00" className="w-full bg-zinc-950 border border-zinc-800 rounded-xl pl-3 pr-8 py-2 text-sm font-bold text-orange-500 focus:outline-none focus:border-orange-600 transition-all" />
{/* Status */}
{bottle.batch_info && (
Batch / Code
{bottle.batch_info}
)}
Letzter Dram
{tastings && tastings.length > 0 ? new Date(tastings[0].created_at).toLocaleDateString('de-DE') : 'Noch nie'}
{isOffline ? (
Bearbeiten & Löschen nur online möglich
) : ( <> Split starten )}

{/* Tasting Notes Section */}

Tasting Notes

Hier findest du deine bisherigen Eindrücke.

{/* Form */}
{isFormVisible && (

Dram bewerten

setIsFormVisible(false)} />
)}
{/* List */}
); }