import type { LocaleCode } from '../i18n/messages'; export interface GalleryBranding { primary_color: string; secondary_color: string; background_color: string; } export interface GalleryMetaResponse { event: { id: number; name: string; slug?: string | null; description?: string | null; gallery_expires_at?: string | null; }; branding: GalleryBranding; } export interface GalleryPhotoResource { id: number; thumbnail_url: string | null; full_url: string | null; download_url: string; likes_count: number; guest_name?: string | null; created_at?: string | null; } export interface GalleryPhotosResponse { data: GalleryPhotoResource[]; next_cursor: string | null; } async function handleResponse(response: Response): Promise { if (response.status === 204) { return {} as T; } const data = await response.json().catch(() => null); if (!response.ok) { const error = new Error((data && data.error && data.error.message) || 'Request failed'); (error as any).code = data?.error?.code ?? response.status; throw error; } return data as T; } export async function fetchGalleryMeta(token: string, locale?: LocaleCode): Promise { const params = new URLSearchParams(); if (locale) params.set('locale', locale); const response = await fetch(`/api/v1/gallery/${encodeURIComponent(token)}${params.toString() ? `?${params.toString()}` : ''}`, { headers: { 'Accept': 'application/json', }, credentials: 'omit', }); return handleResponse(response); } export async function fetchGalleryPhotos(token: string, cursor?: string | null, limit = 30): Promise { const params = new URLSearchParams(); params.set('limit', String(limit)); if (cursor) { params.set('cursor', cursor); } const response = await fetch(`/api/v1/gallery/${encodeURIComponent(token)}/photos?${params.toString()}`, { headers: { 'Accept': 'application/json', }, credentials: 'omit', }); return handleResponse(response); }