import { useMemo, useState } from 'react' import { motion } from 'framer-motion' import type { WikidataAward } from '../../api/wikidata' interface Props { awards: WikidataAward[] | null | undefined } const PRIORITY_KEYWORDS = [ 'Academy Award', 'Oscar', 'Golden Globe', 'BAFTA', 'Emmy', 'Cannes', 'Palme', 'Berlin', 'Sundance', 'Venice', 'Critics', 'SAG', 'Hugo', 'Nebula', 'Saturn', 'MTV', ] /** * Compact award grid pulled from Wikidata P166. We surface the most * recognised prizes first (Oscars, Globes, BAFTAs, Emmys, etc.), then * dedupe and cap at a sensible count. A "Show all" toggle reveals the * remainder when there are many. */ export default function AwardsBlock({ awards }: Props) { const [expanded, setExpanded] = useState(false) const ordered = useMemo(() => { if (!awards) return [] const seen = new Set() const unique: WikidataAward[] = [] for (const a of awards) { const key = a.label if (seen.has(key)) continue seen.add(key) unique.push(a) } return unique.sort((a, b) => priority(a) - priority(b)) }, [awards]) if (ordered.length === 0) return null const visible = expanded ? ordered : ordered.slice(0, 12) return (
{visible.map((a, i) => ( {a.label} {a.point_in_time && ( {a.point_in_time.slice(0, 4)} )} ))}
{ordered.length > 12 && ( )}
) } function priority(a: WikidataAward): number { const label = a.label || '' for (let i = 0; i < PRIORITY_KEYWORDS.length; i++) { if (label.includes(PRIORITY_KEYWORDS[i])) return i } return PRIORITY_KEYWORDS.length }