import { IconChevronLeft, IconChevronRight } from "@tabler/icons-react";
import { useState, type ReactNode } from "react";
import { Logo } from "@/components/site/Logo";
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) {
if (!photo) {
return (
{placeholder}
);
}
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 ? (
<>
>
) : null}
}
className="fx-swap aspect-[387/290] w-full"
/>
}
className="fx-swap aspect-[387/290] w-full"
/>
{remaining > 0 ? (
{messages.gallery.more(remaining)}
) : null}
);
}