import { IconArrowBackUp } from "@tabler/icons-react"; import { useEffect } from "react"; import { Link, useParams } from "react-router"; import { CinemaNotFound } from "@/components/cinema/CinemaNotFound"; import { CinemaSummary } from "@/components/cinema/CinemaSummary"; import { ContactPanel } from "@/components/cinema/ContactPanel"; import { FacilitiesSection } from "@/components/cinema/FacilitiesSection"; import { Gallery } from "@/components/cinema/Gallery"; import { TransportList } from "@/components/cinema/TransportList"; import { CinemaGrid } from "@/components/site/CinemaGrid"; import { Reveal } from "@/components/site/Reveal"; import { ShareButton } from "@/components/site/ShareButton"; import { SiteShell } from "@/components/site/SiteShell"; import { useNearMe } from "@/hooks/use-near-me"; import { trackEvent } from "@/lib/analytics-client"; import { APP_TITLE } from "@/lib/app-config"; import { findCinemaBySlug, cinemaName, listOtherCinemas } from "@/lib/cinemas"; import { useContent } from "@/lib/content-context"; import { readContent } from "@/lib/content.server"; import { sortByDistance } from "@/lib/geo"; import { useI18n } from "@/lib/i18n"; import { DEFAULT_LOCALE, MESSAGES } from "@/lib/i18n/messages"; import { resolvePageOrigin } from "@/lib/page-origin"; import { breadcrumbJsonLd, cinemaJsonLd, originFromMatches, pageMeta, } from "@/lib/seo"; /** head (title) ไม่เปลี่ยนตามภาษา — meta() ไม่มี access ต่อ cookie */ const HEAD_MESSAGES = MESSAGES[DEFAULT_LOCALE]; /** ฟิลด์ที่ต้องใช้ทำ SEO ของหน้าโรงหนัง (ส่งจาก loader เพื่อให้ crawler เห็นครบใน HTML แรก) */ type CinemaSeo = { /** origin ของคำขอ (ไม่ฝังโดเมน) */ origin: string; name: string | null; description: string | null; locationLabel: string | null; coordinates: { latitude: number; longitude: number } | null; mapUrl: string | null; photo: string | null; }; export async function loader({ params, request, }: { params: { slug?: string }; request: Request; }): Promise { const content = await readContent(); const cinema = findCinemaBySlug(content.cinemas, params.slug); if (!cinema) { return { origin: resolvePageOrigin(request), name: null, description: null, locationLabel: null, coordinates: null, mapUrl: null, photo: null, }; } return { origin: resolvePageOrigin(request), name: cinema.name, description: cinema.description.trim() === "" ? null : cinema.description, locationLabel: cinema.location_label || null, coordinates: cinema.coordinates, mapUrl: cinema.map_url, photo: cinema.photos.find((photo) => photo.trim() !== "") ?? null, }; } export function meta({ loaderData, params, matches, }: { loaderData?: CinemaSeo; params?: { slug?: string }; matches?: Array<{ id?: string; data?: unknown }>; }) { const origin = loaderData?.origin ?? originFromMatches(matches); const name = loaderData?.name ?? null; if (!name) { return pageMeta({ origin, title: `${HEAD_MESSAGES.meta.cinemaNotFoundTitle} — ${APP_TITLE}`, description: HEAD_MESSAGES.meta.cinemaNotFoundTitle, path: "/", noIndex: true, }); } const path = `/cinema/${params?.slug ?? ""}`; const location = loaderData?.locationLabel ?? ""; const description = loaderData?.description ?? `${name}${location ? ` — ${location}` : ""} · ที่ตั้ง วิธีเดินทาง สิ่งอำนวยความสะดวก และช่องทางจองตั๋ว`; const title = location ? `${name} — ${location} | AlterFlixHub` : `${name} — AlterFlixHub`; return [ ...pageMeta({ origin, title, description, path }), ...breadcrumbJsonLd(origin, [ { name: "หน้าแรก", path: "/" }, { name, path }, ]), ...cinemaJsonLd({ origin, name, description, path, image: loaderData?.photo ?? null, coordinates: loaderData?.coordinates ?? null, locationLabel: location, mapUrl: loaderData?.mapUrl ?? null, }), ]; } export default function CinemaDetailRoute() { const { messages, locale } = useI18n(); const { cinemas } = useContent(); const { status: nearMeStatus, distances } = useNearMe(); const { slug } = useParams(); const cinema = findCinemaBySlug(cinemas, slug); // เก็บสถิติการเปิดดูหน้ารายละเอียด (ต้องอยู่ก่อน early return เพื่อให้ hook เรียกทุกครั้ง) useEffect(() => { if (!cinema) return; trackEvent({ type: "cinema_view", slug: cinema.slug, locale }); }, [cinema, locale]); if (!cinema) return ; const otherCinemas = listOtherCinemas(cinemas, cinema.slug); const orderedOthers = nearMeStatus === "ready" ? sortByDistance(otherCinemas, distances) : otherCinemas; return (
{messages.detail.back}

{messages.detail.otherCinemas}

{/* แชร์หน้ารายละเอียดโรงนี้ (ท้ายหน้า) */}

{messages.share.pageLabel}

{cinemaName(cinema, locale)}

); }