/** * BoostMedia AI Content Generator Admin - Generated Post Preview * * @package BoostMedia_AI * @license GPL-2.0-or-later */ import { Eye, FileText, Tag, Settings } from 'lucide-react' import type { GeneratedPost } from '../../types' import { Card, Badge } from '../common' import { t, getDateLocale } from '../../lib/i18n' interface GeneratedPostPreviewProps { post: GeneratedPost isExpanded?: boolean onToggleExpand?: () => void hideHeader?: boolean } export function GeneratedPostPreview({ post, isExpanded = false, onToggleExpand, hideHeader = false, }: GeneratedPostPreviewProps) { let content: { title?: string content?: string excerpt?: string meta_fields?: Record seo?: { meta_title?: string; meta_description?: string; focus_keyword?: string } } = {} const raw = post.generated_content ?? post.content if (typeof raw === 'object' && raw !== null) { content = raw as typeof content } else if (typeof raw === 'string') { try { content = JSON.parse(raw || '{}') } catch { content = { content: raw } } } if (!content.title && post.title) { content.title = post.title } if (!content.excerpt && post.excerpt) { content.excerpt = post.excerpt } const statusBadgeVariant: Record = { draft: 'info', pending: 'warning', scheduled: 'warning', published: 'success', failed: 'error', } const statusLabels: Record = { draft: t('Draft'), pending: t('Pending'), scheduled: t('Scheduled'), published: t('Published'), failed: t('Failed'), } const expandedContent = ( <> {/* Excerpt */} {content.excerpt && (

{t('Excerpt')}

{content.excerpt}

)} {/* Content Preview */}

{t('Content')}

${t('No content')}

`, }} />
{/* Meta Fields */} {content.meta_fields && Object.keys(content.meta_fields).length > 0 && (

{t('Custom fields')}

{Object.entries(content.meta_fields).map(([key, value]) => (

{key}

{typeof value === 'string' ? value : JSON.stringify(value)}

))}
)} {/* SEO */} {content.seo && (

SEO

{content.seo.focus_keyword && (

{t('Focus Keyword')}

{content.seo.focus_keyword}

)} {content.seo.meta_title && (

{t('SEO Title')}

{content.seo.meta_title}

)} {content.seo.meta_description && (

{t('SEO Description')}

{content.seo.meta_description}

)}
)} ) if (hideHeader) { return isExpanded ?
{expandedContent}
: null } return ( {/* Header */}

{content.title || t('No title')}

{post.post_type} • {t('created')}{' '} {new Date(post.created_at).toLocaleDateString(getDateLocale())}

{statusLabels[post.status] || post.status}
{/* Expanded Content */} {isExpanded && (
{expandedContent}
)}
) }