import { Link } from 'react-router-dom'; import type { TmdbEntry } from '@/types'; function formatRelativeTime(dateStr: string): string { const now = new Date(); const release = new Date(dateStr); const diffMs = release.getTime() - now.getTime(); if (diffMs <= 0) return 'Out now'; const totalMinutes = Math.floor(diffMs / 60000); const totalHours = Math.floor(totalMinutes / 60); const totalDays = Math.floor(totalHours / 24); const months = Math.floor(totalDays / 30); const remDays = totalDays % 30; if (months > 0 && remDays > 0) return `in ${months}m ${remDays}d`; if (months > 0) return `in ${months}m`; if (totalDays > 0) return `in ${totalDays} day${totalDays !== 1 ? 's' : ''}`; if (totalHours > 0) return `in ${totalHours} hour${totalHours !== 1 ? 's' : ''}`; if (totalMinutes > 0) return `in ${totalMinutes} min`; return 'Very soon'; } interface UpcomingCardProps { entry: TmdbEntry; } export function UpcomingCard({ entry }: UpcomingCardProps) { const title = entry.title || entry.name || 'Untitled'; const poster = entry.poster_path ? `https://image.tmdb.org/t/p/w185${entry.poster_path}` : null; const isTv = entry.media_type === 'tv' || !!entry.name; const linkTo = `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${entry.id}`; const releaseDate = entry.release_date || entry.first_air_date; const relativeTime = releaseDate ? formatRelativeTime(releaseDate) : null; return (
{new Date(releaseDate).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', })}