import { useState } from "react"; import { inputClass, labelClass, primaryButtonClass, secondaryButtonClass, } from "@/components/admin/form-styles"; import type { AboutContent, AboutSection } from "@/lib/content-types"; import type { Locale } from "@/lib/i18n/messages"; const LOCALE_TABS: Array<{ code: Locale; label: string }> = [ { code: "th", label: "ไทย" }, { code: "en", label: "English" }, ]; type AboutEditorProps = { value: Record; defaults: Record; onChange: (next: Record) => void; onSave: () => void; saving: boolean; }; /** * ตัวแก้ไขหน้า "เกี่ยวกับเรา" — แยกแท็บตามภาษา มีตัวอย่างหน้าเว็บให้ดูสด ๆ * ฟิลด์ที่เว้นว่างจะถูกเซิร์ฟเวอร์คืนเป็นข้อความตั้งต้นให้อัตโนมัติ (sanitizeAbout) */ export function AboutEditor({ value, defaults, onChange, onSave, saving, }: AboutEditorProps) { const [locale, setLocale] = useState("th"); const current = value[locale]; function patch(next: Partial) { onChange({ ...value, [locale]: { ...current, ...next } }); } function patchSection(index: number, next: Partial) { patch({ sections: current.sections.map((section, i) => i === index ? { ...section, ...next } : section, ), }); } function moveSection(index: number, direction: -1 | 1) { const target = index + direction; if (target < 0 || target >= current.sections.length) return; const sections = [...current.sections]; const [moved] = sections.splice(index, 1); sections.splice(target, 0, moved); patch({ sections }); } function addSection() { patch({ sections: [ ...current.sections, { heading: `หัวข้อที่ ${current.sections.length + 1}`, body: "" }, ], }); } function removeSection(index: number) { patch({ sections: current.sections.filter((_, i) => i !== index) }); } function restoreDefaults() { onChange({ ...value, [locale]: defaults[locale] }); } const titleMissing = current.title.trim() === ""; const leadTooLong = current.lead.length > 400; return (
{LOCALE_TABS.map((tab) => ( ))}