import { redirect } from '@/i18n/navigation';

interface PageParams {
  params: Promise<{ id: string }>;
  searchParams: Promise<Record<string, string>>;
}

export default async function TimelineRedirect({ params, searchParams }: PageParams) {
  const { id } = await params;
  const search = await searchParams;

  if (!id) {
    redirect({ href: '/alkotok', locale: 'hu' });
    return;
  }

  type TargetPath =
    | '/alkoto/[id]/alkotasok'
    | '/alkoto/[id]/eletut-esemenyek'
    | '/alkoto/[id]/mma-hirek';

  // redirect old category query param pages (there were hu versions only before)
  const kategoria = search.kategoria || search.category;
  let targetPath: TargetPath = '/alkoto/[id]/alkotasok'; // default

  if (kategoria === 'alkotas') {
    targetPath = '/alkoto/[id]/alkotasok';
  } else if (kategoria === 'eletut') {
    targetPath = '/alkoto/[id]/eletut-esemenyek';
  } else if (kategoria === 'mma-hir') {
    targetPath = '/alkoto/[id]/mma-hirek';
  }

  redirect({
    href: { pathname: targetPath, params: { id } },
    locale: 'hu',
  });
}
