import React, { useState, useEffect, useCallback } from 'react'; import { AuthProvider, AuthGuard, useAuth } from './AdminAuth'; import AdminLayout from './AdminLayout'; import { renderTemplate, SAMPLE_PRICE_ALERT, SAMPLE_WATCHLIST_DIGEST } from '../../lib/email-templates'; type BlockType = 'header' | 'product' | 'text' | 'button' | 'divider' | 'price_comparison'; interface Block { id: string; type: BlockType; data: Record; } const BLOCK_TYPES: { type: BlockType; label: string; icon: string }[] = [ { type: 'header', label: 'Header', icon: '๐Ÿท๏ธ' }, { type: 'product', label: 'Product', icon: '๐Ÿ‘Ÿ' }, { type: 'text', label: 'Tekst', icon: '๐Ÿ“' }, { type: 'button', label: 'Button', icon: '๐Ÿ”˜' }, { type: 'divider', label: 'Divider', icon: 'โž–' }, { type: 'price_comparison', label: 'Prijsvergelijk', icon: '๐Ÿ’ฐ' }, ]; function uid() { return Math.random().toString(36).slice(2, 9); } function renderBlockToHtml(block: Block): string { switch (block.type) { case 'header': return `
${block.data.logo ? `` : ''}

${block.data.title || 'SneakerPicks'}

`; case 'product': return `
${block.data.name || 'Product'}
${block.data.price ? `โ‚ฌ${block.data.price}` : ''}
${block.data.url ? `Bekijk Deal โ†’` : ''}
`; case 'text': return `
${block.data.content || ''}
`; case 'button': return `
${block.data.label || 'Click here'}
`; case 'divider': return `
`; case 'price_comparison': const shops = block.data.shops || []; return `
${block.data.name || 'Product'}
${shops.map((s: any) => `
${s.shop} โ‚ฌ${s.price}
`).join('')}
`; default: return ''; } } function BlockEditor({ block, onChange, onRemove, onMoveUp, onMoveDown }: { block: Block; onChange: (b: Block) => void; onRemove: () => void; onMoveUp: () => void; onMoveDown: () => void; }) { const update = (key: string, val: any) => onChange({ ...block, data: { ...block.data, [key]: val } }); return (
{block.type}
{block.type === 'header' && (
update('title', e.target.value)} placeholder="Titel" className="w-full bg-[#0A0A0A] border border-[#333] rounded px-3 py-2 text-sm text-[#F5F5F5]" /> update('logo', e.target.value)} placeholder="Logo URL" className="w-full bg-[#0A0A0A] border border-[#333] rounded px-3 py-2 text-sm text-[#F5F5F5]" />
)} {block.type === 'product' && (
update('name', e.target.value)} placeholder="Product naam" className="w-full bg-[#0A0A0A] border border-[#333] rounded px-3 py-2 text-sm text-[#F5F5F5]" />
update('price', e.target.value)} placeholder="Prijs" className="bg-[#0A0A0A] border border-[#333] rounded px-3 py-2 text-sm text-[#F5F5F5]" /> update('url', e.target.value)} placeholder="Link" className="bg-[#0A0A0A] border border-[#333] rounded px-3 py-2 text-sm text-[#F5F5F5]" />
update('image', e.target.value)} placeholder="Afbeelding URL" className="w-full bg-[#0A0A0A] border border-[#333] rounded px-3 py-2 text-sm text-[#F5F5F5]" /> onChange({ ...block, data: { ...block.data, name: p.name, image: p.image_url, product_id: p.id } })} />
)} {block.type === 'text' && (