import { useState } from "react"; import type { AboutContent, AboutSection } from "@/lib/content-types"; import type { Locale } from "@/lib/i18n/messages"; const inputClass = "w-full rounded-lg border border-[#303030] bg-[#141414] px-3 py-2 text-sm text-white outline-none transition focus:border-[#A92626] focus-visible:ring-2 focus-visible:ring-[#A92626]/40"; const labelClass = "flex flex-col gap-1.5 text-xs text-[#999]"; const buttonClass = "min-h-11 rounded-lg border border-[#303030] px-3 text-sm transition hover:border-[#A92626] hover:text-[#D47272] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#A92626]"; const primaryButtonClass = "min-h-11 rounded-lg bg-[#8F0808] px-4 text-sm font-medium transition hover:bg-[#a30a0a] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#D47272]"; 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) => ( ))}