import React from "react"; import * as Styled from "./index.styled"; interface Props { currentTry: number; date: string; } const MV_CDN_URL = import.meta.env.VITE_CDN_URL || ""; function getRevealedCount(currentTry: number): number { if (currentTry >= 5) return 3; if (currentTry >= 2) return 2; return 1; } export function MVPlayer({ currentTry, date }: Props) { const revealed = getRevealedCount(currentTry); const [errored, setErrored] = React.useState>(new Set()); const [activeImage, setActiveImage] = React.useState(null); const markError = React.useCallback((index: number) => { setErrored((prev) => { const next = new Set(prev); next.add(index); return next; }); }, []); React.useEffect(() => { setErrored(new Set()); setActiveImage(null); }, [date]); return ( {Array.from({ length: 3 }, (_, i) => { const index = i + 1; const isRevealed = index <= revealed; const src = `${MV_CDN_URL}/k-heardle-mvs/${date}/${index}.jpg`; const hasError = errored.has(index); return ( {isRevealed && !hasError ? ( {`MV markError(index)} onClick={() => setActiveImage(src)} style={{ cursor: "zoom-in" }} /> ) : isRevealed && hasError ? ( Frame {index} not available yet. ) : ( ? )} ); })} {revealed < 3 ? `More frames unlock as you guess. (${revealed}/3 revealed)` : "All frames revealed."} {activeImage && ( setActiveImage(null)}> e.stopPropagation()} /> )} ); }