import { useState, useCallback } from 'react';

export function useCallTool() {
  const [loading, setLoading] = useState(false);
  const [error, setError] = useState<string | null>(null);

  const callTool = useCallback(async (tool: string, args: Record<string, unknown>) => {
    setLoading(true);
    setError(null);

    try {
      // In real MCP app, this would call the MCP server
      // For now, return mock data
      console.log('Calling tool:', tool, args);
      
      // Simulate API call
      await new Promise(resolve => setTimeout(resolve, 500));
      
      return { success: true, data: {} };
    } catch (err) {
      const message = err instanceof Error ? err.message : 'Unknown error';
      setError(message);
      throw err;
    } finally {
      setLoading(false);
    }
  }, []);

  return { callTool, loading, error };
}
