"use client" import React from "react" import { useState } from "react" import Image from "next/image" import Link from "next/link" import { posterUrl } from "@/lib/tmdb" import { StarRating } from "@/components/star-rating" import { createClient } from "@/lib/supabase/client" import { useRouter } from "next/navigation" import { BookOpen, Bookmark, ListIcon, Film, Trash2, Plus, Loader2, Tv, } from "lucide-react" interface DiaryEntry { id: string tmdb_movie_id: number movie_title: string movie_poster_path: string | null rating: number | null imdb_rating: number | null rotten_tomatoes_rating: number | null review: string | null watched_on: string media_type: 'movie' | 'tv' season_number: number | null episode_number: number | null } interface WatchlistItem { id: string tmdb_id: number title: string poster_path: string | null added_at: string } interface ListItem { id: string name: string description: string | null list_items: { count: number }[] } interface DiaryContentProps { entries: DiaryEntry[] watchlist: WatchlistItem[] lists: ListItem[] } type Tab = "diary" | "watchlist" | "lists" export function DiaryContent({ entries, watchlist, lists: initialLists, }: DiaryContentProps) { const [activeTab, setActiveTab] = useState("diary") const [lists, setLists] = useState(initialLists) const [showNewList, setShowNewList] = useState(false) const [newListName, setNewListName] = useState("") const [creatingList, setCreatingList] = useState(false) const router = useRouter() const tabs: { id: Tab; label: string; icon: typeof BookOpen; count: number }[] = [ { id: "diary", label: "Tagebuch", icon: BookOpen, count: entries.length }, { id: "watchlist", label: "Watchlist", icon: Bookmark, count: watchlist.length }, { id: "lists", label: "Listen", icon: ListIcon, count: lists.length }, ] async function createList(e: React.FormEvent) { e.preventDefault() if (!newListName.trim()) return setCreatingList(true) const supabase = createClient() const { data: { user }, } = await supabase.auth.getUser() if (!user) return const { data, error } = await supabase .from("lists") .insert({ user_id: user.id, name: newListName.trim() }) .select("*, list_items(count)") .single() if (!error && data) { setLists([data, ...lists]) setNewListName("") setShowNewList(false) } setCreatingList(false) } async function removeFromWatchlist(id: string) { const supabase = createClient() await supabase.from("watchlist").delete().eq("id", id) router.refresh() } async function deleteDiaryEntry(id: string) { const supabase = createClient() await supabase.from("diary_entries").delete().eq("id", id) router.refresh() } return (

Mein Tagebuch

{/* Diary Tab */} {activeTab === "diary" && ( <> {entries.length === 0 ? ( ) : (
{entries.map((entry) => { const url = posterUrl(entry.movie_poster_path, "w342") return (
{url ? ( {entry.movie_title} ) : (
{entry.media_type === 'tv' ? ( ) : ( )}
)}

{entry.movie_title}

{entry.watched_on ? new Date(entry.watched_on).toLocaleDateString( "de-DE", { day: "numeric", month: "long", year: "numeric" } ) : "Kein Datum" } {entry.media_type === 'tv' && entry.season_number && ( S{entry.season_number} {entry.episode_number && `E${entry.episode_number}`} )}

{entry.rating && (
)} {/* External Ratings */}
{entry.imdb_rating && ( IMDb {entry.imdb_rating} )} {entry.rotten_tomatoes_rating && ( RT {entry.rotten_tomatoes_rating}% )}
{entry.review && (

{entry.review}

)}
) })}
)} )} {/* Watchlist Tab */} {activeTab === "watchlist" && ( <> {watchlist.length === 0 ? ( ) : (
{watchlist.map((item) => { const url = posterUrl(item.poster_path, "w185") return (
{url ? ( {item.title} ) : (
)}

{item.title}

) })}
)} )} {/* Lists Tab */} {activeTab === "lists" && ( <> {showNewList && (
setNewListName(e.target.value)} placeholder="Listenname..." className="glass-input h-10 flex-1 text-sm" autoFocus />
)} {lists.length === 0 && !showNewList ? ( ) : (
{lists.map((list) => (

{list.name}

{list.description && (

{list.description}

)}
{list.list_items?.[0]?.count || 0} Filme ))}
)} )}
) } function EmptyState({ icon: Icon, title, description, href, }: { icon: typeof BookOpen title: string description: string href?: string }) { return (

{title}

{description}

{href && ( Los geht's )}
) }