import React, { useEffect, useRef } from 'react'; import { X, Download, Filter, SortAsc, Search, Calendar, Type, HardDrive, Check, Upload, Star } from 'lucide-react'; import { Button } from '../common'; import { PhotoCategory } from '../../types'; import { useTranslation } from 'react-i18next'; import { GalleryFilter, type FilterType } from './GalleryFilter'; interface GallerySidebarProps { isOpen: boolean; onClose: () => void; categories: PhotoCategory[]; selectedCategoryId: number | null; onCategoryChange: (categoryId: number | null) => void; searchTerm: string; onSearchChange: (term: string) => void; sortBy: 'date' | 'name' | 'size' | 'rating'; onSortChange: (sort: 'date' | 'name' | 'size' | 'rating') => void; isSelectionMode: boolean; onToggleSelectionMode: () => void; selectedCount: number; onDownloadAll: () => void; onDownloadSelected: () => void; isDownloading: boolean; isExpired?: boolean; allowDownloads?: boolean; photoCounts?: Record; totalPhotos: number; isMobile: boolean; galleryLayout?: string; allowUploads?: boolean; onUploadClick?: () => void; feedbackEnabled?: boolean; filterType?: FilterType; onFilterChange?: (filter: FilterType) => void; likeCount?: number; favoriteCount?: number; } export const GallerySidebar: React.FC = ({ isOpen, onClose, categories, selectedCategoryId, onCategoryChange, searchTerm, onSearchChange, sortBy, onSortChange, isSelectionMode, onToggleSelectionMode, selectedCount, onDownloadAll, onDownloadSelected, isDownloading, isExpired = false, allowDownloads = true, photoCounts = {}, totalPhotos, isMobile, galleryLayout, allowUploads, onUploadClick, feedbackEnabled = false, filterType = 'all', onFilterChange, likeCount = 0, favoriteCount = 0 }) => { const { t } = useTranslation(); const sidebarRef = useRef(null); // Close sidebar when clicking outside on mobile useEffect(() => { if (isMobile && isOpen) { const handleClickOutside = (event: MouseEvent) => { if (sidebarRef.current && !sidebarRef.current.contains(event.target as Node)) { onClose(); } }; document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); } }, [isMobile, isOpen, onClose]); // Prevent body scroll when sidebar is open on mobile useEffect(() => { if (isMobile && isOpen) { document.body.style.overflow = 'hidden'; return () => { document.body.style.overflow = 'unset'; }; } }, [isMobile, isOpen]); const sortOptions = [ { value: 'date', label: t('gallery.sortByDate'), icon: Calendar }, { value: 'name', label: t('gallery.sortByName'), icon: Type }, { value: 'size', label: t('gallery.sortBySize'), icon: HardDrive }, { value: 'rating', label: t('gallery.sortByRating', 'Rating'), icon: Star } ]; return ( <> {/* Backdrop for mobile */} {isMobile && isOpen && (
)} {/* Sidebar */}
{/* Header */}

{t('gallery.filters')}

{/* Content */}
{/* Upload Section - Only show on mobile when uploads are allowed */} {isMobile && allowUploads && onUploadClick && (
)} {/* Search Section - Hidden for carousel layout */} {galleryLayout !== 'carousel' && (
onSearchChange(e.target.value)} placeholder={t('gallery.searchPlaceholder')} className="w-full pl-10 pr-4 py-2 border border-neutral-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent" />
)} {/* Download Section - Hidden if gallery is expired or downloads disabled */} {allowDownloads && (

{t('gallery.download')}

{isSelectionMode && selectedCount > 0 && ( )}
)} {/* Feedback Filter Section */} {feedbackEnabled && onFilterChange && (
{ onFilterChange(filter); if (isMobile) onClose(); }} feedbackEnabled={feedbackEnabled} likeCount={likeCount} favoriteCount={favoriteCount} className="w-full" />
)} {/* Categories Section - Hidden for carousel layout */} {galleryLayout !== 'carousel' && categories.length > 0 && (

{t('gallery.categories')}

{categories.map((category) => { const count = photoCounts[category.id] || 0; const isSelected = selectedCategoryId === category.id; return ( ); })}
)} {/* Sort Section - Hidden for carousel and timeline layouts */} {galleryLayout !== 'carousel' && galleryLayout !== 'timeline' && (

{t('gallery.sortBy')}

{sortOptions.map((option) => { const Icon = option.icon; const isSelected = sortBy === option.value; return ( ); })}
)}
); };