'use client'; import { Link } from '@/i18n/navigation'; import { Box, Grid, Heading, Text, VStack, Badge, Flex, Image as ChakraImage, SimpleGrid } from '@chakra-ui/react'; import { useState } from 'react'; import { format, startOfMonth, endOfMonth, eachDayOfInterval, isSameMonth, isSameDay, addMonths, subMonths, getDay } from 'date-fns'; import { enUS, tr } from 'date-fns/locale'; import { useLocale } from 'next-intl'; import { FaChevronLeft, FaChevronRight } from 'react-icons/fa'; import { IconButton } from '@chakra-ui/react'; import { FilterBar, FilterState } from './filter-bar'; // import { Game, Event } from '@prisma/client'; // Removed dependency // Note: In a real monorepo we'd share types. For now we will mock or use any. interface CalendarProps { games: any[]; // Replace with correct type events: any[]; } export function GameCalendar({ games = [], events = [] }: CalendarProps) { const [currentDate, setCurrentDate] = useState(new Date()); const [filters, setFilters] = useState({ search: '', platforms: ['PC', 'PS5', 'Xbox', 'Switch'], showEvents: true }); const locale = useLocale(); const dateLocale = locale === 'tr' ? tr : enUS; const monthStart = startOfMonth(currentDate); const monthEnd = endOfMonth(monthStart); const daysInMonth = eachDayOfInterval({ start: monthStart, end: monthEnd }); // Add padding days for start of month const startDayOfWeek = getDay(monthStart); // 0 (Sun) to 6 (Sat) // Adjust for Monday start if needed. Let's assume standard Sunday start for grid. const paddingDays = Array.from({ length: startDayOfWeek }); const nextMonth = () => setCurrentDate(addMonths(currentDate, 1)); const prevMonth = () => setCurrentDate(subMonths(currentDate, 1)); const getItemsForDay = (date: Date) => { // Filter Games const dayGames = games.filter(g => { if (!g.releaseDate || !isSameDay(new Date(g.releaseDate), date)) return false; // Search filter if (filters.search && !g.title.toLowerCase().includes(filters.search.toLowerCase())) return false; // Platform filter (if game has platforms) if (g.platforms && g.platforms.length > 0) { const hasPlatform = g.platforms.some((p: string) => filters.platforms.includes(p) || filters.platforms.some(fp => p.includes(fp))); if (!hasPlatform) return false; } return true; }); // Filter Events const dayEvents = filters.showEvents ? events.filter(e => { if (!isSameDay(new Date(e.startTime), date)) return false; if (filters.search && !e.title.toLowerCase().includes(filters.search.toLowerCase())) return false; return true; }) : []; return [...dayGames.map(g => ({ ...g, type: 'game' })), ...dayEvents.map(e => ({ ...e, type: 'event' }))]; }; return ( {/* Header */} {format(currentDate, 'MMMM yyyy', { locale: dateLocale })} {/* Filters */} {/* Days Header */} {['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'].map(day => ( {day} ))} {/* Calendar Grid */} {paddingDays.map((_, i) => ( ))} {daysInMonth.map((date) => { const items = getItemsForDay(date); const isToday = isSameDay(date, new Date()); return ( {format(date, 'd')} {items.map((item: any, idx) => { const badge = ( {item.title} ); if (item.type === 'game') { return ( {badge} ); } return badge; })} {/* Background image effect for heavy days? Optional polish */} ); })} ); }