94 lines
3.4 KiB
TypeScript
94 lines
3.4 KiB
TypeScript
import { IconMap } from "@tabler/icons-react";
|
|
|
|
import { COLORS } from "@/lib/design-tokens";
|
|
import { cinemaAddressLines, cinemaName, type Cinema } from "@/lib/cinemas";
|
|
import { useI18n } from "@/lib/i18n";
|
|
import { mapEmbedUrl, mapOpenUrl } from "@/lib/map-embed";
|
|
|
|
/**
|
|
* การ์ดที่ตั้ง + แผนที่
|
|
* แผนที่ดึงจากลิงก์ Google Maps ของโรง ถ้าไม่มีจึงใช้พิกัดที่กรอกในหลังบ้าน
|
|
* ถ้าไม่มีทั้งสองอย่างแสดง "ไม่มีข้อมูล"
|
|
*/
|
|
export function LocationPanel({ cinema }: { cinema: Cinema }) {
|
|
const { locale, messages } = useI18n();
|
|
const addressLines = cinemaAddressLines(cinema, locale);
|
|
const embedUrl = mapEmbedUrl(cinema, locale);
|
|
const openUrl = mapOpenUrl(cinema);
|
|
|
|
return (
|
|
<aside
|
|
className="flex flex-col gap-6 self-start rounded-xl p-6"
|
|
style={{ border: `1px solid ${COLORS.border}` }}
|
|
>
|
|
<div className="flex flex-col gap-4">
|
|
<div className="flex items-center justify-between gap-3">
|
|
<h2 className="text-2xl font-semibold leading-[1.3]">
|
|
{messages.detail.location}
|
|
</h2>
|
|
{openUrl ? (
|
|
<a
|
|
href={openUrl}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className="inline-flex items-center gap-1 text-sm text-[#D47272] transition hover:text-white"
|
|
>
|
|
<IconMap size={16} />
|
|
{messages.detail.openMap}
|
|
</a>
|
|
) : null}
|
|
</div>
|
|
|
|
{embedUrl ? (
|
|
<div
|
|
className="relative h-[183px] overflow-hidden rounded-xl"
|
|
style={{
|
|
border: `1px solid ${COLORS.border}`,
|
|
background: COLORS.surfaceMuted,
|
|
}}
|
|
>
|
|
{/* ลายตารางใต้แผนที่ — กันช่องว่างขาวตอน iframe ยังโหลดไม่เสร็จ */}
|
|
<div
|
|
aria-hidden="true"
|
|
className="pointer-events-none absolute inset-0"
|
|
style={{
|
|
backgroundImage:
|
|
"linear-gradient(rgba(255,255,255,0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px)",
|
|
backgroundSize: "24px 24px",
|
|
}}
|
|
/>
|
|
<iframe
|
|
title={`${messages.detail.location} — ${cinemaName(cinema, locale)}`}
|
|
src={embedUrl}
|
|
loading="lazy"
|
|
referrerPolicy="no-referrer-when-downgrade"
|
|
allowFullScreen
|
|
className="relative size-full border-0"
|
|
/>
|
|
</div>
|
|
) : (
|
|
<div
|
|
className="flex h-[183px] items-center justify-center rounded-xl text-sm text-[#777]"
|
|
style={{
|
|
border: `1px dashed ${COLORS.border}`,
|
|
background: COLORS.surfaceMuted,
|
|
}}
|
|
>
|
|
{messages.detail.noData}
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<p className="text-sm leading-[1.3] text-[#999]">
|
|
{addressLines.length > 0
|
|
? addressLines.map((line) => (
|
|
<span key={line} className="block">
|
|
{line}
|
|
</span>
|
|
))
|
|
: messages.detail.addressFallback}
|
|
</p>
|
|
</aside>
|
|
);
|
|
}
|