import { GetReportStore } from '$houdini';
import type { PageServerLoad } from './$types';
import { error } from '@sveltejs/kit';
import { fromGlobalId } from '$lib/utils/relay';

export const load: PageServerLoad = async (event) => {
	const { report: reportId } = event.params;

	const fetchParams = {
		event,
		metadata: { cookie: event.locals.cookie }
	};

	// Fetch the report with full details
	const report = await new GetReportStore().fetch({
		...fetchParams,
		variables: {
			id: reportId
		}
	});

	if (!report.data?.report) {
		throw error(404, 'Report not found');
	}

	return {
		report: report.data.report,
		reportUuid: fromGlobalId(reportId)
	};
};
