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

const EditTrainingPage = () => {
  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>
  console.log(data?.training)
  if (data?.training) return <EditTraining training={data.training} />
  else return <p>Training {id} not found.</p>
}

export default EditTrainingPage
