import { motion } from 'framer-motion'; import { useState, useMemo, useRef, useEffect } from 'react'; import { Instagram, Calendar } from 'lucide-react'; import { Swiper, SwiperSlide } from 'swiper/react'; import 'swiper/css'; import { useMembers } from '@/hooks'; /** * Mobile 멤버 페이지 - 카드 스와이프 스타일 */ function MobileMembers() { const [currentIndex, setCurrentIndex] = useState(0); const swiperRef = useRef(null); const indicatorRef = useRef(null); // 멤버 데이터 로드 const { data: allMembers = [] } = useMembers(); // 현재/전 멤버 정렬 (현재 멤버 먼저, 전 멤버 나중) const members = useMemo(() => { return [...allMembers].sort((a, b) => { if (a.is_former !== b.is_former) { return a.is_former ? 1 : -1; } return 0; }); }, [allMembers]); // 나이 계산 const calculateAge = (birthDate) => { if (!birthDate) return null; const birth = new Date(birthDate); const today = new Date(); let age = today.getFullYear() - birth.getFullYear(); const monthDiff = today.getMonth() - birth.getMonth(); if ( monthDiff < 0 || (monthDiff === 0 && today.getDate() < birth.getDate()) ) { age--; } return age; }; // 인디케이터 자동 스크롤 useEffect(() => { if (indicatorRef.current && members.length > 0) { const container = indicatorRef.current; const itemWidth = 64; // 52px 썸네일 + 12px 간격 const containerWidth = container.offsetWidth; const paddingLeft = 16; // px-4 const targetScroll = paddingLeft + currentIndex * itemWidth + 26 - containerWidth / 2; container.scrollTo({ left: Math.max(0, targetScroll), behavior: 'smooth', }); } }, [currentIndex, members.length]); // 인디케이터 클릭 핸들러 const handleIndicatorClick = (index) => { if (swiperRef.current) { swiperRef.current.slideTo(index); } }; if (members.length === 0) { return (
멤버 정보가 없습니다