"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { useTranslations } from "next-intl"; import { Download, Loader2, X } from "lucide-react"; import { apiFetch } from "@/lib/api/fetch"; import type { MyExport, MyRenderJob } from "@/lib/api/my-renders"; function humanSize(n?: number | null): string { if (!n) return "—"; const u = ["B", "KB", "MB", "GB"]; let i = 0, v = n; while (v >= 1024 && i < u.length - 1) { v /= 1024; i++; } return `${v.toFixed(v < 10 && i > 0 ? 1 : 0)} ${u[i]}`; } export function MyRenders({ jobs, exports }: { jobs: MyRenderJob[]; exports: MyExport[] }) { const t = useTranslations("auto.componentsDashboardMyRenders"); const router = useRouter(); const [busy, setBusy] = useState(null); const cancel = async (id: string) => { if (!confirm(t("confirm"))) return; setBusy(id); try { await apiFetch(`/api/renders/${id}/cancel`, { method: "POST" }); router.refresh(); } finally { setBusy(null); } }; const download = async (id: string) => { setBusy(id); try { const r = await apiFetch(`/api/exports/${id}/download`).then((x) => x.json()).catch(() => null); if (r?.url) window.open(r.url, "_blank"); } finally { setBusy(null); } }; const card = "rounded-xl border border-gray-100 bg-white shadow-sm"; return (

{t("title")}

{t("subtitle")}

{/* Processing */}

{t("processing")}

{jobs.length === 0 ? (

{t("empty")}

) : (
{jobs.map((j) => { const failed = j.step === "Failed"; const pct = Math.round(j.render_progress ?? 0); return (

{j.title || j.project_name || j.name || j.id.slice(0, 8)}

{j.quality} · {j.resolution} · {failed ? t("failed") : j.step}

{!failed && (
)} {failed && j.failed_message &&

{j.failed_message}

}
{failed ? "" : `${pct}%`}
); })}
)}
{/* Ready exports */}

{t("ready")}

{exports.length === 0 ? (

{t("emptyReady")}

) : (
{exports.map((e) => (
{e.image ? ( // eslint-disable-next-line @next/next/no-img-element ) : ( {e.file_extension ?? "video"} )}

{e.render_quality} · {e.width && e.height ? `${e.width}×${e.height}` : "—"} · {humanSize(e.size_bytes)} {e.duration_sec ? ` · ${Math.round(e.duration_sec)}s` : ""}

))}
)}
); }