import { useGame } from "../../context/GameContext.js"; const formatTimeUntilReset = (): string => { const now = new Date(); // Mirror the server's PST/PDT-based rollover: challenges reset at PST midnight const nowAsPST = new Date(now.toLocaleString("en-US", { timeZone: "America/Los_Angeles" })); const tomorrowMidnightPST = new Date(nowAsPST); tomorrowMidnightPST.setDate(tomorrowMidnightPST.getDate() + 1); tomorrowMidnightPST.setHours(0, 0, 0, 0); const pstOffset = nowAsPST.getTime() - now.getTime(); const resetAt = new Date(tomorrowMidnightPST.getTime() - pstOffset); const msRemaining = resetAt.getTime() - now.getTime(); const hoursRemaining = Math.floor(msRemaining / (1000 * 60 * 60)); const minutesRemaining = Math.floor((msRemaining % (1000 * 60 * 60)) / (1000 * 60)); return `${String(hoursRemaining)}h ${String(minutesRemaining)}m`; }; export const DailyChallengePanel = (): React.JSX.Element => { const { state, formatNumber } = useGame(); if (!state) return

Loading...

; const { dailyChallenges } = state; if (!dailyChallenges) { return (

📅 Daily Challenges

Load the game to generate today's challenges!

); } const completedCount = dailyChallenges.challenges.filter((c) => c.completed).length; return (

📅 Daily Challenges

Complete challenges for bonus 💎 crystals! Resets in{" "} {formatTimeUntilReset()} (PST midnight).

{completedCount} / {dailyChallenges.challenges.length} completed

{dailyChallenges.challenges.map((challenge) => { const progressPercent = Math.min( 100, Math.floor((challenge.progress / challenge.target) * 100), ); return (

{challenge.label}

Reward: 💎 {formatNumber(challenge.rewardCrystals)} crystals

{challenge.completed ? ( ✅ Complete! ) : ( <>

{formatNumber(challenge.progress)} / {formatNumber(challenge.target)}

)}
); })}
); };