import { useState } from "react"; import ViewTransitionLink from "@/components/ViewTransitionLink"; import MediaItemMenu from "@/components/MediaItemMenu"; import CardOverlays from "@/components/overlays/CardOverlays"; import { decodeThumbhash } from "@/lib/thumbhash"; import { useOverlayPrefs } from "@/hooks/useOverlayPrefs"; import { overlayDataFromSectionItem } from "@/lib/overlays"; import { buildEpisodeCardLabels } from "@/lib/episodeCardLabels"; import { formatUpcomingDate, formatUpcomingSubtitle, formatUpcomingTime, upcomingBadgeClass, upcomingBadgeLabel, } from "@/lib/upcomingEventPresentation"; import type { SectionItem } from "@/api/types"; interface SectionItemCardProps { item: SectionItem; libraryId?: number; } export default function SectionItemCard({ item, libraryId }: SectionItemCardProps) { const [loaded, setLoaded] = useState(false); const thumbhashUrl = item.poster_thumbhash ? decodeThumbhash(item.poster_thumbhash) : ""; const itemHref = `/item/${item.content_id}${libraryId ? `?libraryId=${libraryId}` : ""}`; const { prefs: overlayPrefs } = useOverlayPrefs(); const upcomingEvent = item.upcoming_event; const subtitle = upcomingEvent ? formatUpcomingSubtitle(upcomingEvent) : ""; const airDateLabel = upcomingEvent ? formatUpcomingDate(upcomingEvent.air_date) : ""; const airTimeLabel = upcomingEvent ? formatUpcomingTime(upcomingEvent.air_time) : null; const episodeLabels = !upcomingEvent ? buildEpisodeCardLabels(item) : null; return (
{item.poster_url ? ( {item.title} setLoaded(true)} /> ) : (
{item.title || "No Poster"}
)}
{item.status === "ambiguous" && ( Ambiguous )} {item.status === "matched" && overlayPrefs && ( )} {upcomingEvent && upcomingEvent.badges.length > 0 && (
{upcomingEvent.badges.map((badge) => ( {upcomingBadgeLabel(badge)} ))}
)}
{episodeLabels ? episodeLabels.seriesTitle : item.title}
{upcomingEvent ? ( <> {subtitle && (
{subtitle}
)}
{airDateLabel} {airTimeLabel && {airTimeLabel}}
) : episodeLabels ? ( <> {episodeLabels.episodeTitle ? (
{episodeLabels.episodeTitle}
) : null}
{episodeLabels.episodeCode}
) : (
{item.year ? `${item.year}` : ""} {item.type === "series" ? "Series" : ""}
)}
); }