import { useState, useEffect } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { useQuery, useMutation } from '@tanstack/react-query'; import toast from 'react-hot-toast'; import { ArrowLeft, Save, Plus, Trash2, Send, GripVertical } from 'lucide-react'; import { DndContext, closestCenter, PointerSensor, useSensor, useSensors, type DragEndEvent, } from '@dnd-kit/core'; import { arrayMove, SortableContext, useSortable, verticalListSortingStrategy, } from '@dnd-kit/sortable'; import { CSS } from '@dnd-kit/utilities'; import { api } from '../../lib/api-client'; import { AppShell, PageHeader, PageBody } from '../../layout/AppShell'; import { Button, Card, CardContent, Input, Label, Select, Textarea } from '../../components/ui/primitives'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '../../components/ui/dialog'; type BlockType = 'heading' | 'paragraph' | 'image' | 'button' | 'product-grid' | 'divider' | 'spacer' | 'html'; interface Block { id: string; type: BlockType; content: Record; } interface Template { id: number; name: string; type: string; blocks_json: Block[]; html_cache: string; } const BLOCK_DEFAULTS: Record> = { heading: { text: 'Nieuwe titel', level: 2 }, paragraph: { text: 'Schrijf hier je tekst...' }, image: { url: '', alt: '', width: 600 }, button: { text: 'Shop nu', url: '#', color: '#00FF6A' }, 'product-grid': { collection_slug: '', limit: 6 }, divider: {}, spacer: { height: 32 }, html: { html: '

Custom HTML...

' }, }; export function EmailEditor() { const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); const [template, setTemplate] = useState