import { redirect } from "next/navigation"

import { auth } from "@/auth"
import { AdminSettingsView } from "@/modules/settings/components/admin-settings-view"
import { StudentSettingsView } from "@/modules/settings/components/student-settings-view"
import { TeacherSettingsView } from "@/modules/settings/components/teacher-settings-view"

export const dynamic = "force-dynamic"

export default async function SettingsPage() {
  const session = await auth()
  if (!session?.user) redirect("/login")

  const role = String(session.user.role ?? "teacher")

  if (role === "admin") return <AdminSettingsView />
  if (role === "student") return <StudentSettingsView user={session.user} />
  if (role === "teacher") return <TeacherSettingsView user={session.user} />

  redirect("/dashboard")
}
