import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ locals, url }) => {
	const { member } = await locals.safeGetSession();

	if (!member) {
		return { notifications: [], expandedId: null };
	}

	const { data: notifications } = await locals.supabase
		.from('notifications')
		.select('*')
		.eq('member_id', member.id)
		.order('created_at', { ascending: false });

	// Get the ID from query param to auto-expand that notification
	const expandedId = url.searchParams.get('id');

	return {
		notifications: notifications || [],
		expandedId
	};
};
