"use client"; import { useCallback, useEffect, useState } from "react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { HABIT_PET_DATA_UPDATED_EVENT } from "@/lib/app-events"; import { getCoins } from "@/lib/avatar-progression-storage"; const shopItems = [ { id: "hat", name: "Pixel cap", price: 50, description: "A cozy cap for your habit pet.", }, { id: "bed", name: "Cloud bed", price: 120, description: "Boost recovery after tough days.", }, { id: "snack", name: "Berry snack", price: 25, description: "A small treat for good streaks.", }, ]; export function ShopContent() { const [coins, setCoins] = useState(null); const [error, setError] = useState(null); const refreshCoins = useCallback(async () => { try { setError(null); setCoins(await getCoins()); } catch (refreshError) { setError( refreshError instanceof Error ? refreshError.message : "Could not load your balance.", ); setCoins(0); } }, []); useEffect(() => { void refreshCoins(); window.addEventListener(HABIT_PET_DATA_UPDATED_EVENT, refreshCoins); return () => { window.removeEventListener(HABIT_PET_DATA_UPDATED_EVENT, refreshCoins); }; }, [refreshCoins]); return ( <>
Your balance {coins === null ? "..." : `${coins} points`}
{error ?

{error}

: null}
{shopItems.map((item) => { const canAfford = coins !== null && coins >= item.price; return (
{item.name} {item.description}
{item.price} pts
); })}
); }