import { useMemo } from 'react';
import { useQuery } from '@tanstack/react-query';
import { apiFetch } from '../lib/api';

export function useFollowing(): Set<string> {
  const { data, error } = useQuery({
    queryKey: ['me-following'],
    queryFn: async () => {
      const r = await apiFetch<{ userIds: string[] }>('/api/me/following');
      console.log('[presence] /api/me/following →', r.userIds?.length ?? 0, 'IDs:', r.userIds);
      return r;
    },
    staleTime: 5 * 60_000,
  });
  if (error) console.warn('[presence] /api/me/following ERROR:', error);
  return useMemo(() => new Set(data?.userIds ?? []), [data]);
}
