import { IconChevronLeft, IconChevronRight } from "@tabler/icons-react"; import { useState, type ReactNode } from "react"; import { Logo } from "@/components/site/Logo"; import { PhotoImage } from "@/components/site/PhotoImage"; import { rotateGallery, 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) { return ( ); } /** แกลเลอรีภาพโรงหนัง — ปุ่มลูกศรเลื่อนดูภาพทั้งหมดโดยภาพหลักและภาพย่อยเลื่อนตามกัน */ export function Gallery({ photos, cinemaName }: GalleryProps) { const { messages } = useI18n(); const [startIndex, setStartIndex] = useState(0); const total = photos.length; // หมุนรายการตามตำแหน่งที่เลือก แล้วแบ่งเป็นภาพหลัก + ภาพย่อยตามเดิม const { main, thumbs, remaining } = splitGallery( rotateGallery(photos, startIndex), ); const [firstThumb = null, secondThumb = null] = thumbs; const canNavigate = total > 1; function step(direction: 1 | -1) { setStartIndex((current) => current + direction); } return ( } className="fx-swap aspect-[269/202] w-full lg:aspect-auto lg:h-[606px]" /> {canNavigate ? ( <> step(-1)} 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 text-white transition after:absolute after:-inset-1 after:content-[''] hover:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#A92626] active:scale-95" > step(1)} 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 text-white transition after:absolute after:-inset-1 after:content-[''] hover:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#A92626] active:scale-95" > > ) : null} } className="fx-swap aspect-[387/290] w-full" /> } className="fx-swap aspect-[387/290] w-full" /> {remaining > 0 ? ( {messages.gallery.more(remaining)} ) : null} ); }