import React, { Component } from 'react';
import Grid from '@mui/material/Grid';
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import CardMedia from '@mui/material/CardMedia';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
import Checkbox from '@mui/material/Checkbox';
import FormControlLabel from '@mui/material/FormControlLabel';
class ExtrasSelector extends Component {
formatPrice(price) {
return new Intl.NumberFormat('de-DE', {
style: 'currency',
currency: 'EUR'
}).format(price);
}
renderExtraCard(extra) {
const { selectedExtras, onExtraToggle, showImage = true } = this.props;
const isSelected = selectedExtras.includes(extra.id);
return (
onExtraToggle(extra.id)}
>
{showImage && (
)}
{
e.stopPropagation();
onExtraToggle(extra.id);
}}
sx={{
color: '#2e7d32',
'&.Mui-checked': { color: '#2e7d32' },
padding: 0
}}
/>
}
label=""
sx={{ margin: 0 }}
onClick={(e) => e.stopPropagation()}
/>
{this.formatPrice(extra.price)}
{extra.name}
{extra.description}
{isSelected && (
✓ Hinzugefügt
)}
);
}
render() {
const { extras, title, subtitle, groupByCategory = true, gridSize = { xs: 12, sm: 6, md: 4 } } = this.props;
if (groupByCategory) {
// Group extras by category
const groupedExtras = extras.reduce((acc, extra) => {
if (!acc[extra.category]) {
acc[extra.category] = [];
}
acc[extra.category].push(extra);
return acc;
}, {});
return (
{title}
{subtitle && (
{subtitle}
)}
{Object.entries(groupedExtras).map(([category, categoryExtras]) => (
{category}
{categoryExtras.map(extra => (
{this.renderExtraCard(extra)}
))}
))}
);
}
// Render without category grouping
return (
{title}
{subtitle && (
{subtitle}
)}
{extras.map(extra => (
{this.renderExtraCard(extra)}
))}
);
}
}
export default ExtrasSelector;