'use client' import { useState, useTransition } from 'react' import { cn } from '@/lib/utils' import { updateAutoPrAction } from '@/actions/products' import { toast } from 'sonner' interface AutoPrToggleProps { productId: string initialValue: boolean } export function AutoPrToggle({ productId, initialValue }: AutoPrToggleProps) { const [enabled, setEnabled] = useState(initialValue) const [isPending, startTransition] = useTransition() function handleToggle() { const newValue = !enabled setEnabled(newValue) startTransition(async () => { const result = await updateAutoPrAction(productId, newValue) if (result.error) { setEnabled(!newValue) toast.error(typeof result.error === 'string' ? result.error : 'Opslaan mislukt') } }) } return (