'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { Box, Container, TextField, Select, MenuItem, FormControl, InputLabel, Card, CardContent, Typography, InputAdornment, Pagination, Grid, LinearProgress, Chip, } from '@mui/material'; import { Search, FilterList, Event, TrendingUp, People, CardGiftcard, Phone, Share, ShoppingCart, Email, LocalFireDepartment, NewReleases, Warning, Star, } from '@mui/icons-material'; import Header from '@/shared/ui/Header'; import { cardStyles, colors, responsiveText } from '@/shared/lib/button-styles'; // Mock 데이터 const mockEvents = [ { id: '1', title: '신규고객 유치 이벤트', status: 'active' as const, daysLeft: 5, participants: 128, targetParticipants: 200, roi: 450, startDate: '2025-11-01', endDate: '2025-11-15', prize: '커피 쿠폰', method: '전화번호 입력', isUrgent: true, isPopular: false, isHighROI: true, isNew: false, }, { id: '2', title: '재방문 유도 이벤트', status: 'active' as const, daysLeft: 12, participants: 56, targetParticipants: 100, roi: 320, startDate: '2025-11-05', endDate: '2025-11-20', prize: '할인 쿠폰', method: 'SNS 팔로우', isUrgent: false, isPopular: false, isHighROI: false, isNew: false, }, { id: '3', title: '매출증대 프로모션', status: 'ended' as const, daysLeft: 0, participants: 234, targetParticipants: 150, roi: 580, startDate: '2025-10-15', endDate: '2025-10-31', prize: '상품권', method: '구매 인증', isUrgent: false, isPopular: true, isHighROI: true, isNew: false, }, { id: '4', title: '봄맞이 특별 이벤트', status: 'scheduled' as const, daysLeft: 30, participants: 0, targetParticipants: 300, roi: 0, startDate: '2025-12-01', endDate: '2025-12-15', prize: '체험권', method: '이메일 등록', isUrgent: false, isPopular: false, isHighROI: false, isNew: true, }, ]; type EventStatus = 'all' | 'active' | 'scheduled' | 'ended'; type Period = '1month' | '3months' | '6months' | '1year' | 'all'; type SortBy = 'latest' | 'participants' | 'roi'; export default function EventsPage() { const router = useRouter(); const [searchTerm, setSearchTerm] = useState(''); const [statusFilter, setStatusFilter] = useState('all'); const [periodFilter, setPeriodFilter] = useState('1month'); const [sortBy, setSortBy] = useState('latest'); const [currentPage, setCurrentPage] = useState(1); const itemsPerPage = 20; // 필터링 및 정렬 const filteredEvents = mockEvents .filter((event) => { const matchesSearch = event.title.toLowerCase().includes(searchTerm.toLowerCase()); const matchesStatus = statusFilter === 'all' || event.status === statusFilter; return matchesSearch && matchesStatus; }) .sort((a, b) => { if (sortBy === 'latest') { return new Date(b.startDate).getTime() - new Date(a.startDate).getTime(); } else if (sortBy === 'participants') { return b.participants - a.participants; } else if (sortBy === 'roi') { return b.roi - a.roi; } return 0; }); // 페이지네이션 const totalPages = Math.ceil(filteredEvents.length / itemsPerPage); const startIndex = (currentPage - 1) * itemsPerPage; const endIndex = Math.min(startIndex + itemsPerPage, filteredEvents.length); const pageEvents = filteredEvents.slice(startIndex, endIndex); const handleEventClick = (eventId: string) => { router.push(`/events/${eventId}`); }; const getStatusStyle = (status: string) => { switch (status) { case 'active': return { bgcolor: colors.mint, color: 'white', }; case 'scheduled': return { bgcolor: colors.blue, color: 'white', }; case 'ended': return { bgcolor: colors.gray[300], color: colors.gray[700], }; default: return { bgcolor: colors.gray[200], color: colors.gray[600], }; } }; const getStatusText = (status: string) => { switch (status) { case 'active': return '진행중'; case 'scheduled': return '예정'; case 'ended': return '종료'; default: return status; } }; const getMethodIcon = (method: string) => { switch (method) { case '전화번호 입력': return ; case 'SNS 팔로우': return ; case '구매 인증': return ; case '이메일 등록': return ; default: return ; } }; const calculateProgress = (event: (typeof mockEvents)[0]) => { if (event.status !== 'active') return 0; const total = new Date(event.endDate).getTime() - new Date(event.startDate).getTime(); const elapsed = Date.now() - new Date(event.startDate).getTime(); return Math.min(Math.max((elapsed / total) * 100, 0), 100); }; // 통계 계산 const stats = { total: mockEvents.length, active: mockEvents.filter((e) => e.status === 'active').length, totalParticipants: mockEvents.reduce((sum, e) => sum + e.participants, 0), avgROI: Math.round( mockEvents.filter((e) => e.roi > 0).reduce((sum, e) => sum + e.roi, 0) / mockEvents.filter((e) => e.roi > 0).length ), }; return ( <>
{/* Summary Statistics */} {stats.total} 전체 이벤트 {stats.active} 진행중 {stats.totalParticipants} 총 참여자 {stats.avgROI}% 평균 ROI {/* Search Section */} setSearchTerm(e.target.value)} InputProps={{ startAdornment: ( ), }} sx={{ '& .MuiOutlinedInput-root': { borderRadius: 3, bgcolor: 'white', fontSize: { xs: '0.875rem', sm: '1rem' }, '& fieldset': { borderColor: colors.gray[200], }, '&:hover fieldset': { borderColor: colors.gray[300], }, '&.Mui-focused fieldset': { borderColor: colors.purple, }, }, }} /> {/* Filters */} 상태 기간 {/* Sorting */} 정렬 {/* Event List */} {pageEvents.length === 0 ? ( event_busy 검색 결과가 없습니다 다른 검색 조건으로 다시 시도해보세요 ) : ( {pageEvents.map((event) => ( handleEventClick(event.id)} > {/* Header with Badges */} {event.title} {getStatusText(event.status)} {event.status === 'active' ? ` | D-${event.daysLeft}` : event.status === 'scheduled' ? ` | D+${event.daysLeft}` : ''} {/* Status Badges */} {event.isUrgent && ( } label="마감임박" size="small" sx={{ bgcolor: '#FEF3C7', color: '#92400E', fontWeight: 600, fontSize: { xs: '0.6875rem', sm: '0.75rem' }, height: { xs: 24, sm: 28 }, '& .MuiChip-icon': { color: '#92400E' }, }} /> )} {event.isPopular && ( } label="인기" size="small" sx={{ bgcolor: '#FEE2E2', color: '#991B1B', fontWeight: 600, fontSize: { xs: '0.6875rem', sm: '0.75rem' }, height: { xs: 24, sm: 28 }, '& .MuiChip-icon': { color: '#991B1B' }, }} /> )} {event.isHighROI && ( } label="높은 ROI" size="small" sx={{ bgcolor: '#DCFCE7', color: '#166534', fontWeight: 600, fontSize: { xs: '0.6875rem', sm: '0.75rem' }, height: { xs: 24, sm: 28 }, '& .MuiChip-icon': { color: '#166534' }, }} /> )} {event.isNew && ( } label="신규" size="small" sx={{ bgcolor: '#DBEAFE', color: '#1E40AF', fontWeight: 600, fontSize: { xs: '0.6875rem', sm: '0.75rem' }, height: { xs: 24, sm: 28 }, '& .MuiChip-icon': { color: '#1E40AF' }, }} /> )} {/* Progress Bar for Active Events */} {event.status === 'active' && ( 이벤트 진행률 {Math.round(calculateProgress(event))}% )} {/* Event Info and Stats Container */} {/* Left: Event Info */} {event.prize} {getMethodIcon(event.method)} {event.method} {/* Date */} 📅 {event.startDate} ~ {event.endDate} {/* Right: Stats */} 참여자 {event.participants.toLocaleString()} {event.targetParticipants > 0 && ( 목표: {event.targetParticipants}명 ( {Math.round((event.participants / event.targetParticipants) * 100)} %) )} ROI = 400 ? colors.mint : event.roi >= 200 ? colors.orange : colors.gray[500], }} > {event.roi}% ))} )} {/* Pagination */} {totalPages > 1 && ( setCurrentPage(page)} size="large" sx={{ '& .MuiPaginationItem-root': { color: colors.gray[700], fontWeight: 600, '&.Mui-selected': { background: `linear-gradient(135deg, ${colors.purple} 0%, ${colors.blue} 100%)`, color: 'white', '&:hover': { background: `linear-gradient(135deg, ${colors.purpleLight} 0%, ${colors.blueLight} 100%)`, }, }, '&:hover': { bgcolor: colors.gray[100], }, }, }} /> )} ); }