"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; import { MoreVertical, ImageIcon, RefreshCw, Trash2, Loader2, Share2, FileArchive, Copy, Check, } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, DialogClose, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { regenerateAction, deleteEpisodeAction, setEpisodeShareAction, } from "@/app/(app)/episodes/actions"; export function EpisodeActions({ episodeId, initialShareId = null, }: { episodeId: string; initialShareId?: string | null; }) { const router = useRouter(); const [busy, setBusy] = useState(false); const [shareOpen, setShareOpen] = useState(false); const [shareId, setShareId] = useState(initialShareId); const [shareToggling, setShareToggling] = useState(false); const [copied, setCopied] = useState(false); const [deleteOpen, setDeleteOpen] = useState(false); const [deleting, setDeleting] = useState(false); const shareUrl = shareId && typeof window !== "undefined" ? `${window.location.origin}/p/${shareId}` : ""; async function regen(type: "art" | "full") { setBusy(true); const res = await regenerateAction(episodeId, type); setBusy(false); if (res.ok) { toast.success(type === "art" ? "Regenerating cover art…" : "Regenerating episode…"); router.refresh(); } else { toast.error(res.error ?? "Could not regenerate"); } } async function toggleShare(enabled: boolean) { setShareToggling(true); const res = await setEpisodeShareAction(episodeId, enabled); setShareToggling(false); if (!res.ok) { toast.error(res.error ?? "Could not update sharing"); return; } setShareId(res.shareId ?? null); toast.success(enabled ? "Public link enabled" : "Sharing turned off"); router.refresh(); } function copyLink() { if (!shareUrl) return; navigator.clipboard .writeText(shareUrl) .then(() => { setCopied(true); toast.success("Link copied"); setTimeout(() => setCopied(false), 1500); }) .catch(() => toast.error("Could not copy")); } async function confirmDelete() { setDeleting(true); const res = await deleteEpisodeAction(episodeId); setDeleting(false); if (res.ok) { toast.success("Episode deleted"); setDeleteOpen(false); router.push("/episodes"); router.refresh(); } else { toast.error(res.error ?? "Could not delete"); } } return ( <>
regen("art")}> Regenerate cover art regen("full")}> Regenerate everything Export ZIP setDeleteOpen(true)} className="text-destructive focus:text-destructive" > Delete episode
{/* Share dialog */} Share this episode Turn on a public link to let anyone listen — no account needed.

Public link

{shareId ? "Anyone with the link can listen." : "Currently private."}

{shareToggling && }
{shareId && (
)}
{/* Delete confirmation */} Delete this episode? This permanently removes the script, audio, cover art and all repurposed content. This cannot be undone. ); }