"use client"; import { GameListRep, getGameDetailApi } from "@/api/home"; import { useRouter } from "@/i18n"; import { useGlobalStore } from "@/stores"; import { Button, Modal, ModalBody, ModalContent, useDisclosure } from "@nextui-org/react"; import { useTranslations } from "next-intl"; import { FC, PropsWithChildren, ReactNode, useRef } from "react"; import styles from "./style.module.scss"; export interface CardProps { item?: GameListRep; render?: (value: GameListRep) => ReactNode; } const Card: FC> = (props) => { const { render, item } = props; const { isOpen, onOpen, onOpenChange } = useDisclosure(); const app: HTMLElement = document.querySelector("#app")!; const t = useTranslations("Game"); const urlRef = useRef(""); const state = useGlobalStore(); const router = useRouter(); const handler = (game: GameListRep) => { onOpen(); const params = { id: game.id, }; getGameDetailApi(params).then((res) => { urlRef.current = res.data.game_url; }); }; const playGameHandler = () => { const { token } = state; if (token) { window.open(urlRef.current); } else { router.push("/login"); } }; return ( <> {render ? ( render(item!) ) : (
handler(item!)}> {item?.game_name_cn}
)} {(onClose) => ( <>
{item?.game_name_cn}

{item?.game_name_cn}

)}
); }; export default Card;