import Link from "next/link"; import { User } from "@/lib/api"; import { UserAvatar } from "@/components/user-avatar"; import { formatDistanceToNow, format } from "date-fns"; import { Card, CardContent, CardHeader } from "@/components/ui/card"; import { profileHref } from "@/lib/utils"; function isSafeImageUrl(url: string): boolean { try { const u = new URL(url); return u.protocol === "https:" || u.protocol === "http:"; } catch { return false; } } interface MovieMeta { movieTitle: string; releaseYear?: number; posterUrl?: string | null; rating?: number; comment?: string | null; watchedAt?: string | null; watchlistEntry?: boolean; } interface MovieCardProps { meta: MovieMeta; author: User; createdAt: Date; } function StarRating({ rating, max = 5 }: { rating: number; max?: number }) { return (
{Array.from({ length: max }).map((_, i) => ( ))}
); } export function MovieCard({ meta, author, createdAt }: MovieCardProps) { const isWatchlist = meta.watchlistEntry === true; const year = meta.releaseYear ? ` (${meta.releaseYear})` : ""; const timeAgo = formatDistanceToNow(createdAt, { addSuffix: true }); const watchedDate = meta.watchedAt ? new Date(meta.watchedAt).toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric", }) : null; return (
{author.displayName ?? author.username} {!author.local && ( {author.username.startsWith("@") ? author.username : `@${author.username}`} )}
{meta.posterUrl && isSafeImageUrl(meta.posterUrl) ? ( {meta.movieTitle} ) : (
No poster
)}

{meta.movieTitle} {year && {year}}

{isWatchlist ? (

📋 Want to watch

) : ( <> {meta.rating !== undefined && (
)} {watchedDate && (

Watched {watchedDate}

)} )} {meta.comment && (

{meta.comment}

)}
); }