'use client'; import React from 'react'; import { Box, Grid, Text, Button, Image, VStack, useToast, useColorModeValue, } from '@chakra-ui/react'; import { InventoryItem } from '../types/user'; interface ShopItem extends InventoryItem { price: number; } interface ShopProps { items: ShopItem[]; userBalance: number; onPurchase: (itemId: string) => Promise; } export const Shop: React.FC = ({ items, userBalance, onPurchase }) => { const toast = useToast(); const bgColor = useColorModeValue('white', 'gray.800'); const borderColor = useColorModeValue('gray.200', 'gray.700'); const handlePurchase = async (item: ShopItem) => { if (userBalance < item.price) { toast({ title: 'Недостаточно средств', description: 'У вас недостаточно Campfire монет для покупки этого предмета', status: 'error', duration: 3000, isClosable: true, }); return; } try { await onPurchase(item.id); toast({ title: 'Покупка успешна!', description: `Вы приобрели ${item.name}`, status: 'success', duration: 3000, isClosable: true, }); } catch (error) { toast({ title: 'Ошибка при покупке', description: 'Произошла ошибка при совершении покупки', status: 'error', duration: 3000, isClosable: true, }); } }; return ( Магазин Ваш баланс: {userBalance} 🔥 {items.map((item) => ( {item.imageUrl && ( {item.name} )} {item.name} {item.description} {item.price} 🔥 ))} ); };