import type { LightboxTexts } from './types.js' /** * English fallbacks, per field — the same philosophy as NOTIFICATION_FALLBACK. * Editors translate them in Form messages → Image viewer (iapl `lightbox: true`). */ export const LIGHTBOX_FALLBACK: LightboxTexts = { close: 'Close', counter: '{current} / {total}', dialog: 'Image viewer', next: 'Next image', open: 'Enlarge image', previous: 'Previous image', } /** Polish fallbacks — used on a page whose locale is Polish. */ export const LIGHTBOX_FALLBACK_PL: LightboxTexts = { close: 'Zamknij', counter: '{current} / {total}', dialog: 'Podgląd zdjęcia', next: 'Następne zdjęcie', open: 'Powiększ zdjęcie', previous: 'Poprzednie zdjęcie', } /** Fallbacks for a page language: Polish for 'pl' / 'pl-PL', English for anything else. */ export const lightboxFallback = (locale?: string): LightboxTexts => locale?.toLowerCase().startsWith('pl') ? LIGHTBOX_FALLBACK_PL : LIGHTBOX_FALLBACK /** Merges partial texts over the fallback for `locale` (English when omitted); empty strings fall back too. */ export function resolveLightboxTexts( texts?: null | Partial>, locale?: string, ): LightboxTexts { const out = { ...lightboxFallback(locale) } for (const key of Object.keys(out) as (keyof LightboxTexts)[]) { const value = texts?.[key] if (typeof value === 'string' && value.trim()) {out[key] = value} } return out } /** "{current} / {total}" → "2 / 5". */ export const formatLightboxCounter = (template: string, current: number, total: number): string => template.replace('{current}', String(current)).replace('{total}', String(total)) /** * The index after a step of `delta`. `loop` wraps around the ends; without it * the index stops at the first and last image. */ export function lightboxIndex(index: number, delta: number, total: number, loop = true): number { if (total <= 0) {return 0} const next = index + delta if (loop) {return ((next % total) + total) % total} return Math.min(Math.max(next, 0), total - 1) }