import { getCategories } from '@/lib/actions/products'
import { CategoryList } from '@/components/admin/category-list'
import { CategoryDialog } from '@/components/admin/category-dialog'
import { LayoutGrid, Plus } from 'lucide-react'
import { Suspense } from 'react'

export default async function AdminCategoriesPage() {
  return (
    <div className="flex-1 space-y-8 p-8 pt-6">
      <div className="flex items-center justify-between space-y-2">
        <div>
          <h2 className="text-3xl font-bold tracking-tight text-gradient flex items-center gap-3">
            <LayoutGrid className="w-8 h-8 text-primary" />
            Kategorien
          </h2>
          <p className="text-muted-foreground">
            Verwalten Sie die Struktur Ihres Webshops.
          </p>
        </div>
        <div className="flex items-center space-x-2">
          <Suspense fallback={<div className="h-10 w-32 animate-pulse bg-white/5 rounded-md" />}>
            <CreateCategoryAction />
          </Suspense>
        </div>
      </div>
      <Suspense fallback={<div className="h-40 w-full animate-pulse bg-white/5 rounded-xl" />}>
        <CategoryDataWrapper />
      </Suspense>
    </div>
  )
}

async function CategoryDataWrapper() {
  const categories = await getCategories()
  return <CategoryList initialCategories={categories} />
}

async function CreateCategoryAction() {
  return (
    <CategoryDialog />
  )
}
