import { useRouter } from 'next/router'
import { useFileQuery } from '../../../src/gql'
import EditFile from '../../../src/file/components/EditFile'
import { AdminPage } from '../../../src/app'

const EditFilePage = () => {
  const router = useRouter()
  const { id } = router.query

  const { data = { file: undefined }, error = undefined, loading = false } =
    typeof id === 'string' ? useFileQuery({ variables: { where: { id } } }) : {}

  let content
  if (error) content = <p>Error loading video.</p>
  else if (loading) content = <p>Loading video...</p>
  else content = <EditFile file={data.file} />
  return <AdminPage>{content}</AdminPage>
}

export default EditFilePage
