import Link from "next/link";
import { requireSession } from "@/lib/auth";
import { canManageSettings } from "@/lib/rbac";
import { PageHeader, EmptyState } from "@/components/ui";
import { REQUIRED_COLUMNS, OPTIONAL_COLUMNS } from "@/lib/import";
import { ImportForm } from "./import-form";

export const dynamic = "force-dynamic";

export default async function ImportPage() {
  const session = await requireSession();

  if (!canManageSettings(session)) {
    return (
      <>
        <PageHeader title="Nhập dữ liệu từ Excel" />
        <EmptyState
          message="Bạn không có quyền nhập dữ liệu."
          hint="Chức năng này chỉ dành cho Ban giám đốc."
        />
      </>
    );
  }

  return (
    <>
      <PageHeader
        title="Nhập dữ liệu từ Excel"
        subtitle="Đưa danh mục sản phẩm, danh sách khách hàng và đơn hàng lịch sử vào hệ thống."
        actions={
          <Link href="/danh-muc" className="btn-ghost">
            ← Danh mục
          </Link>
        }
      />
      <ImportForm requiredColumns={REQUIRED_COLUMNS} optionalColumns={OPTIONAL_COLUMNS} />
    </>
  );
}
