import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"

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 async function generateMetadata(): Promise<Metadata> {
  const t = await getTranslations("files")
  return {
    title: `${t("title")} - Next_Edu`,
    description: t("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} />
}
