import { useEffect, useState } from 'react'

/**
 * Checks whether web search tools are configured on the server.
 * Calls the existing /api/ai/config endpoint and looks for relevant keys.
 */
export function useWebSearchAvailable(): boolean {
  const [available, setAvailable] = useState(false)

  useEffect(() => {
    fetch('/api/ai/web-search-available')
      .then(r => r.ok ? r.json() : { available: false })
      .then(d => setAvailable(!!d.available))
      .catch(() => setAvailable(false))
  }, [])

  return available
}
