{
  "name": "social-hooks-usefriends",
  "type": "registry:hook",
  "dependencies": [
    "@tanstack/react-query",
    "bmap-api-types"
  ],
  "devDependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "components/social/hooks/useFriends.ts",
      "type": "registry:hook",
      "content": "// useFriends Hook - Fetch and manage friends list\nimport { useQuery } from \"@tanstack/react-query\";\nimport type { Friend } from \"bmap-api-types\";\nimport { useBitcoinAuth } from \"../../../hooks/useBitcoinAuth.js\";\nimport { API_ENDPOINTS, DEFAULT_SOCIAL_API_URL } from \"../constants.js\";\nimport type { SocialError } from \"../types/social.js\";\n\n// Export for use in other components\nexport interface FriendRequest {\n\tbapId: string;\n\ttxid: string;\n\theight: number;\n}\n\ninterface FriendData {\n\tfriends: Friend[];\n\tincoming: FriendRequest[];\n\toutgoing: FriendRequest[];\n}\n\ninterface UseFriendsResult {\n\tfriends: Friend[];\n\tincoming: FriendRequest[];\n\toutgoing: FriendRequest[];\n\tisLoading: boolean;\n\terror: SocialError | null;\n\trefetch: () => void;\n}\n\nexport function useFriends(): UseFriendsResult {\n\tconst { user, isAuthenticated, config } = useBitcoinAuth();\n\n\tconst {\n\t\tdata: friendData,\n\t\tisLoading,\n\t\terror,\n\t\trefetch,\n\t} = useQuery<FriendData, SocialError>({\n\t\tqueryKey: [\"friends\", user?.idKey],\n\t\tqueryFn: async () => {\n\t\t\tif (!user?.idKey) {\n\t\t\t\tthrow {\n\t\t\t\t\tcode: \"UNAUTHORIZED\",\n\t\t\t\t\tmessage: \"User must be authenticated\",\n\t\t\t\t} as SocialError;\n\t\t\t}\n\n\t\t\tconst apiUrl = config?.apiUrl || DEFAULT_SOCIAL_API_URL;\n\t\t\tconst response = await fetch(\n\t\t\t\t`${apiUrl}${API_ENDPOINTS.FRIENDS(user.idKey)}`,\n\t\t\t);\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow {\n\t\t\t\t\tcode: \"NETWORK_ERROR\",\n\t\t\t\t\tmessage: \"Failed to fetch friends\",\n\t\t\t\t} as SocialError;\n\t\t\t}\n\n\t\t\treturn response.json();\n\t\t},\n\t\tenabled: isAuthenticated && !!user?.idKey,\n\t\tstaleTime: 5 * 60 * 1000, // 5 minutes\n\t\trefetchOnWindowFocus: false,\n\t});\n\n\treturn {\n\t\tfriends: friendData?.friends || [],\n\t\tincoming: friendData?.incoming || [],\n\t\toutgoing: friendData?.outgoing || [],\n\t\tisLoading,\n\t\terror: error || null,\n\t\trefetch,\n\t};\n}\n",
      "target": "<%- config.aliases.hooks %>/usefriends.ts"
    }
  ]
}