import { requireAuth } from "@/shared/lib/auth-guard"
import { getParentDashboardData } from "@/modules/parent/data-access"
import { ParentDashboard } from "@/modules/parent/components/parent-dashboard"
import { ParentNoChildrenPage } from "@/modules/parent/components/parent-children-data-page"
import { Users } from "lucide-react"

export const dynamic = "force-dynamic"

export const metadata = { title: "Dashboard - Next_Edu" }

export default async function ParentDashboardPage() {
  const ctx = await requireAuth()

  // 非 admin 且 dataScope 非 children 类型时，显示空状态
  if (
    ctx.dataScope.type !== "all" &&
    !(ctx.dataScope.type === "children" && ctx.dataScope.childrenIds.length > 0)
  ) {
    return (
      <div className="p-6 md:p-8">
        <ParentNoChildrenPage
          title="Parent Dashboard"
          description="Here's an overview of your children."
          icon={Users}
          emptyTitle="No children linked"
          emptyDescription="Your account is not linked to any student accounts yet. Please contact the school administrator."
        />
      </div>
    )
  }

  const data = await getParentDashboardData(ctx.userId)

  return (
    <div className="p-6 md:p-8">
      <ParentDashboard data={data} />
    </div>
  )
}
