const fs = require('fs');
const paths = [
'src/app/horaires/train/[trainNumber]/page.tsx',
'src/app/[region]/horaires/train/[trainNumber]/page.tsx',
'src/app/se-deplacer/horaires/train/[trainNumber]/page.tsx',
'src/app/[region]/se-deplacer/horaires/train/[trainNumber]/page.tsx'
];
paths.forEach(p => {
if (fs.existsSync(p)) {
let content = fs.readFileSync(p, 'utf8');
// Check if searchParams is already included
if (!content.includes('searchParams')) {
content = content.replace(/params: Promise<\{([\s\S]*?)\}>;/, 'params: Promise<{$1}>;\n searchParams?: Promise<{ [key: string]: string | string[] | undefined }>;');
content = content.replace(/export default async function (.*)\(\{ params \}: (.*)\) \{/, 'export default async function $1({ params, searchParams }: $2) {');
content = content.replace(/const \{ (.*) \} = await params;/, 'const { $1 } = await params;\n const resolvedSearchParams = searchParams ? await searchParams : {};\n const dateStr = typeof resolvedSearchParams.date === \'string\' ? resolvedSearchParams.date : undefined;');
content = content.replace(//, '');
fs.writeFileSync(p, content);
console.log(`Updated ${p}`);
} else {
console.log(`Already has searchParams ${p}`);
}
} else {
console.log(`Not found: ${p}`);
}
});