import { api } from '../api.js'; import { GestureHandler, PullToRefreshIndicator } from '../gesture-handler.js'; class PhotoGallery extends HTMLElement { constructor() { super(); this.photos = []; this.boundHandleClick = this.handleClick.bind(this); this.gestureHandler = null; this.pullIndicator = null; } connectedCallback() { this.addEventListener('click', this.boundHandleClick); this.render(); this.loadPhotos(); this.initGestures(); } disconnectedCallback() { this.removeEventListener('click', this.boundHandleClick); if (this.gestureHandler) { this.gestureHandler.destroy(); } if (this.pullIndicator) { this.pullIndicator.destroy(); } } initGestures() { const container = this.querySelector('.photo-gallery'); if (!container) return; this.pullIndicator = new PullToRefreshIndicator(container); this.gestureHandler = new GestureHandler(container); this.gestureHandler.on('pullToRefresh', async () => { this.pullIndicator.showRefreshing(); await this.loadPhotos(); this.pullIndicator.hide(); }); container.addEventListener('pull-progress', (e) => { this.pullIndicator.setProgress(e.detail.progress); }); container.addEventListener('pull-end', () => { if (this.pullIndicator) { this.pullIndicator.hide(); } }); } async loadPhotos() { try { this.photos = await api.getPhotos(); this.renderPhotos(); } catch (error) { console.error('Failed to load photos:', error); this.querySelector('.gallery-grid').innerHTML = '
Failed to load photos
'; } } async renderPhotos() { const grid = this.querySelector('.gallery-grid'); if (this.photos.length === 0) { grid.innerHTML = ''; const header = this.querySelector('.gallery-header'); const empty = document.createElement('p'); empty.className = 'empty-state'; empty.textContent = 'No photos found.'; header.insertAdjacentElement('afterend', empty); return; } // Remove any existing empty-state const existingEmpty = this.querySelector('.empty-state'); if (existingEmpty) existingEmpty.remove(); grid.innerHTML = this.photos.map(photo => `