import React, { Component } from 'react'; import ListItem from '@mui/material/ListItem'; import ListItemAvatar from '@mui/material/ListItemAvatar'; import Avatar from '@mui/material/Avatar'; import Typography from '@mui/material/Typography'; import Box from '@mui/material/Box'; import { Link } from 'react-router-dom'; import AddToCartButton from './AddToCartButton.js'; class CartItem extends Component { componentDidMount() { if (!window.tinyPicCache) { window.tinyPicCache = {}; } if(this.props.item && this.props.item.pictureList && this.props.item.pictureList.split(',').length > 0) { const picid = this.props.item.pictureList.split(',')[0]; if(window.tinyPicCache[picid]){ this.setState({image:window.tinyPicCache[picid],loading:false, error: false}) }else{ this.setState({image: null, loading: true, error: false}); if(this.props.socket){ this.props.socket.emit('getPic', { bildId:picid, size:'tiny' }, (res) => { if(res.success){ window.tinyPicCache[picid] = URL.createObjectURL(new Blob([res.imageBuffer], { type: 'image/jpeg' })); this.setState({image: window.tinyPicCache[picid], loading: false}); } }) } } } } handleIncrement = () => { const { item, onQuantityChange } = this.props; onQuantityChange(item.quantity + 1); }; handleDecrement = () => { const { item, onQuantityChange } = this.props; if (item.quantity > 1) { onQuantityChange(item.quantity - 1); } }; render() { const { item } = this.props; return ( <> {item.name} {new Intl.NumberFormat('de-DE', {style: 'currency', currency: 'EUR'}).format(item.price)} x {item.quantity} {new Intl.NumberFormat('de-DE', {style: 'currency', currency: 'EUR'}).format(item.price * item.quantity)} {/* Weight and VAT display - conditional layout based on weight */} {(item.weight > 0 || item.vat) && ( 0 || (item.versandklasse && item.versandklasse != 'standard' && item.versandklasse != 'kostenlos') ? 'space-between' : 'flex-end', mb: 1 }}> {item.weight > 0 && ( {item.weight.toFixed(1).replace('.',',')} kg )} {item.versandklasse && item.versandklasse != 'standard' && item.versandklasse != 'kostenlos' && ( {item.versandklasse} )} {item.vat && ( inkl. {new Intl.NumberFormat('de-DE', {style: 'currency', currency: 'EUR'}).format( (item.price * item.quantity) - ((item.price * item.quantity) / (1 + item.vat / 100)) )} MwSt. ({item.vat}%) )} )} {this.props.id.toString().endsWith("steckling") ? "Lieferzeit: 14 Tage" : item.available == 1 ? "Lieferzeit: 2-3 Tage" : item.availableSupplier == 1 ? "Lieferzeit: 7-9 Tage" : ""} ); } } export default CartItem;