import { fetchScenesById } from '#/src/scenes.js';

function getTitle(scene) {
	if (scene.title) {
		return scene.title;
	}

	if (scene.actors.length > 0) {
		return `Scene with ${scene.actors.map((actor) => actor.name).join(', ')}`;
	}

	return 'Scene';
}

export async function onBeforeRender(pageContext) {
	const [scene] = await fetchScenesById([Number(pageContext.routeParams.sceneId)], {
		reqUser: pageContext.user,
		actorStashes: true,
	});

	return {
		pageContext: {
			title: getTitle(scene),
			pageProps: {
				scene,
			},
		},
	};
}