Files
web-alterflixhub/app/components/site/CinemaCard.tsx
T
2026-11-01 17:24:44 +07:00

99 lines
3.4 KiB
TypeScript

import {
IconArrowRight,
IconBuildingCommunity,
IconMapPin,
} from "@tabler/icons-react";
import { Link } from "react-router";
import {
CARD_GRADIENTS,
cinemaCategoryLabel,
cinemaLocationLabel,
cinemaName,
type Cinema,
} from "@/lib/cinemas";
import { formatDistance } from "@/lib/geo";
import { trackEvent } from "@/lib/analytics-client";
import { useNearMe } from "@/hooks/use-near-me";
import { useI18n } from "@/lib/i18n";
type CinemaCardProps = {
cinema: Cinema;
/** ลำดับการ์ด ใช้เลือก gradient ให้สลับสีสม่ำเสมอ */
index?: number;
/** ที่มาของการ์ด ใช้บันทึกสถิติการคลิก */
source?: string;
/** คำค้นปัจจุบัน (แนบไปกับการคลิกเพื่อวัด CTR ของคำค้น) */
searchQuery?: string;
};
export function CinemaCard({
cinema,
index = 0,
source = "list",
searchQuery,
}: CinemaCardProps) {
const { locale, messages } = useI18n();
const { distances } = useNearMe();
const gradient = CARD_GRADIENTS[index % CARD_GRADIENTS.length];
// รูปแรก = ปกการ์ด (ถ้าไม่มีรูป ใช้ gradient เดิมเป็นพื้นหลัง)
const cover = cinema.photos.find((photo) => photo.trim() !== "");
const distanceLabel = formatDistance(
distances[cinema.slug],
messages.card.distanceFallback,
);
return (
<article
className={`relative flex aspect-[3/4] flex-col justify-end overflow-hidden rounded-[20px] bg-gradient-to-br p-2 lg:aspect-auto lg:h-[308px] ${gradient}`}
>
{cover ? (
<>
<img
src={cover}
alt=""
aria-hidden="true"
loading="lazy"
className="absolute inset-0 size-full object-cover"
/>
{/* ไล่เงาเพื่อให้ตัวอักษรบนการ์ดอ่านได้ */}
<div
aria-hidden="true"
className="absolute inset-0 bg-gradient-to-t from-[#0D0D0D]/95 via-[#0D0D0D]/35 to-transparent"
/>
</>
) : null}
<div className="relative flex flex-col gap-1.5 rounded-2xl border border-white/10 bg-[#1B1B1B]/80 p-3 backdrop-blur-xl">
<span className="text-[10px] text-[#B3B3B3]">{distanceLabel}</span>
<h3 className="text-sm font-semibold">{cinemaName(cinema, locale)}</h3>
<p className="flex items-center gap-1.5 text-xs text-[#B3B3B3]">
<IconMapPin size={12} />
{cinemaLocationLabel(cinema, locale) || messages.card.locationFallback}
</p>
<p className="flex items-center gap-1.5 text-xs text-[#B3B3B3]">
<IconBuildingCommunity size={12} />
{cinemaCategoryLabel(cinema, messages) ||
messages.card.categoryFallback}
</p>
<Link
to={`/cinema/${cinema.slug}`}
onClick={() =>
trackEvent({
type: "cinema_select",
slug: cinema.slug,
source,
query: searchQuery,
position: index + 1,
locale,
})
}
className="mt-3 flex items-center justify-end gap-2 text-xs font-medium"
>
{messages.card.seeDetail} <IconArrowRight size={12} />
</Link>
</div>
</article>
);
}