import { CINEMAS } from "@/lib/cinemas"; import type { AboutContent, ArticleContent, ContentStore, FooterItem, LocaleEntry, TermEntry, } from "@/lib/content-types"; import type { Locale } from "@/lib/i18n/messages"; import { MESSAGES } from "@/lib/i18n/messages"; import type { Messages } from "@/lib/i18n/messages"; export const DEFAULT_LOCALES: LocaleEntry[] = [ { code: "th", label: "ไทย" }, { code: "en", label: "English" }, ]; function flatten( value: unknown, prefix: string, out: Record, ): void { if (typeof value === "string") { out[prefix] = value; return; } if (value && typeof value === "object") { for (const [key, child] of Object.entries( value as Record, )) { flatten(child, prefix ? `${prefix}.${key}` : key, out); } } } /** รวมข้อความทุกภาษาเป็นรายการคำศัพท์ (ใช้เป็นค่าเริ่มต้นของหน้า admin) */ export function seedTerms(): TermEntry[] { const perLocale: Record> = {}; for (const locale of Object.keys(MESSAGES) as Locale[]) { const flat: Record = {}; flatten(MESSAGES[locale], "", flat); perLocale[locale] = flat; } const keys = Object.keys(perLocale.th ?? perLocale.en ?? {}); return keys.map((key) => ({ key, values: Object.fromEntries( Object.entries(perLocale).map(([locale, flat]) => [ locale, flat[key] ?? "", ]), ), })); } export const DEFAULT_FOOTER: FooterItem[] = [ { id: "facebook", icon_name: "IconBrandFacebook", label: "Facebook", href: "https://www.facebook.com/", }, { id: "instagram", icon_name: "IconBrandInstagram", label: "Instagram", href: "https://www.instagram.com/", }, { id: "linkedin", icon_name: "IconBrandLinkedin", label: "LinkedIn", href: "https://www.linkedin.com/", }, { id: "youtube", icon_name: "IconBrandYoutube", label: "YouTube", href: "https://www.youtube.com/", }, { id: "telegram", icon_name: "IconBrandTelegram", label: "Telegram", href: "https://t.me/", }, ]; /** เนื้อหาหน้า "เกี่ยวกับเรา" เริ่มต้น — ดึงจากข้อความ i18n เพื่อไม่ต้องดูแลสองที่ */ export function seedAbout(): Record { return { th: toAboutContent(MESSAGES.th.about), en: toAboutContent(MESSAGES.en.about), }; } function toAboutContent(source: Messages["about"]): AboutContent { return { title: source.title, lead: source.lead, sections: source.sections.map((section) => ({ heading: section.heading, body: section.body, })), contactHeading: source.contactHeading, contactNote: source.contactNote, }; } export function seedContent(): ContentStore { return { cinemas: CINEMAS, site: { locales: DEFAULT_LOCALES, terms: seedTerms(), footer: DEFAULT_FOOTER, }, about: seedAbout(), forCinemas: seedForCinemas(), forFilmLovers: seedForFilmLovers(), }; } /** ค่าเริ่มต้นหน้า "สำหรับคนทำโรงหนัง" — ย่อหน้าตั้งต้นมาจาก messages (แก้ต่อได้ในหลังบ้าน) */ export function seedForCinemas(): Record { return seedArticle(MESSAGES.th.forCinemas, MESSAGES.en.forCinemas); } /** ค่าเริ่มต้นหน้า "สำหรับคนรักหนัง" */ export function seedForFilmLovers(): Record { return seedArticle(MESSAGES.th.forFilmLovers, MESSAGES.en.forFilmLovers); } type SeedArticle = { title: string; lead: string; paragraphs: string[]; contactHeading: string; contactNote: string; }; /** แปลงข้อความ i18n ของหน้าบทความ → บล็อกเริ่มต้น (ใช้ทั้งหน้าโรงหนังและคนรักหนัง) */ function seedArticle( th: SeedArticle, en: SeedArticle, ): Record { return { th: toArticleContent(th), en: toArticleContent(en) }; } function toArticleContent(source: SeedArticle): ArticleContent { return { title: source.title, lead: source.lead, blocks: source.paragraphs.map((text) => ({ type: "paragraph", text })), contactHeading: source.contactHeading, contactNote: source.contactNote, }; }