/** จำนวนช่องภาพที่แกลเลอรีแสดงจริง: 1 ภาพหลัก + 2 ภาพย่อย */ export const GALLERY_SLOTS = 3; const THUMB_SLOTS = GALLERY_SLOTS - 1; export type GalleryView = { main: string | null; thumbs: string[]; /** จำนวนรูปที่ยังไม่ถูกแสดง ใช้ทำป้าย "+N" — 0 คือไม่ต้องมีป้าย */ remaining: number; }; /** * หมุนรายการรูปให้เริ่มที่ index (ค่าติดลบ/เกินจำนวนได้ — วนกลับอัตโนมัติ) * ใช้กับปุ่มก่อนหน้า/ถัดไปของแกลเลอรี: ภาพหลักเลื่อน และภาพย่อยเลื่อนตาม */ export function rotateGallery(photos: string[], index: number): string[] { const total = photos.length; if (total === 0) return []; const start = ((index % total) + total) % total; return [...photos.slice(start), ...photos.slice(0, start)]; } /** * แบ่งรูปทั้งหมดเป็นภาพหลัก + ภาพย่อย และนับรูปที่เหลือ * ป้าย "+N" จึงมาจากจำนวนรูปจริง ไม่ใช่ค่าคงที่ในโค้ด */ export function splitGallery(photos: string[]): GalleryView { const [main = null, ...rest] = photos; return { main, thumbs: rest.slice(0, THUMB_SLOTS), remaining: Math.max(rest.length - THUMB_SLOTS, 0), }; }