"use client"; import { useState } from 'react'; import { Image, Tooltip } from 'antd'; import NextImage from 'next/image'; import { EyeOutlined, SwapOutlined, UserOutlined, CameraOutlined, BulbOutlined } from '@ant-design/icons'; import { useDeviceType } from '@/hooks/useDeviceType'; import type { PhotoPreviewSectionProps, PhotoType } from './types'; import './styles.css'; /** * Photo Preview Section Component * Displays a horizontal list of photos with type indicators and preview/replace functionality * @param photos - Array of photos with type information * @param onEdit - Callback when a photo is clicked for editing * @param onReplace - Callback when replace button is clicked * @param className - Additional CSS classes */ export default function PhotoPreviewSection({ photos = [], onEdit, onReplace, className = '', }: PhotoPreviewSectionProps) { const [previewVisible, setPreviewVisible] = useState(false); const [previewImage, setPreviewImage] = useState(''); const [hoveredIndex, setHoveredIndex] = useState(null); const { isMobileDevice } = useDeviceType(); /** * Get icon for photo type */ const getTypeIcon = (type: PhotoType) => { switch (type) { case 'character': return ; case 'scene': return ; case 'prop': return ; default: return null; } }; /** * Get label for photo type */ const getTypeLabel = (type: PhotoType) => { switch (type) { case 'character': return 'Character'; case 'scene': return 'Scene'; case 'prop': return 'Prop'; default: return ''; } }; /** * Handle photo preview */ const handlePreview = (url: string) => { setPreviewImage(url); setPreviewVisible(true); }; /** * Handle preview button click */ const handlePreviewClick = (e: React.MouseEvent, url: string) => { e.stopPropagation(); handlePreview(url); }; /** * Handle replace button click */ const handleReplaceClick = (e: React.MouseEvent, index: number) => { e.stopPropagation(); onReplace?.(index); }; /** Don't render if no photos */ if (photos.length === 0) { return null; } return (
{/* Photo List Container with Horizontal Scroll */}
{photos.map((photo, index) => { const photoName = photo.name || `${getTypeLabel(photo.type)} ${index + 1}`; return (
{/* Photo Image Container */}
setHoveredIndex(index)} onMouseLeave={() => setHoveredIndex(null)} > {/* Photo Image */}
{/* Hover Overlay with Preview and Replace Icons */}
{/* Preview Button */} {/* Replace Button */}
{/* Type Icon - Bottom Left Corner */}
{getTypeIcon(photo.type)}
{/* Photo Name - Below Image */} {isMobileDevice ? ( // H5: Direct display with line-clamp
{photoName}
) : ( // PC: Tooltip on hover
{photoName}
)}
); })}
{/* Preview Modal - Using absolute positioning to avoid layout space */}
Preview { setPreviewVisible(visible); }, }} />
); }