'use client'; import { useState, useMemo } from 'react'; import { Search, User, Star, Wine, MessageSquare } from 'lucide-react'; interface Tasting { id: string; bottle_id: string; user_id: string; rating: number; nose_notes: string | null; palate_notes: string | null; finish_notes: string | null; created_at: string; user: { username: string; display_name: string | null }; bottle: { id: string; name: string; distillery: string | null; image_url: string | null } | null; } interface AdminTastingsListProps { tastings: Tasting[]; } export default function AdminTastingsList({ tastings }: AdminTastingsListProps) { const [search, setSearch] = useState(''); const [filterUser, setFilterUser] = useState(null); const [filterRating, setFilterRating] = useState(null); // Get unique users for filter const users = useMemo(() => { const userMap = new Map(); tastings.forEach(t => { userMap.set(t.user_id, t.user.display_name || t.user.username); }); return Array.from(userMap.entries()).sort((a, b) => a[1].localeCompare(b[1])); }, [tastings]); // Filter tastings const filteredTastings = useMemo(() => { let result = tastings; if (search) { const searchLower = search.toLowerCase(); result = result.filter(t => t.bottle?.name?.toLowerCase().includes(searchLower) || t.bottle?.distillery?.toLowerCase().includes(searchLower) || t.user.username.toLowerCase().includes(searchLower) || t.nose_notes?.toLowerCase().includes(searchLower) || t.palate_notes?.toLowerCase().includes(searchLower) || t.finish_notes?.toLowerCase().includes(searchLower) ); } if (filterUser) { result = result.filter(t => t.user_id === filterUser); } if (filterRating !== null) { result = result.filter(t => Math.floor(t.rating) === filterRating); } return result; }, [tastings, search, filterUser, filterRating]); const renderStars = (rating: number) => { return (
{[1, 2, 3, 4, 5].map(star => ( ))}
); }; return (
{/* Filters */}
setSearch(e.target.value)} placeholder="Search bottles, users, or notes..." className="w-full pl-12 pr-4 py-3 bg-zinc-900 border border-zinc-800 rounded-xl text-white placeholder-zinc-600 focus:outline-none focus:border-orange-600" />
{/* Results */}
Showing {filteredTastings.length} of {tastings.length} tastings
{/* Tastings List */}
{filteredTastings.map(tasting => { const hasNotes = tasting.nose_notes || tasting.palate_notes || tasting.finish_notes; return (
{/* Bottle Image */}
{tasting.bottle?.image_url ? ( {tasting.bottle.name ) : (
)}
{/* Content */}

{tasting.bottle?.name || 'Unknown Bottle'}

{tasting.bottle?.distillery || 'Unknown Distillery'}

{tasting.rating > 0 ? renderStars(tasting.rating) : ( No rating )}
{/* Notes Preview */} {hasNotes && (
{tasting.nose_notes && (

Nose: {tasting.nose_notes.slice(0, 80)}...

)} {tasting.palate_notes && (

Palate: {tasting.palate_notes.slice(0, 80)}...

)}
)} {/* Meta */}
{tasting.user.display_name || tasting.user.username} {new Date(tasting.created_at).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', })} {hasNotes && ( Has notes )}
); })}
{/* Empty State */} {filteredTastings.length === 0 && (

No Tastings Found

No tastings match your filters.

)}
); }