import { prisma } from "@/lib/prisma"
import PageRenderer from "@/components/page-builder/PageRenderer"

export default async function StorefrontHomePage() {
  const homePage = await prisma.storePage.findFirst({
    where: { OR: [{ slug: 'home' }, { type: 'HOME' }] }
  });

  if (homePage?.content && typeof homePage.content === 'object' && 'sections' in (homePage.content as any)) {
    return (
      <div className="w-full bg-slate-50 min-h-screen">
        <PageRenderer content={homePage.content} />
      </div>
    );
  }

  // Fallback to minimal layout if no page builder data is found
  return (
    <div className="w-full flex items-center justify-center min-h-[50vh]">
      <div className="text-center p-8 bg-slate-100 rounded-3xl">
        <h1 className="text-2xl font-bold text-slate-800 mb-2">به فروشگاه ما خوش آمدید</h1>
        <p className="text-slate-500 text-sm">قالب صفحه اصلی هنوز تنظیم نشده است. لطفاً از پنل مدیریت تنظیم کنید.</p>
      </div>
    </div>
  )
}

