import { genreLabel } from '../lib/genres' import { t } from '../i18n' import { Loader2, Plus, Share2 } from 'lucide-react' import { useState, type CSSProperties } from 'react' import { TOP_CATEGORIES } from '../lib/constants' import { renderTopCard, slug } from '../lib/shareCard' import { cx, formatRating } from '../lib/utils' import { useMedia } from '../store' import type { MediaItem, TopCategory } from '../types' import Poster from './Poster' import { RatingBadge } from './Rating' import TopFiveEditor from './TopFiveEditor' import SharePreview from './SharePreview' import { LinkArrow, SectionTitle } from './ui' /** Chiffre géant en contour (rouge pour le n°1, gris pour les autres). */ function RankNumber({ rank, big }: { rank: number; big?: boolean }) { const style: CSSProperties = { WebkitTextStroke: big ? '2.5px var(--color-accent)' : '2px var(--color-ink-3)', color: 'transparent', fontSize: big ? '10rem' : '5.5rem', lineHeight: 0.8, letterSpacing: '-0.06em', } return ( {rank} ) } function EmptySlot({ rank, onClick, big }: { rank: number; onClick: () => void; big?: boolean }) { return ( ) } export default function TopFive({ onOpen }: { onOpen: (item: MediaItem) => void }) { const { items, settings } = useMedia() const cats = TOP_CATEGORIES.filter((c) => settings.topCategories.includes(c.value)) const [selected, setSelected] = useState() const [editing, setEditing] = useState(false) const [sharing, setSharing] = useState(false) const [preview, setPreview] = useState<{ blob: Blob; filename: string; title: string }>() if (!cats.length) return null const current = cats.find((c) => c.value === selected) ?? cats[0] const byRank = new Map(items.filter((i) => i.top?.category === current.value).map((i) => [i.top!.rank, i])) const first = byRank.get(1) const edit = () => setEditing(true) const share = async () => { setSharing(true) try { const blob = await renderTopCard(current.plural, [1, 2, 3, 4, 5].map((r) => byRank.get(r))) setPreview({ blob, filename: `azuucine-top5-${slug(current.plural)}.png`, title: t('top.shareTitle', { category: current.plural }) }) } finally { setSharing(false) } } return ( <> {sharing ? : } {t('share.share')} {t('common.edit')} } > {t('top.title')} 5 {/* Choix de la catégorie */} {cats.length > 1 && ( {cats.map((c) => ( setSelected(c.value)} className={cx('chip py-1! text-[13px]', current.value === c.value && 'chip-on')}> {c.plural} ))} )} {/* N°1 : grand chiffre rouge + affiche + infos */} {first ? ( onOpen(first)} className="relative z-10 w-32"> ) : ( )} {t('top.number', { rank: 1 })} · {current.plural} {first ? ( <> onOpen(first)} className="mt-1.5 block text-start text-lg font-bold leading-snug"> {first.title} {first.year && {first.year}} {first.genres.length > 0 && {first.genres.slice(0, 3).map(genreLabel).join(' · ')}} > ) : ( {t('top.pickFirst')} )} {/* N°2 à 5 : chiffres en contour qui dépassent derrière les affiches */} {[2, 3, 4, 5].map((rank) => { const item = byRank.get(rank) return ( {item ? ( onOpen(item)} className="block w-full"> ) : ( )} {item ? item.title : '—'} {item?.rating ? {formatRating(item.rating, settings.ratingScale)}/{settings.ratingScale} : null} ) })} {preview && setPreview(undefined)} />} {editing && setEditing(false)} />} > ) }
{first.genres.slice(0, 3).map(genreLabel).join(' · ')}
{t('top.pickFirst')}
{item ? item.title : '—'}
{formatRating(item.rating, settings.ratingScale)}/{settings.ratingScale}