import React, { Component } from 'react'; import Grid from '@mui/material/Grid'; import CardMedia from '@mui/material/CardMedia'; import Typography from '@mui/material/Typography'; import Box from '@mui/material/Box'; import Stack from '@mui/material/Stack'; import CircularProgress from '@mui/material/CircularProgress'; import { Link } from 'react-router-dom'; import IconButton from '@mui/material/IconButton'; import ZoomInIcon from '@mui/icons-material/ZoomIn'; class ExtrasSelector extends Component { formatPrice(price) { return new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(price); } // Render product image using working code from GrowTentKonfigurator renderProductImage(product) { if (!window.smallPicCache) { window.smallPicCache = {}; } const pictureList = product.pictureList; if (!pictureList || pictureList.length === 0 || !pictureList.split(',').length) { return ( ); } const bildId = pictureList.split(',')[0]; if (window.smallPicCache[bildId]) { return ( ); } // Load image if not cached if (!this.loadingImages) this.loadingImages = new Set(); if (!this.loadingImages.has(bildId)) { this.loadingImages.add(bildId); window.socketManager.emit('getPic', { bildId, size:'small' }, (res) => { if (res.success) { window.smallPicCache[bildId] = URL.createObjectURL(new Blob([res.imageBuffer], { type: 'image/jpeg' })); this.forceUpdate(); } this.loadingImages.delete(bildId); }); } return ( ); } renderExtraCard(extra) { const { selectedExtras, onExtraToggle, showImage = true } = this.props; const isSelected = selectedExtras.includes(extra.id); return ( onExtraToggle(extra.id)}> {/* Image */} {showImage && ( {this.renderProductImage(extra)} )} {/* Content */} {/* Name */} {extra.name} {extra.kurzBeschreibung} {/* Price with VAT - Same as other sections */} {extra.price ? this.formatPrice(extra.price) : 'Kein Preis'} {extra.vat && ( (incl. {extra.vat}% MwSt.,*) )} {/* Selection Indicator - Separate line */} {isSelected && ( ✓ Ausgewählt )} event.stopPropagation()} > ); } render() { const { extras, title, subtitle, gridSize = { xs: 12, sm: 6, md: 4 } } = this.props; if (!extras || !Array.isArray(extras)) { return ( {title} Keine Extras verfügbar ); } return ( {title} {subtitle && ( {subtitle} )} {extras.map(extra => ( {this.renderExtraCard(extra)} ))} ); } } export default ExtrasSelector;