import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';

export const load: PageServerLoad = async ({ fetch }) => {
	const api = createApiClient(fetch);
	const result = await api.GET('/api/ocr/training-info/global');

	if (!result.response.ok) {
		throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
	}

	return { history: result.data! };
};
