import { useState, useEffect } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { motion, AnimatePresence } from 'framer-motion'; import { ArrowLeft, Calendar, Music2, Play, Clock, X, ChevronLeft, ChevronRight } from 'lucide-react'; function AlbumDetail() { const { id } = useParams(); const navigate = useNavigate(); const [album, setAlbum] = useState(null); const [loading, setLoading] = useState(true); const [lightbox, setLightbox] = useState({ open: false, images: [], index: 0 }); const [slideDirection, setSlideDirection] = useState(0); useEffect(() => { fetch(`/api/albums/${id}`) .then(res => res.json()) .then(data => { setAlbum(data); setLoading(false); }) .catch(error => { console.error('앨범 데이터 로드 오류:', error); setLoading(false); }); }, [id]); // 날짜 포맷팅 const formatDate = (dateStr) => { if (!dateStr) return ''; const date = new Date(dateStr); return `${date.getFullYear()}.${String(date.getMonth() + 1).padStart(2, '0')}.${String(date.getDate()).padStart(2, '0')}`; }; // 총 재생 시간 계산 const getTotalDuration = () => { if (!album?.tracks) return ''; let totalSeconds = 0; album.tracks.forEach(track => { if (track.duration) { const parts = track.duration.split(':'); totalSeconds += parseInt(parts[0]) * 60 + parseInt(parts[1]); } }); const mins = Math.floor(totalSeconds / 60); const secs = totalSeconds % 60; return `${mins}:${String(secs).padStart(2, '0')}`; }; // 뒤로가기 const handleBack = () => { navigate('/discography'); }; if (loading) { return (
); } if (!album) { return (

앨범을 찾을 수 없습니다.

); } return ( <>
{/* 뒤로가기 버튼 */} 앨범으로 돌아가기 {/* 앨범 정보 헤더 */}
{/* 앨범 커버 - 크기 증가 */} {album.title} {/* 앨범 정보 */}
{album.album_type}

{album.title}

{formatDate(album.release_date)}
{album.tracks?.length || 0}곡
{getTotalDuration()}

타이틀곡: {album.tracks?.find(t => t.is_title_track === 1)?.title || album.tracks?.[0]?.title}

{/* 앨범 티저 이미지 */} {album.teasers && album.teasers.length > 0 && (

Official Teaser

{album.teasers.map((teaser, index) => (
setLightbox({ open: true, images: album.teasers, index })} className="w-24 h-24 bg-gray-200 rounded-lg overflow-hidden cursor-pointer transition-all duration-200 hover:scale-110 hover:shadow-xl hover:z-10" > {`Teaser
))}
)}
{/* 2열 그리드: 소개글 + 트랙 리스트 */}
{/* 소개글 */} {album.description && (

앨범 소개

{album.description}

)} {/* 트랙 리스트 */}

수록곡

{album.tracks?.map((track, index) => (
{/* 트랙 번호 */}
{String(track.track_number).padStart(2, '0')}
{/* 트랙 정보 */}

{track.title}

{track.is_title_track === 1 && ( 타이틀 )}
{/* 재생 시간 */}
{track.duration || '-'}
))}
{/* 컨셉 포토 섹션 */}

컨셉 포토

{/* 4장 정사각형 그리드 - 실제 이미지는 object-cover로 크롭 */}
{[1, 2, 3, 4].map((num) => (
{/* 실제 이미지가 들어갈 자리 - object-cover로 중앙 크롭 */} {/* */}
{/* 더미 플레이스홀더 */}
{num}
))}
{/* 라이트박스 모달 */} {lightbox.open && ( {/* 닫기 버튼 */} {/* 이전 버튼 */} {lightbox.images.length > 1 && ( )} {/* 이미지 */} e.stopPropagation()} initial={{ opacity: 0, x: slideDirection * 100 }} animate={{ opacity: 1, x: 0 }} transition={{ duration: 0.25, ease: 'easeOut' }} /> {/* 다음 버튼 */} {lightbox.images.length > 1 && ( )} {/* 인디케이터 */}
{lightbox.images.map((_, i) => (
)}
); } export default AlbumDetail;