"use client"; import { useState, useTransition, useCallback } from "react"; import { useRouter } from "next/navigation"; import Image from "next/image"; import Link from "next/link"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Badge } from "@/components/ui/badge"; import { Textarea } from "@/components/ui/textarea"; import { cn } from "@/lib/utils"; import { updateShotNotes } from "@/actions/shots"; import { useToast } from "@/components/ui/use-toast"; import { Film, Clock, CheckCircle2, AlertCircle, Calendar, ChevronDown, ChevronRight, Loader2, } from "lucide-react"; import { format } from "date-fns"; type ShotRow = { id: string; shotCode: string; scene: string; episode: string | null; shotNumber: number; status: string; priority: string; dueDate: Date | string | null; thumbnailUrl: string | null; notes: string | null; description: string | null; artist: { id: string; name: string | null; image: string | null; email: string } | null; }; interface Project { id: string; name: string; code: string; projectType: string; } interface ShotStatusClientProps { projects: Project[]; selectedProjectId: string | null; selectedProject: Project | null; shots: ShotRow[]; canManage: boolean; } const STATUS_CONFIG: Record = { WAITING: { label: "Waiting", color: "bg-zinc-500/10 text-zinc-400 border-zinc-500/20", icon: Clock }, IN_PROGRESS: { label: "In Progress", color: "bg-blue-500/10 text-blue-400 border-blue-500/20", icon: Film }, IN_REVIEW: { label: "In Review", color: "bg-purple-500/10 text-purple-400 border-purple-500/20", icon: AlertCircle }, REVISIONS: { label: "Revisions", color: "bg-orange-500/10 text-orange-400 border-orange-500/20", icon: AlertCircle }, COMPLETE: { label: "Complete", color: "bg-emerald-500/10 text-emerald-400 border-emerald-500/20", icon: CheckCircle2 }, }; function NotesCell({ shot, canManage, }: { shot: ShotRow; canManage: boolean; }) { const [value, setValue] = useState(shot.notes ?? ""); const [saved, setSaved] = useState(true); const [isPending, startTransition] = useTransition(); const { toast } = useToast(); const handleBlur = useCallback(() => { if (value === (shot.notes ?? "")) return; startTransition(async () => { try { await updateShotNotes(shot.id, value); setSaved(true); toast({ title: "Notes saved" }); } catch { toast({ title: "Failed to save notes", variant: "destructive" }); } }); }, [value, shot.id, shot.notes, toast]); if (!canManage) { return ( {shot.notes ?? } ); } return (