import { useRouter } from 'next/router'
import { Training } from '../../src/training'
import { useTrainingQuery } from '../../src/gql'

const TrainingPage = () => {
  const router = useRouter()
  const { id } = router.query
  const { data, error, loading } = useTrainingQuery({
    variables: { id: typeof id === 'string' ? id : id[0] }
  })

  if (loading) return <p>Loading data...</p>
  if (error) return <p>Error loading data.</p>
  if (data?.training) return <Training training={data.training} />
  else return <p>Training {id} not found.</p>
}

export default TrainingPage
