'use client';
import { Box, Container, Heading, Text, Image, Badge, Flex, Grid, GridItem, Button, Icon, Stack, Tag, TagLabel, AspectRatio } from '@chakra-ui/react';
import { Game, gamesApi } from '@/lib/api/games';
import { notificationsApi } from '@/lib/api/notifications';
import { useEffect, useState } from 'react';
import { FaPlaystation, FaXbox, FaDesktop, FaGamepad, FaStar, FaBuilding, FaCalendar, FaSync, FaBell } from 'react-icons/fa'; // Assuming react-icons is installed, or use lucid-react if available in project
import { useQuery } from '@tanstack/react-query'; // Assuming react-query is used
import { toaster } from '@/components/ui/feedback/toaster'; // Updated path
// Import UI components (assuming they exist or use basic Chakra)
// I will use basic Chakra v3 components. For icons, I'll fallback to text if icons missing or Import from react-icons if available.
// The prompted file said Chakra UI v3.
interface GameDetailProps {
slug: string;
}
export function GameDetail({ slug }: GameDetailProps) {
const { data: response, isLoading, error, refetch } = useQuery({
queryKey: ['game', slug],
queryFn: () => gamesApi.getBySlug(slug),
});
useEffect(() => {
console.log('GameDetail mounted for slug:', slug);
}, [slug]);
const [isSyncing, setIsSyncing] = useState(false);
const [isSubscribing, setIsSubscribing] = useState(false);
const handleSync = async () => {
setIsSyncing(true);
try {
await gamesApi.sync(slug);
toaster.create({ title: 'Game synced successfully', type: 'success' });
refetch();
} catch (e) {
toaster.create({ title: 'Failed to sync game', type: 'error' });
} finally {
setIsSyncing(false);
}
};
const handleSubscribe = async () => {
setIsSubscribing(true);
try {
if (!game?.id) return;
await notificationsApi.subscribe(game.id);
toaster.create({ title: 'Subscribed to alerts!', type: 'success' });
} catch (e: any) {
// Handle "Already subscribed" specifically if possible, else generic error
const msg = e.response?.data?.message || 'Failed to subscribe';
toaster.create({ title: msg, type: msg.includes('Already') ? 'info' : 'error' });
} finally {
setIsSubscribing(false);
}
};
if (isLoading) return Loading...;
if (error || !response?.data?.data) return (
Game not found
);
const game = response.data.data;
return (
{/* Hero Section */}
{/* Background Blur */}
{game.title}
{game.rating && (
{Math.round(game.rating).toFixed(1)}
)}
{game.releaseDate && (
{new Date(game.releaseDate).toLocaleDateString()}
)}
{game.platforms?.map(p => (
{p.platform.name}
))}
{game.genres?.map(g => (
{g.genre.name}
))}
{/* Content Section */}
About
{game.description || "No description available."}
{game.screenshots && game.screenshots.length > 0 && (
Gallery
{game.screenshots.map((shot, idx) => (
))}
)}
Information
Developer
{game.developer || "Unknown"}
Publisher
{game.publisher || "Unknown"}
Release Date
{game.releaseDate ? new Date(game.releaseDate).toLocaleDateString(undefined, { dateStyle: 'long' }) : 'TBD'}
);
}