import type { RequestHandler } from './$types';
import { backendFetch } from '$lib/server/scraper';

/**
 * GET /api/translation/status/[slug]/[n]?lang=<lang>
 * Proxies the translation status check to the backend.
 */
export const GET: RequestHandler = async ({ params, url }) => {
	const { slug, n } = params;
	const lang = url.searchParams.get('lang') ?? '';
	const res = await backendFetch(
		`/api/translation/status/${encodeURIComponent(slug)}/${n}?lang=${lang}`
	);
	if (!res.ok) {
		return new Response(JSON.stringify({ status: 'idle' }), {
			headers: { 'Content-Type': 'application/json' }
		});
	}
	const data = await res.json();
	return new Response(JSON.stringify(data), {
		headers: { 'Content-Type': 'application/json' }
	});
};
