/** * ข้อมูลโรงหนังอิสระ — แหล่งข้อมูลเดียวของทั้งหน้าแรกและหน้ารายละเอียด * ค่าที่ไม่รู้จริงปล่อยเป็นค่าว่าง/null แล้ว UI แสดงข้อความสำรองตามภาษา (lib/i18n) * ข้อความอังกฤษเป็นฟิลด์เสริม (*_en) ถ้าไม่กรอกจะ fallback เป็นไทย */ import type { Coordinates } from "@/lib/geo"; import type { FacilityKey, Locale, Messages } from "@/lib/i18n/messages"; import { FACILITY_KEYS } from "@/lib/i18n/messages"; export type TransportMode = { /** ใช้เลือกไอคอนและชื่อวิธีเดินทางจากข้อความแปล */ icon_name: "private_car" | "metro" | "bus"; /** รายละเอียดเส้นทาง — ภาษาตามข้อมูล (ยังไม่มีฟิลด์ _en) */ value: string; value_en?: string; }; export type ContactChannel = { label: string; value: string; href: string | null; }; export type Cinema = { slug: string; name: string; /** ชื่อภาษาไทย (ไม่กรอกก็ใช้ name อังกฤษ) */ name_th?: string; tags: string[]; location_label: string; location_label_en?: string; /** พิกัดโรงหนังสำหรับคำนวณระยะทาง — null คือยังไม่ทราบตำแหน่งจริง */ coordinates: Coordinates | null; description: string; description_en?: string; map_url: string | null; address_lines: string[]; address_lines_en?: string[]; transport: TransportMode[]; contacts: ContactChannel[]; payments: string[]; /** สิ่งอำนวยความสะดวกที่มีจริง — คีย์ตาม FACILITY_KEYS (ไม่กรอก = ไม่ระบุ) */ facilities?: FacilityKey[]; /** * ข้อความเฉพาะโรงนี้ต่อหัวข้อ (ทับค่าเริ่มต้นจาก messages.ts) * label = ชื่อหัวข้อ (ไม่แยกภาษา) · sub_th/sub_en = คำอธิบาย */ facility_details?: Partial< Record >; /** ซ่อนจากหน้าเว็บ (ยังเปิดดูได้ด้วย URL ตรง) — ไม่แสดงในรายการ/ค้นหา/โรงอื่นๆ */ hidden?: boolean; /** * ชั้นกรองที่ 1 — ประเภทโรงหนัง (ค่าเดียว): โรงภาพยนตร์ท้องถิ่น / โรงภาพยนตร์อินดี้ / กลุ่มคนฉายหนัง * ไม่กรอก = ยังไม่จัดประเภท (จะไม่ปรากฏเมื่อกรองด้วยประเภทใด ๆ) */ venue_type?: VenueType | null; /** หัวข้อการ์ดติดต่อ/จองตั๋ว เฉพาะโรงนี้ (ว่าง = ใช้ค่าเริ่มต้นจาก messages) */ contact_heading?: string; /** รูปโรงหนัง เรียงตามลำดับที่ใช้ในแกลเลอรี — ว่างได้ถ้ายังไม่มีรูป */ photos: string[]; }; export const CINEMA_CATEGORIES = [ "ทั้งหมด", "ยอดนิยม", "อาร์ตเฮาส์", "สารคดี", "หนังสั้น", "หนังคลาสสิก", "หนังนานาชาติ", "หนังนอกกระแส", "หนังในกระแส", "หนังฝรั่งเศส", "หนังไทย", ] as const; export type CinemaCategory = (typeof CINEMA_CATEGORIES)[number]; /** * ชั้นกรองที่ 1 — "ประเภทโรงหนัง" (เลือกได้ทีละอย่าง) * ข้อมูลเก็บที่ `cinema.venue_type` (คนละฟิลด์กับ tags เพราะโรงหนึ่งเป็นได้ประเภทเดียว) */ export const VENUE_TYPES = [ "โรงภาพยนตร์ท้องถิ่น", "โรงภาพยนตร์อินดี้", "กลุ่มคนฉายหนัง", ] as const; export type VenueType = (typeof VENUE_TYPES)[number]; export const DEFAULT_CATEGORY: CinemaCategory = "ทั้งหมด"; /** ลำดับ gradient ของการ์ด ใช้ร่วมกันทุกหน้าเพื่อให้สีคงที่ */ export const CARD_GRADIENTS = [ "from-[#3a2a22] via-[#2a2a3a] to-[#1b1b1b]", "from-[#2a2a3a] via-[#1f2a3a] to-[#1b1b1b]", "from-[#3a3a4a] via-[#2a2a2a] to-[#1b1b1b]", "from-[#4a3320] via-[#2a2a2a] to-[#1b1b1b]", ] as const; export const CINEMAS: Cinema[] = [ { slug: "house-cinema-samyan", name: "HOUSE CINEMA SAMYAN", name_th: "HOUSE สามย่าน", tags: ["หนังนอกกระแส", "อาร์ตเฮาส์"], location_label: "ชั้น 5 สามย่านมิตรทาวน์ กรุงเทพฯ", location_label_en: "5th floor, Samyan Mitrtown, Bangkok", coordinates: { latitude: 13.7343452, longitude: 100.5282654 }, description: "โรงภาพยนตร์สำหรับคนที่อยากค้นพบหนังหลากหลาย เน้นภาพยนตร์นอกกระแสและเรื่องที่ไม่ได้เข้าฉายในวงกว้าง พร้อมเรื่องราวและมุมมองที่แตกต่างสำหรับคนรักหนัง", description_en: "A cinema for people who want to discover a wide range of films — focused on independent titles and stories that never reach a wide release, with perspectives made for film lovers.", map_url: "https://maps.google.com/?q=House+Samyan", address_lines: [ "ชั้น 5 ศูนย์การค้าสามย่านมิตรทาวน์", "944/1 ถนนพระราม 4 แขวงวังใหม่ เขตปทุมวัน กรุงเทพฯ 10330", ], address_lines_en: [ "5th floor, Samyan Mitrtown", "944/1 Rama IV Road, Wang Mai, Pathum Wan, Bangkok 10330", ], transport: [ { icon_name: "private_car", value: "ที่จอดรถภายในศูนย์การค้าสามย่านมิตรทาวน์", value_en: "Parking inside Samyan Mitrtown", }, { icon_name: "metro", value: "MRT สถานีสามย่าน", value_en: "MRT Sam Yan station", }, { icon_name: "bus", value: "29, 34, 36, 40, 47, 50", value_en: "29, 34, 36, 40, 47, 50", }, ], contacts: [ { label: "Website", value: "www.housesamyan.com", href: "https://www.housesamyan.com", }, { label: "Facebook", value: "House Samyan", href: "https://www.facebook.com/housesamyan", }, { label: "Call", value: "098-869-0997", href: "tel:0988690997" }, ], payments: ["เงินสด", "บัตรเครดิต", "สแกนจ่าย"], // ใส่ path รูปจริง เช่น "/images/cinemas/house-samyan/1.jpg" — ป้าย "+N" คำนวณจากความยาวอาร์เรย์นี้ photos: [], }, { slug: "thana-cineplex", name: "THANA CINEPLEX", tags: ["หนังในกระแส", "ยอดนิยม"], location_label: "เดอะมอลล์งามวงศ์วาน นนทบุรี", location_label_en: "The Mall Ngamwongwan, Nonthaburi", coordinates: { latitude: 13.8564363, longitude: 100.5419053 }, description: "", map_url: null, address_lines: [], transport: [], contacts: [], payments: [], photos: [], }, { slug: "century-the-movie-plaza", name: "CENTURY", name_th: "เซ็นจูรี่มูฟวี่พลาซ่า", tags: ["หนังในกระแส"], location_label: "เซ็นจูรี่ เดอะมูฟวี่ พลาซ่า อนุสาวรีย์ชัยฯ กรุงเทพฯ", location_label_en: "Century The Movie Plaza, Victory Monument, Bangkok", coordinates: { latitude: 13.7616674, longitude: 100.5371572 }, description: "", map_url: null, address_lines: [], transport: [], contacts: [], payments: [], photos: [], }, { slug: "ck-plaza", name: "CK PLAZA", tags: ["หนังในกระแส"], location_label: "", coordinates: null, description: "", map_url: null, address_lines: [], transport: [], contacts: [], payments: [], photos: [], }, { slug: "major-hollywood", name: "MAJOR HOLLYWOOD", tags: ["หนังในกระแส", "ยอดนิยม"], location_label: "", coordinates: null, description: "", map_url: null, address_lines: [], transport: [], contacts: [], payments: [], photos: [], }, { slug: "coliseum-paradise", name: "COLISEUM PARADISE", tags: ["หนังคลาสสิก", "อาร์ตเฮาส์"], location_label: "", coordinates: null, description: "", map_url: null, address_lines: [], transport: [], contacts: [], payments: [], photos: [], }, // รายการที่ผู้ใช้ให้มา — ใส่เฉพาะชื่อ TH/EN ฟิลด์อื่นรอเติม { slug: "alliance-francaise-de-bangkok", name: "Alliance Française de Bangkok", name_th: "สมาคมฝรั่งเศสกรุงเทพ", tags: [], location_label: "", coordinates: null, description: "", map_url: null, address_lines: [], transport: [], contacts: [], payments: [], photos: [], }, { slug: "cinema-oasis", name: "Cinema Oasis", name_th: "มูลนิธิซิเนม่าโอเอซิส", tags: [], location_label: "", coordinates: null, description: "", map_url: null, address_lines: [], transport: [], contacts: [], payments: [], photos: [], }, { slug: "the-friese-greene-club", name: "The Friese-Greene Club", name_th: "เดอะ ฟรีส-กรีน คลับ", tags: [], location_label: "", coordinates: null, description: "", map_url: null, address_lines: [], transport: [], contacts: [], payments: [], photos: [], }, { slug: "century-the-movie-plaza-sukhumvit", name: "Century - The Movie Plaza Sukhumvit", name_th: "เซ็นจูรี่มูวี่พลาซ่า สุขุมวิท", tags: [], location_label: "", coordinates: null, description: "", map_url: null, address_lines: [], transport: [], contacts: [], payments: [], photos: [], }, { slug: "thai-film-archive", name: "Thai Film Archive", name_th: "หอภาพยนตร์", tags: [], location_label: "", coordinates: null, description: "", map_url: null, address_lines: [], transport: [], contacts: [], payments: [], photos: [], }, ]; /** ฟิลด์ที่มี *_en จะใช้เมื่อภาษาเป็นอังกฤษ และ fallback เป็นไทยเมื่อยังไม่แปล */ function pick(primary: string, english: string | undefined, locale: Locale) { return locale === "en" && english ? english : primary; } function pickList( primary: string[], english: string[] | undefined, locale: Locale, ): string[] { return locale === "en" && english && english.length > 0 ? english : primary; } export function cinemaLocationLabel(cinema: Cinema, locale: Locale): string { return pick(cinema.location_label, cinema.location_label_en, locale); } /** ชื่อที่แสดงตามภาษา — ไทยใช้ name_th ถ้ามี ไม่งั้นใช้ชื่ออังกฤษ */ export function cinemaName(cinema: Cinema, locale: Locale): string { if (locale === "th" && cinema.name_th) return cinema.name_th; return cinema.name; } export function cinemaDescription(cinema: Cinema, locale: Locale): string { return pick(cinema.description, cinema.description_en, locale); } export function cinemaAddressLines(cinema: Cinema, locale: Locale): string[] { return pickList(cinema.address_lines, cinema.address_lines_en, locale); } /** * สิ่งอำนวยความสะดวกของโรงนี้ เรียงตาม FACILITY_KEYS * ข้อมูลเก่าที่ไม่มีฟิลด์นี้จะได้อาร์เรย์ว่าง (UI แสดง "ไม่มีข้อมูล") */ export function cinemaFacilities(cinema: Cinema): FacilityKey[] { const selected = new Set(cinema.facilities ?? []); return FACILITY_KEYS.filter((key) => selected.has(key)); } /** หมวดที่เลือกได้ในหลังบ้าน — ตัด "ทั้งหมด" ออกเพราะใช้เป็นตัวกรอง "ไม่กรอง" */ export const ASSIGNABLE_CATEGORIES: CinemaCategory[] = CINEMA_CATEGORIES.filter( (category) => category !== DEFAULT_CATEGORY, ); export function transportValue(route: TransportMode, locale: Locale): string { return pick(route.value, route.value_en, locale); } /** ประเภทภาพยนตร์ที่แสดงบนการ์ด สร้างจาก tags เพื่อไม่ต้องกรอกซ้ำ */ export function cinemaCategoryLabel( cinema: Cinema, messages: Messages, ): string { return cinema.tags.map((tag) => messages.tags[tag] ?? tag).join(" · "); } export function hasCategory(cinema: Cinema, category: CinemaCategory): boolean { return category === DEFAULT_CATEGORY || cinema.tags.includes(category); } /** ชั้นกรองที่ 1: ประเภทโรงหนัง — null = ไม่กรอง */ export function hasVenue(cinema: Cinema, venue: VenueType | null): boolean { return venue === null || cinema.venue_type === venue; } /** ตัวกรองประเภทในลิสต์หลังบ้าน — "all" = ทุกประเภท, "unset" = ยังไม่จัดประเภท */ export type VenueFilterValue = VenueType | "all" | "unset"; /** กรองรายชื่อโรงหนังในหลังบ้านตามประเภท (ชั้นกรองที่ 1) + คำค้นชื่อ/slug */ export function filterAdminCinemas( cinemas: Cinema[], { venue, query, }: { venue: VenueFilterValue; query: string; }, ): Cinema[] { const needle = query.trim().toLowerCase(); return cinemas.filter((cinema) => { if (venue === "unset") { if (cinema.venue_type) return false; } else if (venue !== "all" && cinema.venue_type !== venue) { return false; } if (!needle) return true; return `${cinema.name} ${cinema.name_th ?? ""} ${cinema.slug}` .toLowerCase() .includes(needle); }); } /** ตั้งประเภทให้หลายโรงพร้อมกัน (คืนลิสต์ใหม่ ไม่แตะตัวเดิม) */ export function setVenueForSlugs( cinemas: Cinema[], slugs: string[], venue: VenueType, ): Cinema[] { if (slugs.length === 0) return cinemas; const target = new Set(slugs); return cinemas.map((cinema) => target.has(cinema.slug) ? { ...cinema, venue_type: venue } : cinema, ); } /** นับจำนวนโรงต่อประเภท (สำหรับสรุปในหลังบ้าน) */ export function venueCounts( cinemas: Cinema[], ): Record { const counts: Record = { all: cinemas.length, unset: 0, โรงภาพยนตร์ท้องถิ่น: 0, โรงภาพยนตร์อินดี้: 0, กลุ่มคนฉายหนัง: 0, }; for (const cinema of cinemas) { if (cinema.venue_type) counts[cinema.venue_type] += 1; else counts.unset += 1; } return counts; } export function findCinemaBySlug( cinemas: Cinema[], slug: string | undefined, ): Cinema | undefined { if (!slug) return undefined; return cinemas.find((cinema) => cinema.slug === slug); } export function listOtherCinemas( cinemas: Cinema[], slug: string, limit = 4, ): Cinema[] { return cinemas .filter((cinema) => cinema.slug !== slug && !cinema.hidden) .slice(0, limit); } /** โรงหนังที่แสดงบนหน้าเว็บ (ตัดตัวที่ถูกซ่อนในหลังบ้านออก) */ export function publiclyVisible(cinemas: Cinema[]): Cinema[] { return cinemas.filter((cinema) => !cinema.hidden); }