'use client'

import AppContextProvider from "@/helpers/context/AppContextProvider"
import CommonView from "@/views/CommonView"
import CourseIndividualContentWrapper from "./_partials/CourseIndividualContentWrapper"
import { APP_BASE_URL } from "@/utils/constants"
import { defaultFetcher } from "@/helpers/fetch.helper"
import useSWR from "swr"
import { useEffect } from "react"
import { useRouter } from "next/navigation"
import { routes } from "@/lib/routes"


const CourseDetailPage : React.FC<{
  params : Record<string,any>
}> = ({params}) => {
  const { id } = params
  const router = useRouter()
  const CourseDetailPage = `${APP_BASE_URL}/api/course/info/${id}` 
  const { data } = useSWR(CourseDetailPage, defaultFetcher);

  console.log(data)


  useEffect(() => {
    if(!id) router.replace(routes.COURSE_LIST_INDEX)
  },[])

  return(
    <AppContextProvider>
      <CommonView>
        <CourseIndividualContentWrapper course_uuid={id}/>
      </CommonView>
    </AppContextProvider>
  )
}

export default CourseDetailPage