import React, { useState } from 'react'; import { AuthProvider, AuthGuard, useAuth } from './AdminAuth'; import AdminLayout from './AdminLayout'; interface Section { id: string; type: string; title: string; config: Record; sort_order: number; enabled: boolean; } const SECTION_TYPES = [ { value: 'hero', label: 'Hero Banner' }, { value: 'featured_products', label: 'Featured Products' }, { value: 'collection', label: 'Collection' }, { value: 'brand_grid', label: 'Brand Grid' }, { value: 'category_grid', label: 'Category Grid' }, { value: 'deals', label: 'Latest Deals' }, { value: 'custom_html', label: 'Custom HTML' }, ]; function HomepageEditorContent() { const { token } = useAuth(); const [sections, setSections] = useState([ { id: '1', type: 'hero', title: 'Hero Banner', config: { title: 'Beste sneaker deals van Nederland', cta_text: 'Bekijk deals', cta_url: '/deals' }, sort_order: 0, enabled: true }, { id: '2', type: 'featured_products', title: 'Featured Products', config: { product_ids: [], layout: 'grid' }, sort_order: 1, enabled: true }, { id: '3', type: 'collection', title: 'Bestsellers', config: { collection_id: '', limit: 8, layout: 'carousel' }, sort_order: 2, enabled: true }, { id: '4', type: 'brand_grid', title: 'Trending Brands', config: { brand_ids: [] }, sort_order: 3, enabled: true }, ]); const [dragIdx, setDragIdx] = useState(null); const moveSection = (from: number, to: number) => { const next = [...sections]; const [item] = next.splice(from, 1); next.splice(to, 0, item); setSections(next.map((s, i) => ({ ...s, sort_order: i }))); }; const toggleEnabled = (id: string) => { setSections(prev => prev.map(s => s.id === id ? { ...s, enabled: !s.enabled } : s)); }; const removeSection = (id: string) => { setSections(prev => prev.filter(s => s.id !== id)); }; const addSection = () => { setSections(prev => [...prev, { id: crypto.randomUUID(), type: 'custom_html', title: 'New Section', config: {}, sort_order: prev.length, enabled: true, }]); }; const typeIcon = (type: string) => { const icons: Record = { hero: 'H', featured_products: 'F', collection: 'C', brand_grid: 'T', category_grid: 'G', deals: 'D', custom_html: 'X' }; return icons[type] || '📄'; }; return (

Drag to reorder sections. Changes are saved when you click Save.

{sections.map((section, idx) => (
setDragIdx(idx)} onDragOver={e => e.preventDefault()} onDrop={() => { if (dragIdx !== null && dragIdx !== idx) moveSection(dragIdx, idx); setDragIdx(null); }} className={`bg-[#141414] border rounded-xl p-4 transition-all cursor-move ${section.enabled ? 'border-[#333]' : 'border-[#222] opacity-50'} ${dragIdx === idx ? 'border-[#00FF6A] scale-[1.02]' : 'hover:border-[#444]'}`} >
≡ {typeIcon(section.type)}
{section.title}
{SECTION_TYPES.find(t => t.value === section.type)?.label}
))}
); } export default function HomepageEditorPage() { return ; }