'use client'
import BreadCrumbNav from "@/components/(dashboard)/common/BreadCumbNav/BreadCrumbNav"
import ContentContainer from "@/components/(dashboard)/elements/ContentContainer"
import { PageHeading } from "@/components/(dashboard)/ui/title"
import CommonContainer from "@/components/elements/CommonContainer"
import AppContextProvider from "@/helpers/context/AppContextProvider"
import { defaultFetcher } from "@/helpers/fetch.helper"
import { routes } from "@/lib/routes"
import { APP_BASE_URL } from "@/utils/constants"
import AdminView from "@/views/AdminView"
import useSWR from "swr"
import CourseTable from "./_partials/CourseTable"

const CourseIndexPage = () => {
    const CourseListURL = `${APP_BASE_URL}/api/course/listAll`
    const { data, mutate, isLoading } = useSWR(CourseListURL, defaultFetcher);

    return (
        <AppContextProvider>
            <AdminView>
                <CommonContainer>
                    <PageHeading>Courses</PageHeading>
                    <BreadCrumbNav breadCrumbItems={[
                        {
                            title: 'Dashboard',
                            href: routes.DASHBOARD_ROUTE
                        },
                        {
                            title: 'Courses',
                            href: routes.COURSE_INDEX_PAGE
                        },
                    ]}/>
                    <ContentContainer>
                        <div>
                            <CourseTable
                                mutate={mutate}
                                isLoading={isLoading}
                                Data={data?.data || []}
                            />
                        </div>
                    </ContentContainer>
                </CommonContainer>
            </AdminView>
        </AppContextProvider>
    )
}

export default CourseIndexPage