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

export const load: PageServerLoad = async (event) => {
	const { url, locals } = event;
	const tab = url.searchParams.get('tab') ?? 'all';
	const includeArchived = tab === 'archived';

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

	const result = await new GetMyConversationsStore().fetch({
		...fetchParams,
		variables: {
			includeArchived,
			first: 50
		}
	});

	return {
		conversations: result
	};
};
