98 lines
3.3 KiB
TypeScript
98 lines
3.3 KiB
TypeScript
import { IconChevronLeft, IconChevronRight } from "@tabler/icons-react";
|
|
import type { ReactNode } from "react";
|
|
|
|
import { Logo } from "@/components/site/Logo";
|
|
import { splitGallery } from "@/lib/gallery";
|
|
import { useI18n } from "@/lib/i18n";
|
|
|
|
type GalleryProps = {
|
|
photos: string[];
|
|
cinemaName: string;
|
|
};
|
|
|
|
type GallerySlotProps = {
|
|
photo: string | null;
|
|
alt: string;
|
|
/** เนื้อหาที่แสดงเมื่อยังไม่มีรูป — ใช้โลโก้ AlterFlixHub แทนข้อความ */
|
|
placeholder: ReactNode;
|
|
className: string;
|
|
};
|
|
|
|
function GallerySlot({ photo, alt, placeholder, className }: GallerySlotProps) {
|
|
if (!photo) {
|
|
return (
|
|
<div
|
|
className={`flex items-center justify-center bg-[#242424] text-sm text-[#999] ${className}`}
|
|
>
|
|
{placeholder}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<img
|
|
src={photo}
|
|
alt={alt}
|
|
className={`bg-[#242424] object-cover ${className}`}
|
|
/>
|
|
);
|
|
}
|
|
|
|
/** แกลเลอรีภาพโรงหนัง — ป้าย "+N" คำนวณจากจำนวนรูปจริงในข้อมูล */
|
|
export function Gallery({ photos, cinemaName }: GalleryProps) {
|
|
const { messages } = useI18n();
|
|
const { main, thumbs, remaining } = splitGallery(photos);
|
|
const [firstThumb = null, secondThumb = null] = thumbs;
|
|
|
|
return (
|
|
<section className="grid gap-6 lg:grid-cols-[minmax(0,807px)_minmax(0,387px)]">
|
|
<div className="relative overflow-hidden rounded-xl">
|
|
<GallerySlot
|
|
photo={main}
|
|
alt={`${messages.gallery.main} — ${cinemaName}`}
|
|
placeholder={<Logo size="md" />}
|
|
className="aspect-[269/202] w-full lg:aspect-auto lg:h-[606px]"
|
|
/>
|
|
<button
|
|
type="button"
|
|
aria-label={messages.gallery.previous}
|
|
className="absolute left-6 top-1/2 flex size-10 -translate-y-1/2 items-center justify-center rounded-full bg-black/50"
|
|
>
|
|
<IconChevronLeft size={24} />
|
|
</button>
|
|
<button
|
|
type="button"
|
|
aria-label={messages.gallery.next}
|
|
className="absolute right-6 top-1/2 flex size-10 -translate-y-1/2 items-center justify-center rounded-full bg-black/50"
|
|
>
|
|
<IconChevronRight size={24} />
|
|
</button>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 gap-6 lg:grid-cols-1 lg:grid-rows-2">
|
|
<div className="overflow-hidden rounded-xl">
|
|
<GallerySlot
|
|
photo={firstThumb}
|
|
alt={`${messages.gallery.second} — ${cinemaName}`}
|
|
placeholder={<Logo size="sm" />}
|
|
className="aspect-[387/290] w-full"
|
|
/>
|
|
</div>
|
|
<div className="relative overflow-hidden rounded-xl">
|
|
<GallerySlot
|
|
photo={secondThumb}
|
|
alt={`${messages.gallery.third} — ${cinemaName}`}
|
|
placeholder={<Logo size="sm" />}
|
|
className="aspect-[387/290] w-full"
|
|
/>
|
|
{remaining > 0 ? (
|
|
<div className="absolute bottom-2.5 right-2.5 flex size-[60px] items-center justify-center rounded-lg bg-black/80 text-lg font-medium">
|
|
{messages.gallery.more(remaining)}
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|