import React, { createContext, useContext } from 'react'; import { useFileOperations, type FilePreviewResult } from '../hooks/useFiles'; interface FileContextType { handleFileUpload: (file: File, workflowId?: string) => Promise<{ success: boolean; fileData?: any; error?: string }>; handleFileDelete: (fileId: string, onOptimisticDelete?: () => void) => Promise; handleFilePreview: (fileId: string, fileName: string, mimeType?: string) => Promise; handleFileDownload: (fileId: string, fileName: string) => Promise; uploadingFile: boolean; deletingFiles: Set; previewingFiles: Set; downloadingFiles: Set; } export const FileContext = createContext(undefined); export function FileProvider({ children }: { children: React.ReactNode }) { const { handleFileUpload: hookHandleFileUpload, handleFileDelete: hookHandleFileDelete, handleFilePreview, handleFileDownload, uploadingFile, deletingFiles, previewingFiles, downloadingFiles, } = useFileOperations(); return ( { await handleFileDownload(fileId, fileName); }, uploadingFile, deletingFiles, previewingFiles, downloadingFiles, }} > {children} ); } export function useFileContext() { const context = useContext(FileContext); if (context === undefined) { throw new Error('useFileContext must be used within a FileProvider'); } return context; }