import { Suspense } from 'react'
import { notFound } from 'next/navigation'
import { OrderDetailContent } from './OrderDetailContent'
import { Skeleton } from '@/components/ui/Skeleton'
import { Card, CardContent } from '@/components/ui/Card'

interface OrderDetailPageProps {
  params: Promise<{ id: string }>
}

export default async function OrderDetailPage({ params }: OrderDetailPageProps) {
  const { id } = await params

  return (
    <div className="space-y-6">
      <Suspense fallback={<OrderDetailSkeleton />}>
        <OrderDetailContent orderId={id} />
      </Suspense>
    </div>
  )
}

function OrderDetailSkeleton() {
  return (
    <div className="space-y-6">
      <div className="flex items-center justify-between">
        <Skeleton className="h-8 w-48" />
        <Skeleton className="h-10 w-32" />
      </div>
      <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
        {Array.from({ length: 4 }).map((_, i) => (
          <Card key={i}><CardContent className="p-6"><Skeleton className="h-8 w-full" /><Skeleton className="h-4 w-1/2 mt-2" /></CardContent></Card>
        ))}
      </div>
      <div className="grid gap-6 lg:grid-cols-2">
        <Card><CardContent className="p-6"><Skeleton className="h-6 w-1/3" /><SkeletonText lines={5} /></CardContent></Card>
        <Card><CardContent className="p-6"><Skeleton className="h-6 w-1/3" /><SkeletonText lines={8} /></CardContent></Card>
      </div>
    </div>
  )
}

function SkeletonText({ lines = 3 }: { lines?: number }) {
  return (
    <div className="space-y-3 mt-4">
      {Array.from({ length: lines }).map((_, i) => (
        <Skeleton key={i} className="h-4 w-full" />
      ))}
    </div>
  )
}