/**
 * Hook for fetching graph nodes
 */

import { useQuery } from '@tanstack/react-query';
import { useSupabaseClient } from '../provider';
import { fetchGraphNodes } from '../queries/nodes';
import { canvasKeys } from './keys';

export interface UseGraphNodesOptions {
	enabled?: boolean;
}

/**
 * Hook to fetch all nodes for a graph
 */
export function useGraphNodes(graphId: string | null, options: UseGraphNodesOptions = {}) {
	const { enabled = true } = options;
	const supabase = useSupabaseClient();

	return useQuery({
		queryKey: canvasKeys.nodes(graphId || ''),
		queryFn: () => fetchGraphNodes(supabase, graphId!),
		enabled: enabled && !!graphId,
	});
}
