"use client"; import { useState, useEffect } from "react"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; const FORMAT_LABELS: Record = { "instagram-feed": { label: "Instagram Feed", dimensions: "1080x1080" }, "instagram-stories": { label: "Instagram Stories", dimensions: "1080x1920" }, tiktok: { label: "TikTok", dimensions: "1080x1920" }, "nextdoor-spotlight": { label: "Nextdoor Spotlight", dimensions: "1200x1200" }, "nextdoor-display": { label: "Nextdoor Display", dimensions: "1200x628" }, }; interface RepurposeModalProps { assetId: string; onClose: () => void; } export function RepurposeModal({ assetId, onClose }: RepurposeModalProps) { const [available, setAvailable] = useState([]); const [selected, setSelected] = useState>(new Set()); const [loading, setLoading] = useState(false); const [result, setResult] = useState<{ formats?: string[] } | null>(null); useEffect(() => { fetch(`/api/assets/${assetId}/repurpose`) .then((r) => r.json()) .then((data) => { setAvailable(data.formats || []); setSelected(new Set(data.formats || [])); }) .catch(() => {}); }, [assetId]); async function handleRepurpose() { setLoading(true); const res = await fetch(`/api/assets/${assetId}/repurpose`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ formats: Array.from(selected) }), }); const data = await res.json(); setResult(data); setLoading(false); } function toggle(key: string) { setSelected((prev) => { const next = new Set(prev); if (next.has(key)) next.delete(key); else next.add(key); return next; }); } return ( Repurpose Asset Resize this image for other platforms. Captions will be re-toned to match each platform. {result ? (

Repurposing to {result.formats?.length || 0} format{(result.formats?.length || 0) !== 1 ? "s" : ""}

Gemini is regenerating the ad at each new size. New assets will appear in the Asset Library when ready.

) : ( <>
{available.map((key) => { const fmt = FORMAT_LABELS[key]; if (!fmt) return null; return ( ); })}
)}
); }