'use client'; import { Locale } from '@/lib/i18n'; import { getSEOData, SEOData } from '@/lib/seo'; import { useEffect, useState } from 'react'; interface TDKConfigManagerProps { locale: Locale; page: string; onSave?: (data: SEOData) => void; className?: string; } export default function TDKConfigManager({ locale, page, onSave, className = '', }: TDKConfigManagerProps) { const [seoData, setSeoData] = useState({ title: '', description: '', keywords: [], }); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [newKeyword, setNewKeyword] = useState(''); useEffect(() => { const loadSEOData = async () => { try { setLoading(true); const data = await getSEOData(locale, page); setSeoData(data); } catch (error) { console.error('Failed to load SEO data:', error); } finally { setLoading(false); } }; loadSEOData(); }, [locale, page]); const handleSave = async () => { if (onSave) { setSaving(true); try { await onSave(seoData); alert( locale === 'zh-CN' ? '保存成功!' : locale === 'zh-TW' ? '儲存成功!' : 'Saved successfully!', ); } catch (error) { alert( locale === 'zh-CN' ? '保存失败!' : locale === 'zh-TW' ? '儲存失敗!' : 'Save failed!', ); } finally { setSaving(false); } } }; const addKeyword = () => { if (newKeyword.trim() && !seoData.keywords.includes(newKeyword.trim())) { setSeoData({ ...seoData, keywords: [...seoData.keywords, newKeyword.trim()], }); setNewKeyword(''); } }; const removeKeyword = (index: number) => { setSeoData({ ...seoData, keywords: seoData.keywords.filter((_, i) => i !== index), }); }; if (loading) { return (
); } return (

{locale === 'zh-CN' ? 'TDK配置管理' : locale === 'zh-TW' ? 'TDK配置管理' : 'TDK Configuration'}

{/* Title */}
setSeoData({ ...seoData, title: e.target.value })} className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder={ locale === 'zh-CN' ? '输入页面标题' : locale === 'zh-TW' ? '輸入頁面標題' : 'Enter page title' } />
{seoData.title.length}/60{' '} {locale === 'zh-CN' ? '字符' : locale === 'zh-TW' ? '字元' : 'characters'}
{/* Description */}