'use client' import Link from 'next/link' import { useRouter } from 'next/navigation' import { useState, useTransition } from 'react' import { Pencil } from 'lucide-react' import { toast } from 'sonner' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { CodeBadge } from '@/components/shared/code-badge' import { DemoTooltip } from '@/components/shared/demo-tooltip' import { restoreProductAction } from '@/actions/products' import { setActiveProductAction } from '@/actions/active-product' import { ProductDialog, type ProductDialogProduct } from '@/components/dialogs/product-dialog' import { debugProps } from '@/lib/debug' interface Product { id: string name: string code: string | null description: string | null repo_url: string | null definition_of_done: string | null auto_pr: boolean } interface ProductListProps { products: Product[] isDemo: boolean showArchived?: boolean activeProductId: string | null } export function ProductList({ products, isDemo, showArchived = false, activeProductId }: ProductListProps) { const router = useRouter() const [, startTransition] = useTransition() const [editingProduct, setEditingProduct] = useState(null) function handleRestore(id: string) { startTransition(async () => { const result = await restoreProductAction(id) if ('error' in result) toast.error(result.error ?? 'Herstellen mislukt') else { toast.success('Product hersteld'); router.refresh() } }) } function handleActivate(id: string) { startTransition(async () => { const result = await setActiveProductAction(id) if (result?.error) toast.error(typeof result.error === 'string' ? result.error : 'Activeren mislukt') else router.push(`/products/${id}`) }) } if (products.length === 0) { return (

{showArchived ? 'Geen gearchiveerde producten.' : 'Je hebt nog geen producten aangemaakt.'}

) } return (
{products.map(product => (
!showArchived && router.push(`/products/${product.id}`)} className={`group bg-surface-container-low border border-border rounded-xl p-4 transition-colors ${ showArchived ? 'opacity-60' : 'cursor-pointer hover:border-primary' }`} data-debug-id="product-list__items" >
{product.code && }

{product.name}

{product.description && (

{product.description.slice(0, 80)}{product.description.length > 80 ? '…' : ''}

)}
{product.repo_url && ( e.stopPropagation()} className="text-xs text-muted-foreground hover:text-primary underline" > Repo )} {!showArchived && ( <> {product.id === activeProductId ? Actief : ( ) } )} {showArchived && ( )}
))} {editingProduct && ( { if (!v) setEditingProduct(null) }} product={editingProduct} isDemo={isDemo} /> )}
) }