import { render } from 'vike/abort'; /* eslint-disable-line import/extensions */
import { fetchActorRevisions } from '#/src/actors.js';

export async function onBeforeRender(pageContext) {
	if (!pageContext.user || pageContext.user.role === 'user') {
		throw render(404);
	}

	const {
		revisions,
		avatars,
	} = await fetchActorRevisions(null, {
		isFinalized: false,
		limit: 50,
	}, pageContext.user);

	return {
		pageContext: {
			title: pageContext.routeParams.section,
			pageProps: {
				revisions,
				avatars,
			},
		},
	};
}
