import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ url }) => {
	// Preservar parámetros relevantes al redirigir al nuevo flujo en Despacho
	const dodaId = url.searchParams.get('doda_id');
	const integrationNumber = url.searchParams.get('integration_number');

	const target = new URL('/dashboard/despacho/doda', url.origin);
	if (dodaId) target.searchParams.set('doda_id', dodaId);
	if (integrationNumber) target.searchParams.set('integration_number', integrationNumber);

	throw redirect(303, `${target.pathname}${target.search}`);
};
