import { useState, useEffect } from 'react'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import toast from 'react-hot-toast'; import { X, Save, Sparkles, ExternalLink, Eye } from 'lucide-react'; import { api } from '../../lib/api-client'; import { Button, Badge, Input, Label, Textarea, Skeleton } from '../../components/ui/primitives'; import { Tabs, TabsList, TabsTrigger, TabsContent } from '../../components/ui/tabs'; import type { ProductDetail, ProductOffer } from './types'; interface Props { productId: number; onClose: () => void; onSaved?: () => void; } export function ProductDetailDrawer({ productId, onClose, onSaved }: Props) { const qc = useQueryClient(); const [form, setForm] = useState>({}); const [previewOpen, setPreviewOpen] = useState(false); const { data, isLoading } = useQuery({ queryKey: ['product', productId], queryFn: () => api.get<{ product: ProductDetail; offers: ProductOffer[] }>(`/products/${productId}`), }); useEffect(() => { if (data?.product) { setForm({ name: data.product.name, display_name: data.product.display_name, brand: data.product.brand, model_name: data.product.model_name, is_sneaker: data.product.is_sneaker, gender: data.product.gender, description: data.product.description, ai_description: data.product.ai_description, }); } }, [data?.product]); const saveMut = useMutation({ mutationFn: (body: Partial) => api.put<{ product: ProductDetail }>(`/products/${productId}`, body), onSuccess: () => { toast.success('Product opgeslagen'); qc.invalidateQueries({ queryKey: ['product', productId] }); onSaved?.(); }, onError: (e: Error) => toast.error(e.message), }); const regenMut = useMutation({ mutationFn: () => api.post<{ jobId: number }>('/products/bulk', { ids: [productId], action: 'regen-ai-desc' }), onSuccess: (res) => toast.success(`AI-desc regeneratie job #${res.jobId}`), onError: (e: Error) => toast.error(e.message), }); return (
e.stopPropagation()} >
{data?.product?.image_url && ( )}

{data?.product?.name ?? 'Laden...'}

{data?.product?.brand ?? ''} {data?.product?.model_name ? `· ${data.product.model_name}` : ''}

{isLoading ? (
) : data?.product ? (
Info Beschrijving Aanbieders ({data.offers.length})
setForm({ ...form, name: e.target.value })} />
setForm({ ...form, display_name: e.target.value })} />
setForm({ ...form, brand: e.target.value })} />
setForm({ ...form, model_name: e.target.value })} />
ID {data.product.id} · slug {data.product.slug}