import { useQuery } from '@tanstack/react-query';
import { fetchLocalFiles } from '../api';

export function useLocalFiles(
  taskId: number | null,
  section: 'workspace' | 'input' | 'output' | 'logs',
  path: string,
  enabled: boolean,
) {
  return useQuery({
    queryKey: ['localFiles', taskId, section, path],
    queryFn: () => {
      if (taskId === null) throw new Error('No task');
      return fetchLocalFiles(taskId, section, path);
    },
    enabled: enabled && taskId !== null,
  });
}
