import { redirect } from 'next/navigation'
import { requireSession } from '@/lib/auth-guard'
import { resolveActiveSprint } from '@/lib/active-sprint'

interface Props {
  params: Promise<{ id: string }>
}

export default async function SprintRedirectPage({ params }: Props) {
  const { id } = await params
  const session = await requireSession()
  const active = await resolveActiveSprint(id, session.userId)
  if (!active) {
    redirect(`/products/${id}?alert=no_sprint`)
  }
  redirect(`/products/${id}/sprint/${active.id}`)
}
