import { useSelector } from '@tanstack/react-store'
import { gameStore } from '../hooks/useGameStore'
import { getAvailableItems } from '../utils/shopItems'
export function Shop() {
const isShopOpen = useSelector(gameStore, (s) => s.isShopOpen)
const coinsCollected = useSelector(gameStore, (s) => s.coinsCollected)
const stage = useSelector(gameStore, (s) => s.stage)
const purchasedBoosts = useSelector(gameStore, (s) => s.purchasedBoosts)
const { closeShop, purchaseItem } = gameStore.actions
if (!isShopOpen) return null
const availableItems = getAvailableItems(stage)
return (
Shop
🪙
{coinsCollected}
{availableItems.map((item) => {
const canAfford = coinsCollected >= item.cost
// Get current stack count for stackable items
const stackCount =
item.type === 'permSpeed'
? purchasedBoosts.permSpeed
: item.type === 'permAccel'
? purchasedBoosts.permAccel
: item.type === 'permHealth'
? purchasedBoosts.permHealth
: 0
// Check if already owned (non-stackable)
const alreadyOwned =
item.type === 'rapidFire' && purchasedBoosts.rapidFire
// Check if max stacks reached
const maxStacksReached =
item.stackable &&
item.maxStacks &&
item.maxStacks > 0 &&
stackCount >= item.maxStacks
const canPurchase = canAfford && !alreadyOwned && !maxStacksReached
return (
)
})}
)
}