106 lines
3.7 KiB
TypeScript
106 lines
3.7 KiB
TypeScript
import type { Cinema } from "@/lib/cinemas";
|
|
import { DEFAULT_LOCALE, MESSAGES, type FacilityKey } from "@/lib/i18n/messages";
|
|
|
|
/**
|
|
* แก้ข้อความสิ่งอำนวยความสะดวก "ของโรงนี้" (ผูกกับโรง ไม่ใช่ส่วนกลาง)
|
|
*
|
|
* - ชื่อหัวข้อ: ช่องเดียว (ใช้ทั้ง TH/EN) — ว่าง = ใช้ค่าเริ่มต้นจาก messages.ts
|
|
* - คำอธิบาย TH/EN: แสดงเฉพาะโรงที่ต้องการ (hasDescriptions) เช่น เฮ้าส์ สามย่าน
|
|
* ที่มีข้อมูลครบแล้ว โรงอื่นไม่ต้องกรอก
|
|
*/
|
|
|
|
export type FacilityDetail = {
|
|
label?: string;
|
|
sub_th?: string;
|
|
sub_en?: string;
|
|
};
|
|
|
|
const ADMIN_MESSAGES = MESSAGES[DEFAULT_LOCALE];
|
|
|
|
type Props = {
|
|
facilities: FacilityKey[];
|
|
details: NonNullable<Cinema["facility_details"]>;
|
|
hasDescriptions: boolean;
|
|
onChange: (next: NonNullable<Cinema["facility_details"]>) => void;
|
|
inputClass: string;
|
|
labelClass: string;
|
|
};
|
|
|
|
export function CinemaFacilitiesEditor({
|
|
facilities,
|
|
details,
|
|
hasDescriptions,
|
|
onChange,
|
|
inputClass,
|
|
labelClass,
|
|
}: Props) {
|
|
if (facilities.length === 0) {
|
|
return (
|
|
<span className="text-[11px] text-[#777]">
|
|
เลือกหัวข้อด้านบนก่อน แล้วค่อยใส่ชื่อที่ต้องการ
|
|
</span>
|
|
);
|
|
}
|
|
|
|
function update(key: FacilityKey, patch: FacilityDetail) {
|
|
const current = details[key] ?? {};
|
|
const next: FacilityDetail = { ...current, ...patch };
|
|
const cleaned: FacilityDetail = {};
|
|
if (next.label?.trim()) cleaned.label = next.label;
|
|
if (next.sub_th?.trim()) cleaned.sub_th = next.sub_th;
|
|
if (next.sub_en?.trim()) cleaned.sub_en = next.sub_en;
|
|
onChange({ ...details, [key]: cleaned });
|
|
}
|
|
|
|
return (
|
|
<div className="flex flex-col gap-2">
|
|
{facilities.map((key) => {
|
|
const fallback = ADMIN_MESSAGES.facilities[key];
|
|
const detail = details[key] ?? {};
|
|
return (
|
|
<div
|
|
key={key}
|
|
className="grid gap-2 rounded-lg border border-[#242424] p-2 sm:grid-cols-2"
|
|
>
|
|
<label className={labelClass}>
|
|
ชื่อหัวข้อ
|
|
<input
|
|
className={inputClass}
|
|
value={detail.label ?? ""}
|
|
placeholder={fallback.title}
|
|
onChange={(event) => update(key, { label: event.target.value })}
|
|
/>
|
|
</label>
|
|
{hasDescriptions ? (
|
|
<>
|
|
<label className={labelClass}>
|
|
คำอธิบาย (TH)
|
|
<input
|
|
className={inputClass}
|
|
value={detail.sub_th ?? ""}
|
|
placeholder={fallback.sub}
|
|
onChange={(event) =>
|
|
update(key, { sub_th: event.target.value })
|
|
}
|
|
/>
|
|
</label>
|
|
<label className={labelClass}>
|
|
คำอธิบาย (EN)
|
|
<input
|
|
className={inputClass}
|
|
value={detail.sub_en ?? ""}
|
|
placeholder={MESSAGES.en.facilities[key].sub}
|
|
onChange={(event) =>
|
|
update(key, { sub_en: event.target.value })
|
|
}
|
|
/>
|
|
</label>
|
|
</>
|
|
) : null}
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|