"use client"; import Image from "next/image"; import { useEffect } from "react"; import { ModalPrices, ModalReviews, ModalScreenshots } from "@/components/game-profile-sections"; import { formatReleaseDate, selectGameView, type ModalDict } from "@/lib/game/game-format"; import { steamdbAppUrl } from "@/lib/game/discord-app"; import type { Locale } from "@/lib/i18n/locales"; import { useGameProfile } from "@/hooks/use-game-profile"; export function GameProfileModal({ applicationId, heroSeed, lang, iconUrl, fallbackName, fallbackGameUrl, dict, onClose, }: { applicationId: string; heroSeed: number; lang: Locale; iconUrl: string | null; fallbackName: string; fallbackGameUrl: string; dict: ModalDict; onClose: () => void; }) { const { profile, failed, localeTag, hero, hasDetails, partialFail, isDeterministicMiss, canRetry, retry, reset, setBannerPick, } = useGameProfile(applicationId, lang, heroSeed); useEffect(() => { function onKey(event: KeyboardEvent): void { if (event.key === "Escape") { onClose(); } } document.addEventListener("keydown", onKey); const previous = document.body.style.overflow; document.body.style.overflow = "hidden"; return () => { document.removeEventListener("keydown", onKey); document.body.style.overflow = previous; }; }, [onClose]); const { gameUrl, name, bestPrice, historyLow, isFree } = selectGameView( profile, fallbackName, fallbackGameUrl, ); return (
event.stopPropagation()} > {hero ? (
) : null}
{iconUrl ? ( ) : (
{name.charAt(0).toUpperCase()}
)}

{name}

{profile && profile.genres.length > 0 ? (
{profile.genres.map((genre) => ( {genre} ))}
) : null}
{!profile && !failed ? (

{dict.loading}

) : null} {failed && !profile ? (

{dict.loadError}

) : null} {isDeterministicMiss ? (

{dict.noGameData}

) : partialFail ? (

{dict.partialFail}

) : null} {profile?.description ? (

{profile.description}

) : null}
{profile?.steamUrl ? ( {dict.openOnSteam} ↗ ) : null} {profile?.steamId ? ( {dict.openOnSteamDb} ↗ ) : null} {profile?.igdbUrl ? ( {dict.openOnIgdb} ↗ ) : null} {dict.openOnDiscord} ↗ {profile?.itad?.pageUrl ? ( {dict.allPrices} ↗ ) : null}
{profile && hasDetails ? (
{profile.developers.length > 0 ? (
{dict.developers}
{profile.developers.join(", ")}
) : null} {profile.publishers.length > 0 ? (
{dict.publishers}
{profile.publishers.join(", ")}
) : null} {profile.releaseDate ? (
{dict.releaseDate}
{formatReleaseDate(profile.releaseDate, localeTag)}
) : null} {profile.platforms.length > 0 ? (
{dict.platforms}
{profile.platforms.join(" · ")}
) : null} {profile.links.length > 0 ? (
{dict.links}
{profile.links.slice(0, 8).map((link) => ( {link.label} ↗ ))}
) : null}
) : null} {profile ? : null} {profile?.itad && (bestPrice || historyLow) ? ( ) : null} {profile && profile.screenshots.length > 0 ? ( ) : null}
); }