import PageContainer from "@/components/layout/page-container";
import { buttonVariants } from "@/components/ui/button";
import CourseListingPage from "@/features/courses/components/course-listing";
import { requireHRDDashboardAccess } from "@/lib/auth/page-guards";
import { searchParamsCache } from "@/lib/searchparams";
import { cn } from "@/lib/utils";
import { Icons } from "@/components/icons";
import Link from "next/link";
import { SearchParams } from "nuqs/server";

export const metadata = {
  title: "แดชบอร์ด: หลักสูตร",
};

type PageProps = {
  searchParams: Promise<SearchParams>;
};

export default async function Page(props: PageProps) {
  await requireHRDDashboardAccess();

  const searchParams = await props.searchParams;
  searchParamsCache.parse(searchParams);

  return (
    <PageContainer
      pageTitle="หลักสูตร"
      pageDescription="จัดการหลักสูตรภายในบริษัท"
      pageHeaderAction={
        <Link
          href="/dashboard/courses/new"
          className={cn(buttonVariants(), "text-xs md:text-sm")}
        >
          <Icons.add className="mr-2 h-4 w-4" /> เพิ่มหลักสูตร
        </Link>
      }
    >
      <CourseListingPage />
    </PageContainer>
  );
}
