"use client"; import { useUiText } from "@suphark/ui/components/shared/ui-text"; import { DropdownMenuGroup, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, } from "@suphark/ui/components/ui/dropdown-menu"; import type { ReactNode } from "react"; export interface LanguageOption { /** รหัสภาษา เช่น "th", "en" */ value: string; /** ชื่อภาษา — ควรเขียนเป็นภาษานั้นเอง ("ไทย" / "English") ผู้ใช้จะหาเจอแม้อ่านภาษาปัจจุบันไม่ออก */ label: ReactNode; /** บรรทัดรองในเมนู เช่นชื่อภาษาในภาษาปัจจุบัน */ hint?: ReactNode; /** ธงหน้าชื่อ (emoji หรือ element) */ flag?: ReactNode; } /** * กลุ่มตัวเลือกภาษาสำหรับใส่ใน DropdownMenu (เช่นเมนูผู้ใช้) — คู่กับ `ThemeMenuItems` * แพ็กเกจไม่รู้จัก i18n ของแอป: แอปส่ง `locales` + `value` + `onValueChange` (จะเขียน cookie/เรียก * server action หรือ `router.refresh()` ก็ทำฝั่งแอป) — ยกจาก Pi Config/Pi PDF ที่เขียนเหมือนกัน */ export function LanguageMenuItems({ value, onValueChange, locales, label, disabled = false, }: { value: string; onValueChange: (value: string) => void; locales: ReadonlyArray; /** หัวกลุ่ม (ค่าเริ่มต้น `UiText.language.label` — "ภาษา") */ label?: ReactNode; /** ปิดระหว่างเปลี่ยนภาษา (pending ของ transition) */ disabled?: boolean; }) { const text = useUiText(); return ( {label ?? text.language?.label ?? "ภาษา"} onValueChange(String(next))}> {locales.map((locale) => ( {locale.flag && ( )} {locale.label} {locale.hint && ( {locale.hint} )} ))} ); }