import type { Metadata } from "next"
import type { JSX } from "react"

import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import {
  getFileAttachmentsWithFilters,
  getFileStats,
} from "@/modules/files/data-access"
import { AdminFilesView } from "@/modules/files/components/admin-files-view"

export const metadata: Metadata = {
  title: "文件管理 - Next_Edu",
  description: "查看与管理系统中所有上传文件",
}

export const dynamic = "force-dynamic"

export default async function AdminFilesPage(): Promise<JSX.Element> {
  await requirePermission(Permissions.FILE_READ)
  const [files, stats] = await Promise.all([
    getFileAttachmentsWithFilters({ limit: 200 }),
    getFileStats(),
  ])

  return <AdminFilesView files={files} stats={stats} />
}
