import { forwardRef, MutableRefObject, useEffect, useState } from "react"; import Image from "next/image"; import { Pie, Bar } from "react-chartjs-2"; import { Chart as ChartJS, ArcElement, Tooltip, Legend, CategoryScale, LinearScale, BarElement } from "chart.js"; ChartJS.register(ArcElement, Tooltip, Legend, CategoryScale, LinearScale, BarElement); import ClientOnlyPortal from "./ClientOnlyPortal"; interface ModalProps { modalOpen: boolean toggleModal: Function card: any } const Modal = forwardRef(({modalOpen, toggleModal, card}, ref) => { const [randomQuote, setRandomQuote] = useState(""); const barData = { labels: ["USD", "USD Foil", "USD Etched", "Euro", "Euro Foil", "Tix"], datasets: [ { label: "Card Prices", data: [ card.prices?.usd, card.prices?.usd_foil, card.prices?.usd_etched, card.prices?.eur, card.prices?.eur_foil, card.prices?.tix ], backgroundColor: [ "rgb(0,33,71)", "rgb(0,33,71)", "rgb(255, 221, 0)", "rgb(255, 221, 0)", "rgb(255, 221, 0)", "rgb(255, 255, 255)", ], } ] }; const pieData = { labels: ["Power", "Toughness"], datasets: [ { label: "Card Power and Toughness", data: [card.power, card.toughness], backgroundColor: [ "rgb(200, 16, 46)", "rgb(0, 33, 71)" ], borderColor: [ "rgba(200, 16, 46, 0.2)", "rgba(0, 33, 71, 0.2)" ] }, ] }; useEffect(() => { !card.flavor_text ? fetch('https://api.quotable.io/random').then( res => res.json() ).then( quote => setRandomQuote(`${quote.content} — ${quote.author}`)) : null; if( (ref as MutableRefObject).current ) { (ref as MutableRefObject).current.scrollTo(0, 0); } }, [card]); return (
<>

{card.flavor_text || randomQuote}

{card && ( {`${card.name} )}

{card?.name}

{card.oracle_text}

null, }, }, }} />

Prices

); }); export default Modal;