/** * BoostMedia AI Content Generator Admin - Post Editor Component * * @package BoostMedia_AI * @license GPL-2.0-or-later */ import { useState, useEffect } from 'react' import { X, Save } from 'lucide-react' import type { GeneratedPost } from '../../types' import { Button, Card } from '../common' import { t } from '../../lib/i18n' interface PostEditorProps { post: GeneratedPost onSave: (updatedPost: GeneratedPost) => void onClose: () => void } interface EditableContent { title: string content: string excerpt: string meta_fields: Record seo: { meta_title: string meta_description: string focus_keyword: string } } export function PostEditor({ post, onSave, onClose }: PostEditorProps) { const [content, setContent] = useState({ title: '', content: '', excerpt: '', meta_fields: {}, seo: { meta_title: '', meta_description: '', focus_keyword: '', }, }) const [isSaving, setIsSaving] = useState(false) useEffect(() => { let parsed: Record = {} const raw = post.generated_content ?? post.content if (typeof raw === 'object' && raw !== null) { parsed = raw as Record } else if (typeof raw === 'string') { try { parsed = JSON.parse(raw || '{}') } catch { parsed = { content: raw } } } const seo = parsed.seo as Record | undefined setContent({ title: (parsed.title as string) || (post.title as string) || '', content: (parsed.content as string) || '', excerpt: (parsed.excerpt as string) || (post.excerpt as string) || '', meta_fields: (parsed.meta_fields as Record) || {}, seo: { meta_title: seo?.meta_title || '', meta_description: seo?.meta_description || '', focus_keyword: seo?.focus_keyword || '', }, }) }, [post]) const handleSave = async () => { setIsSaving(true) try { const updatedPost: GeneratedPost = { ...post, generated_content: JSON.stringify(content), } onSave(updatedPost) } finally { setIsSaving(false) } } const updateMetaField = (key: string, value: string) => { setContent((prev) => ({ ...prev, meta_fields: { ...prev.meta_fields, [key]: value, }, })) } return (
{/* Header */}

{t('Edit Post')}

{/* Content */}
{/* Title */}
setContent((prev) => ({ ...prev, title: e.target.value })) } className=" w-full p-3 rounded-bc border border-bc-gray-300 bg-white text-bc-gray-800 focus:ring-2 focus:ring-bc-primary focus:border-bc-primary transition-all duration-200 " />
{/* Excerpt */}