import React from 'react'; import { EmailBlock } from './types'; import { __ } from '@/lib/i18n'; import { parseMarkdownBasics } from '@/lib/markdown-utils'; interface BlockRendererProps { block: EmailBlock; isEditing: boolean; onEdit: () => void; onDelete: () => void; onMoveUp: () => void; onMoveDown: () => void; isFirst: boolean; isLast: boolean; } export function BlockRenderer({ block, isEditing, onEdit, onDelete, onMoveUp, onMoveDown, isFirst, isLast }: BlockRendererProps) { // Prevent navigation in builder const handleClick = (e: React.MouseEvent) => { const target = e.target as HTMLElement; if ( target.tagName === 'A' || target.tagName === 'BUTTON' || target.closest('a') || target.closest('button') || target.classList.contains('button') || target.classList.contains('button-outline') || target.closest('.button') || target.closest('.button-outline') ) { e.preventDefault(); e.stopPropagation(); } }; const renderBlockContent = () => { switch (block.type) { case 'card': const cardStyles: { [key: string]: React.CSSProperties } = { default: { background: '#ffffff', borderRadius: '8px', padding: '32px 40px', marginBottom: '24px' }, success: { background: '#e8f5e9', border: '1px solid #4caf50', borderRadius: '8px', padding: '32px 40px', marginBottom: '24px' }, info: { background: '#f0f7ff', border: '1px solid #0071e3', borderRadius: '8px', padding: '32px 40px', marginBottom: '24px' }, warning: { background: '#fff8e1', border: '1px solid #ff9800', borderRadius: '8px', padding: '32px 40px', marginBottom: '24px' }, hero: { background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', color: '#fff', borderRadius: '8px', padding: '32px 40px', marginBottom: '24px' } }; // Convert markdown to HTML for visual rendering const htmlContent = parseMarkdownBasics(block.content); return (
); case 'button': { const buttonStyle: React.CSSProperties = block.style === 'solid' ? { display: 'inline-block', background: '#7f54b3', color: '#fff', padding: '14px 28px', borderRadius: '6px', textDecoration: 'none', fontWeight: 600, } : { display: 'inline-block', background: 'transparent', color: '#7f54b3', padding: '12px 26px', border: '2px solid #7f54b3', borderRadius: '6px', textDecoration: 'none', fontWeight: 600, }; const containerStyle: React.CSSProperties = { textAlign: block.align || 'center', }; if (block.widthMode === 'full') { buttonStyle.display = 'block'; buttonStyle.width = '100%'; buttonStyle.textAlign = 'center'; } else if (block.widthMode === 'custom' && block.customMaxWidth) { buttonStyle.maxWidth = `${block.customMaxWidth}px`; buttonStyle.width = '100%'; } return (
{block.text}
); } case 'image': { const containerStyle: React.CSSProperties = { textAlign: block.align, marginBottom: 24, }; const imgStyle: React.CSSProperties = { display: 'inline-block', }; if (block.widthMode === 'full') { imgStyle.display = 'block'; imgStyle.width = '100%'; imgStyle.height = 'auto'; } else if (block.widthMode === 'custom' && block.customMaxWidth) { imgStyle.maxWidth = `${block.customMaxWidth}px`; imgStyle.width = '100%'; imgStyle.height = 'auto'; } return (
{block.alt
); } case 'divider': return
; case 'spacer': return
; default: return null; } }; return (
{/* Block Content */}
{renderBlockContent()}
{/* Hover Controls */}
{!isFirst && ( )} {!isLast && ( )} {/* Only show edit button for card, button, and image blocks */} {(block.type === 'card' || block.type === 'button' || block.type === 'image') && ( )}
); }