"use client"

import { useQuiz } from "@/client/quiz"
import { getDefaultLayout, IDefaultLayoutPage, IPageHeader } from "@/components/layout/default-layout"
import QuizForm from "@/components/quiz/QuizForm"
import { Alert } from "antd"
import { useRouter } from "next/router"

const pageHeader: IPageHeader = {
  title: "퀴즈",
}

const QuizPage: IDefaultLayoutPage = () => {
  const router = useRouter()
  const pid = router.query.pid as string
  const qid = router.query.qid as string

  const { data, error } = useQuiz({ id: qid })

  if (error) {
    return <Alert message="데이터 로딩 중 오류가 발생했습니다." type="warning" />
  }

  if (data) {
    console.log("data", data)
    return <QuizForm pid={pid} qid={qid} data={data} />
  } else {
    return <></>
  }
}

QuizPage.getLayout = getDefaultLayout
QuizPage.pageHeader = pageHeader

export default QuizPage
