'use client'; /** * NOVA CMS - CONTENT PREVIEW * =========================== * * Vista previa de contenido del headless CMS. * Muestra el contenido de una entrada de forma legible. */ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { FileText, Calendar, Hash, ToggleRight, Image as ImageIcon, ExternalLink } from 'lucide-react'; interface Field { id: string; label: string; apiIdentifier: string; type: 'TEXT' | 'RICH_TEXT' | 'NUMBER' | 'BOOLEAN' | 'DATE' | 'MEDIA'; isRequired: boolean; } interface ContentType { id: string; name: string; apiIdentifier: string; description?: string; fields: Field[]; } interface ContentPreviewProps { contentType: ContentType; data: Record; createdAt?: Date; updatedAt?: Date; } export function ContentPreview({ contentType, data, createdAt, updatedAt }: ContentPreviewProps) { const getFieldIcon = (type: Field['type']) => { switch (type) { case 'TEXT': case 'RICH_TEXT': return ; case 'NUMBER': return ; case 'BOOLEAN': return ; case 'DATE': return ; case 'MEDIA': return ; default: return ; } }; const formatValue = (value: any, field: Field) => { if (value === null || value === undefined || value === '') { return Sin valor; } switch (field.type) { case 'TEXT': return {String(value)}; case 'RICH_TEXT': return (
{String(value)}
); case 'NUMBER': return ( {Number(value).toLocaleString()} ); case 'BOOLEAN': return ( {value ? '✅ Sí' : '❌ No'} ); case 'DATE': return ( {new Date(value).toLocaleDateString('es-ES', { year: 'numeric', month: 'long', day: 'numeric' })} ); case 'MEDIA': const isUrl = typeof value === 'string' && value.startsWith('http'); return isUrl ? (
Ver archivo {value.match(/\.(jpg|jpeg|png|gif|webp)$/i) && ( Preview { e.currentTarget.style.display = 'none'; }} /> )}
) : ( {String(value)} ); default: return {String(value)}; } }; return (
{/* Header */}
{contentType.name} {contentType.description && (

{contentType.description}

)}
{contentType.apiIdentifier}
{(createdAt || updatedAt) && (
{createdAt && ( Creado: {new Date(createdAt).toLocaleDateString()} )} {updatedAt && ( Actualizado: {new Date(updatedAt).toLocaleDateString()} )}
)}
{/* Fields */}
{contentType.fields.map((field) => (
{getFieldIcon(field.type)}

{field.label}

{field.isRequired && ( Requerido )} {field.type}
{formatValue(data[field.apiIdentifier], field)}
))}
{/* Debug Info (solo en desarrollo) */} {process.env.NODE_ENV === 'development' && ( Debug - Datos Raw
              {JSON.stringify(data, null, 2)}
            
)}
); }