Repository Public
1"use client";2import { useEffect } from "react";3import Link from "next/link";4import { Info } from "lucide-react";5import { api, cn, duration, RIGHTS_LABEL, useApi, type Title, type TitleDetail, type TitleFull } from "@/lib/client";6import { Empty, FavButton, PlayButton, TitleRow } from "./ui";7import { useVod } from "./vod-player";89/** Large banner for one title that really has artwork and a source. */10export function Banner({ title, eyebrow }: { title: TitleFull; eyebrow?: string }) {11 const { playMedia } = useVod();12 const start = async () => { const d = await api<TitleDetail>(`/titles/${title.id}`); if (d.resume) playMedia(d.resume.mediaId); };13 return (14 <section className="relative isolate overflow-hidden">15 <div className="absolute inset-0 -z-10">16 {(title.backdrop ?? title.poster) && <img src={title.backdrop ?? title.poster!} alt="" referrerPolicy="no-referrer" className="h-full w-full object-cover object-top opacity-70" />}17 <div className="hero-fade absolute inset-0" />18 </div>19 <div className="flex min-h-[26rem] flex-col justify-end px-4 pb-7 pt-24 sm:min-h-[30rem] lg:min-h-[34rem] lg:px-8 lg:pb-10">20 {eyebrow && <p className="eyebrow text-white/70">{eyebrow}</p>}21 <h1 className="mt-1.5 max-w-3xl text-[2.1rem] font-bold leading-[1.04] sm:text-5xl lg:text-6xl">{title.title}</h1>22 <p className="mt-3 flex flex-wrap items-center gap-2 text-sm text-dim">23 {title.year && <span className="font-semibold text-ink">{title.year}</span>}{title.kind === "movie" ? title.runtime && <span>{duration(title.runtime)}</span> : <span>{title.episodes} épisodes</span>}24 {title.genres.slice(0, 3).map((g) => <span key={g} className="chip">{g}</span>)}<span className="chip">{RIGHTS_LABEL[title.rights]}</span>25 </p>26 {title.synopsis && <p className="mt-3 line-clamp-3 max-w-2xl text-[15px] leading-relaxed text-ink/85">{title.synopsis}</p>}27 <div className="mt-5 flex flex-wrap gap-3">28 <PlayButton onClick={start} autoFocus />29 <Link href={`/titre/${title.id}`} data-nav className="inline-flex h-12 items-center gap-2 rounded-full bg-white/10 px-5 text-sm font-semibold backdrop-blur hover:bg-white/15"><Info className="h-5 w-5" />Détails</Link>30 <FavButton title={title} />31 </div>32 </div>33 </section>34 );35}3637interface Data { rows: { key: string; title: string; items: Title[]; href: string | null }[]; hero: TitleFull | null; facets: { genres: { id: string; count: number }[]; total: number } }3839export function VodSection({ section, heading, empty, catalogue, genreLinks }: { section: "films" | "series" | "docs" | "library"; heading: string; empty: React.ReactNode; catalogue: string; genreLinks?: boolean }) {40 const { data, error, loading, reload } = useApi<Data>(`/vod/home?section=${section}`);41 const { version } = useVod();42 useEffect(() => { if (version) reload(); }, [version, reload]);43 if (loading && !data) return <div className="space-y-6 p-4 lg:p-8"><div className="skeleton h-80 rounded-3xl" />{[0, 1].map((i) => <div key={i} className="skeleton h-48 rounded-2xl" />)}</div>;44 if (error && !data) return <Empty title="Impossible de charger cette section">{error}</Empty>;45 if (!data) return null;46 if (!data.rows.length) return <div className="pt-6"><h1 className="px-4 text-2xl font-bold tracking-tight lg:px-8 lg:text-3xl">{heading}</h1><Empty title="Rien à afficher pour l'instant">{empty}</Empty></div>;47 return (48 <div className="space-y-6 pb-6 lg:space-y-8">49 {data.hero ? <Banner title={data.hero} eyebrow={heading} /> : <h1 className="px-4 pt-6 text-2xl font-bold tracking-tight lg:px-8 lg:text-3xl">{heading}</h1>}50 {genreLinks && data.facets.genres.length > 0 && (51 <div className="no-scrollbar -mt-2 flex gap-2 overflow-x-auto px-4 lg:px-8">52 <Link href={catalogue} data-nav className={cn("flex h-10 shrink-0 items-center rounded-full bg-white px-4 text-sm font-semibold text-black")}>Tout le catalogue · {data.facets.total.toLocaleString("fr-CA")}</Link>53 {data.facets.genres.slice(0, 14).map((g) => <Link key={g.id} href={`${catalogue}${catalogue.includes("?") ? "&" : "?"}genre=${encodeURIComponent(g.id)}`} className="flex h-10 shrink-0 items-center rounded-full bg-white/10 px-4 text-sm font-medium hover:bg-white/15">{g.id}</Link>)}54 </div>55 )}56 {data.rows.map((r) => <TitleRow key={r.key} title={r.title} items={r.items} href={r.href} wide={r.key === "continue"} />)}57 </div>58 );59}60