| [8a7f936] | 1 | import React, {useEffect, useState} from 'react';
|
|---|
| 2 | import {Card, CardContent, CardMedia, Typography, Box, Chip} from '@mui/material';
|
|---|
| [1bf6e1f] | 3 | import StarIcon from '@mui/icons-material/Star';
|
|---|
| [8a7f936] | 4 | import {onGetBuildDetails} from "../pages/+Layout.telefunc";
|
|---|
| [1bf6e1f] | 5 |
|
|---|
| [8a7f936] | 6 | export default function BuildCard({build, onClick}: { build: any, onClick?: () => void }) {
|
|---|
| 7 | const [caseImage, setCaseImage] = useState<string>("https://placehold.co/600x400?text=PC+Build");
|
|---|
| 8 | const [imageLoading, setImageLoading] = useState(true);
|
|---|
| 9 |
|
|---|
| 10 | const formattedPrice = new Intl.NumberFormat('en-US', {
|
|---|
| 11 | style: 'currency',
|
|---|
| 12 | currency: 'EUR'
|
|---|
| 13 | }).format(build.total_price || 0);
|
|---|
| 14 |
|
|---|
| 15 | useEffect(() => {
|
|---|
| 16 | onGetBuildDetails({buildId: build.id})
|
|---|
| 17 | .then(details => {
|
|---|
| 18 | const caseComponent = details.components.find((c: any) => c.type === 'case');
|
|---|
| 19 | setCaseImage(caseComponent?.imgUrl || caseComponent?.imgUrl || "https://placehold.co/600x400?text=PC+Build");
|
|---|
| 20 | })
|
|---|
| 21 | .catch(() => {
|
|---|
| 22 | })
|
|---|
| 23 | .finally(() => setImageLoading(false));
|
|---|
| 24 | }, [build.id]);
|
|---|
| [1bf6e1f] | 25 |
|
|---|
| 26 | return (
|
|---|
| 27 | <Card
|
|---|
| 28 | onClick={onClick}
|
|---|
| [8a7f936] | 29 | sx={{
|
|---|
| 30 | width: '100%',
|
|---|
| 31 | height: '100%',
|
|---|
| 32 | display: 'flex',
|
|---|
| 33 | flexDirection: 'column',
|
|---|
| 34 | cursor: onClick ? 'pointer' : 'default',
|
|---|
| 35 | transition: 'transform 0.2s, box-shadow 0.2s',
|
|---|
| 36 | '&:hover': onClick ? {
|
|---|
| 37 | transform: 'translateY(-4px)',
|
|---|
| 38 | boxShadow: 6
|
|---|
| 39 | } : {},
|
|---|
| 40 | position: 'relative'
|
|---|
| 41 | }}
|
|---|
| [1bf6e1f] | 42 | >
|
|---|
| [8a7f936] | 43 | <Box sx={{position: 'relative', paddingTop: '75%'}}>
|
|---|
| 44 | <CardMedia
|
|---|
| 45 | component="img"
|
|---|
| 46 | image={caseImage || '/placeholder-pc.png'}
|
|---|
| 47 | alt={build.name}
|
|---|
| 48 | sx={{
|
|---|
| 49 | position: 'absolute',
|
|---|
| 50 | top: 0,
|
|---|
| 51 | left: 0,
|
|---|
| 52 | width: '100%',
|
|---|
| 53 | height: '100%',
|
|---|
| 54 | objectFit: 'contain',
|
|---|
| 55 | p: 2,
|
|---|
| 56 | bgcolor: '#f5f5f5'
|
|---|
| 57 | }}
|
|---|
| 58 | />
|
|---|
| 59 | </Box>
|
|---|
| [1bf6e1f] | 60 |
|
|---|
| [8a7f936] | 61 | <CardContent sx={{flexGrow: 1, display: 'flex', flexDirection: 'column', justifyContent: 'space-between'}}>
|
|---|
| 62 | <Box sx={{mb: 2}}>
|
|---|
| 63 | <Typography variant="h6" component="div" fontWeight="bold" wrap title={build.name}>
|
|---|
| 64 | {build.name}
|
|---|
| 65 | </Typography>
|
|---|
| [1bf6e1f] | 66 | </Box>
|
|---|
| 67 |
|
|---|
| [8a7f936] | 68 | <Box sx={{display: 'flex', justifyContent: 'space-between', alignItems: 'center', mt: 'auto'}}>
|
|---|
| 69 | <Chip
|
|---|
| 70 | label={formattedPrice}
|
|---|
| 71 | color="primary"
|
|---|
| 72 | variant="outlined"
|
|---|
| 73 | size="small"
|
|---|
| 74 | sx={{fontWeight: 'bold'}}
|
|---|
| 75 | />
|
|---|
| 76 | <Box sx={{display: 'flex', alignItems: 'center'}}>
|
|---|
| 77 | <StarIcon sx={{color: '#faaf00', fontSize: 20, mr: 0.5}}/>
|
|---|
| [1bf6e1f] | 78 | <Typography variant="body2" fontWeight="bold">
|
|---|
| [e599341] | 79 | {Number(build.avgRating || 5).toFixed(1)}
|
|---|
| [1bf6e1f] | 80 | </Typography>
|
|---|
| 81 | </Box>
|
|---|
| 82 | </Box>
|
|---|
| 83 | </CardContent>
|
|---|
| 84 | </Card>
|
|---|
| 85 | );
|
|---|
| [8a7f936] | 86 | }
|
|---|