import { redirect } from 'next/navigation'

type CoursePageProps = {
  params: Promise<{ slug: string[] }>,
}

export default async function CourseCatchAllRoute({ params }: CoursePageProps) {
  const { slug } = await params

  // If URL starts with a number (e.g., /courses/2612/project-management...), redirect to /courses/slug
  if (slug && slug.length > 0 && /^[0-9]+$/.test(slug[0])) {
    const courseSlug = slug.slice(1).join('/')
    redirect(`/courses/${courseSlug}`)
  }

  // For any other catch-all, show 404
  redirect('/services/upcoming-courses')
}
