import { useRef } from 'react' import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' import { queryOptions } from '@tanstack/react-query' import { api } from '@/lib/api-client' import { useAuthStore } from '@/stores/auth.store' import { Button } from '@/components/ui/button' import { ImageIcon, Plus, Trash2 } from 'lucide-react' import { toast } from 'sonner' interface FileRecord { id: string path: string category: string filename: string } function ticketFilesOptions(ticketId: string) { return queryOptions({ queryKey: ['files', 'repair_ticket', ticketId], queryFn: () => api.get<{ data: FileRecord[] }>('/v1/files', { entityType: 'repair_ticket', entityId: ticketId }), enabled: !!ticketId, }) } const PHOTO_CATEGORIES = [ { key: 'intake', label: 'Intake Photos', description: 'Condition at intake' }, { key: 'in_progress', label: 'Work in Progress', description: 'During repair' }, { key: 'completed', label: 'Completed', description: 'Final result' }, ] as const interface TicketPhotosProps { ticketId: string currentStatus: string } export function TicketPhotos({ ticketId, currentStatus }: TicketPhotosProps) { const queryClient = useQueryClient() const token = useAuthStore((s) => s.token) const { data: filesData } = useQuery(ticketFilesOptions(ticketId)) const files = filesData?.data ?? [] // Determine which category to highlight based on current status const activeCategory = ['in_progress', 'pending_parts'].includes(currentStatus) ? 'in_progress' : ['ready', 'picked_up', 'delivered'].includes(currentStatus) ? 'completed' : 'intake' return (
{description}
No photos
) : (