import { useEffect, useState } from "react"; import { ArrowLeft, Film, Play, Download, Trash2 } from "lucide-react"; interface FilmItem { id: string; render_number: number; final_video_url: string | null; created_at: string; status: string; } interface Project { id: string; title: string; aspect_ratio: string; } interface ProjectFilmsViewProps { projectId: string; onBack: () => void; } export function ProjectFilmsView({ projectId, onBack }: ProjectFilmsViewProps) { const [project, setProject] = useState(null); const [films, setFilms] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); async function load() { setLoading(true); setError(null); try { const [projectRes, filmRes] = await Promise.all([ fetch(`/api/projects/${projectId}`), fetch(`/api/projects/${projectId}/render`), ]); if (!projectRes.ok) throw new Error(`Project ${projectRes.status}`); if (!filmRes.ok) throw new Error(`Films ${filmRes.status}`); const projectData = await projectRes.json(); const filmData = await filmRes.json(); setProject(projectData.project); setFilms(filmData.renders || []); } catch (e) { setError(e instanceof Error ? e.message : "Failed to load"); } finally { setLoading(false); } } useEffect(() => { load(); }, [projectId]); async function deleteFilm(filmId: string) { try { const res = await fetch(`/api/projects/${projectId}/renders/${filmId}`, { method: "DELETE" }); if (!res.ok) throw new Error("Delete failed"); setFilms((prev) => prev.filter((f) => f.id !== filmId)); } catch (e) { setError(e instanceof Error ? e.message : "Delete failed"); } } if (loading) { return (

Loading films…

); } if (error) { return (

{error}

); } const ar = project?.aspect_ratio ?? "9:16"; const aspectClass = ar === "16:9" ? "aspect-[16/9]" : ar === "1:1" ? "aspect-square" : "aspect-[9/16]"; const gridClass = ar === "16:9" ? "grid gap-6 sm:grid-cols-2 max-w-4xl mx-auto" : ar === "1:1" ? "grid gap-4 sm:grid-cols-2 lg:grid-cols-3 max-w-3xl mx-auto" : "grid gap-4 grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 max-w-3xl mx-auto"; return (
{/* Top bar */}

Films

{project?.title}

{films.length} film{films.length !== 1 ? "s" : ""}
{/* Main */}
{films.length === 0 ? (

No films yet.

Go back and hit Re-render to create one.

) : (
{films.map((f) => (
{f.final_video_url ? (
{new Date(f.created_at).toLocaleString()} {f.status}
Watch Download
))}
)}
); }