import DynamicListPageUI from './DynamicListPageUI';
import { getPageData } from '@/utils/data';

export default async function DynamicListPage({ slugArr, basePath, columns, pageSize = 10, searchParams }) {
  // 先 await searchParams
  const resolvedSearchParams = await searchParams;
  // 解析当前页码
  const currentPage = Number(resolvedSearchParams?.page) || 1;

  let items = [];
  let total = 0;
  let error = null;

  try {
    const result = await getPageData({
      slug_list: slugArr,
      page: currentPage,
      page_size: pageSize,
      downloadFiles: true
    });
    items = result.data;
    total = result.total;
    error = result.error;
  } catch (e) {
    items = [];
    total = 0;
    error = e;
  }

  return (
    <DynamicListPageUI
      initialItems={items}
      slugArr={slugArr}
      basePath={basePath}
      columns={columns}
      pageSize={pageSize}
      totalItems={total}
    />
  );
} 