import { notFound } from 'next/navigation';
import { getPageData } from "@/utils/data";
import { getLocalPageData } from "@/data/presentation";
import Presentation from "@/components/presentation/Presentation";

const baseSlug = 'presentation';

const LoadingSpinner = () => (
  <div className="flex justify-center items-center p-8">
    <div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-500"></div>
  </div>
);

export default async function Page({ params, searchParams }) {
  const resolvedParams = await params;
  const slug = resolvedParams.slug || [];
  const slugArr = [baseSlug, ...(Array.isArray(slug) ? slug : [slug])];


  const { data, error } = await getPageData({
    slug_list: slugArr,
    downloadFiles: true,
  });

  if (error) {
    notFound();
  }

  if (data) {
    // 优先从本地markdown文件获取数据
    const localData = await getLocalPageData(slugArr);
    
    if (localData.data) {
      // 如果本地文件存在，直接使用本地数据
      return <Presentation data={localData.data} />;
    }

    // 如果本地文件不存在，使用API数据
    return <Presentation data={data} />;
  } else {
    notFound();
  }
} 
