import type { PageServerLoad } from './$types';
import { listAIJobs, type AIJob } from '$lib/server/pocketbase';
import { log } from '$lib/server/logger';

export type { AIJob };

export const load: PageServerLoad = async () => {
	// Parent layout already guards admin role.
	// Stream jobs so navigation is instant; list populates a moment later.
	const jobs = listAIJobs().catch((e): AIJob[] => {
		log.warn('admin/ai-jobs', 'failed to load ai jobs', { err: String(e) });
		return [];
	});
	return { jobs };
};
