import { calendarService } from '$lib/services/calendar';
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ params, parent }) => {
	const parentData = await parent();
	const eventId = params.event;

	const eventResult = await calendarService.getEvent(eventId);

	if (eventResult.error) {
		throw error(404, {
			message: eventResult.error.message || 'Event not found'
		});
	}

	if (!eventResult.data) {
		throw error(404, {
			message: 'Event not found'
		});
	}

	return {
		event: eventResult.data,
		teamProfiles: parentData.team?.data?.teamProfiles ?? []
	};
};
