import { fetchActors } from '#/src/actors.js';
import { curateActorsQuery } from '#/src/web/actors.js';

export async function onBeforeRender(pageContext) {
	const {
		actors,
		countries,
		cupRange,
		limit,
		total,
	} = await fetchActors(curateActorsQuery(pageContext.urlQuery), {
		page: Number(pageContext.routeParams.page) || 1,
		limit: Number(pageContext.urlParsed.search.limit) || 120,
		order: pageContext.urlParsed.search.order?.split('.') || ['likes', 'desc'],
	}, pageContext.user);

	return {
		pageContext: {
			pageProps: {
				actors,
				countries,
				cupRange,
				limit,
				total,
			},
		},
	};
}
