import type { PageServerLoad } from './$types';
import { fetchSponsors } from '$lib/server/github';
import { fetchPublications } from '$lib/server/atproto/publications';
import { fetchLatestPosts } from '$lib/server/atproto/documents';
import { fetchSubscriberCounts } from '$lib/server/atproto/interactions';
import { fetchCurrentlyReading } from '$lib/server/atproto/books';
import { fetchNowPlaying } from '$lib/server/atproto/music';

export const load: PageServerLoad = async ({ fetch }) => {
	const [sponsors, publications] = await Promise.all([fetchSponsors(fetch), fetchPublications()]);

	// Stream the Free Time data (not awaited) so it loads behind skeletons instead of
	// blocking the page — nowPlaying in particular hits rate-limited MusicBrainz APIs.
	return {
		sponsors,
		publications,
		latestPosts: fetchLatestPosts(),
		subscriberCounts: fetchSubscriberCounts(),
		currentlyReading: fetchCurrentlyReading(),
		nowPlaying: fetchNowPlaying(fetch)
	};
};
