/**
 * useApi — React hook wrapping ApiClient.
 *
 * Returns a memoized ApiClient instance stable for the lifetime of the
 * component, or until `config` reference changes.  No teardown is needed
 * because ApiClient holds no open resources.
 */
import { useMemo } from 'react'
import { ApiClient } from '../../services/api'
import type { ApiClientConfig } from '../../services/api'

export type { ApiClientConfig }

/**
 * @param config - Optional configuration forwarded verbatim to ApiClient.
 *   Pass a stable reference (e.g. a module-level constant or useMemo'd
 *   object) to prevent unnecessary client re-creation across renders.
 * @returns A memoized `ApiClient` instance.
 */
export function useApi(config?: ApiClientConfig): ApiClient {
  return useMemo(() => new ApiClient(config ?? {}), [config])
}
