import React, { Component } from 'react'; import Box from '@mui/material/Box'; import List from '@mui/material/List'; import Typography from '@mui/material/Typography'; import Button from '@mui/material/Button'; import Table from '@mui/material/Table'; import TableBody from '@mui/material/TableBody'; import TableCell from '@mui/material/TableCell'; import TableRow from '@mui/material/TableRow'; import CartItem from './CartItem.js'; class CartDropdown extends Component { render() { const { cartItems = [], onClose, onCheckout, showDetailedSummary = false, deliveryMethod = '', deliveryCost = 0 } = this.props; // Calculate the total weight of all items in the cart const totalWeight = cartItems.reduce((sum, item) => { const weightPerItem = item.weight || 0; const quantity = item.quantity || 1; return sum + weightPerItem * quantity; }, 0); // Calculate price breakdowns const priceCalculations = cartItems.reduce((acc, item) => { const totalItemPrice = item.price * item.quantity; const netPrice = totalItemPrice / (1 + item.vat / 100); const vatAmount = totalItemPrice - netPrice; acc.totalGross += totalItemPrice; acc.totalNet += netPrice; if (item.vat === 7) { acc.vat7 += vatAmount; } else if (item.vat === 19) { acc.vat19 += vatAmount; } return acc; }, { totalGross: 0, totalNet: 0, vat7: 0, vat19: 0 }); // Calculate detailed summary with shipping (similar to OrderSummary) const currencyFormatter = new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }); const shippingNetPrice = deliveryCost / (1 + 19 / 100); const shippingVat = deliveryCost - shippingNetPrice; const totalVat7 = priceCalculations.vat7; const totalVat19 = priceCalculations.vat19 + shippingVat; const totalGross = priceCalculations.totalGross + deliveryCost; return ( <> {cartItems.length} {cartItems.length === 1 ? 'Produkt' : 'Produkte'} { cartItems && ( <> {cartItems.map((item) => ( ))} {/* Display total weight if greater than 0 */} {totalWeight > 0 && ( Gesamtgewicht: {totalWeight.toFixed(2)} kg )} {/* Price breakdown table */} {cartItems.length > 0 && ( {showDetailedSummary ? ( // Detailed summary with shipping costs <> Bestellübersicht {deliveryMethod && ( Versandart: {deliveryMethod} )} Waren (netto): {currencyFormatter.format(priceCalculations.totalNet)} {deliveryCost > 0 && ( Versandkosten (netto): {currencyFormatter.format(shippingNetPrice)} )} {totalVat7 > 0 && ( 7% Mehrwertsteuer: {currencyFormatter.format(totalVat7)} )} {totalVat19 > 0 && ( 19% Mehrwertsteuer (inkl. Versand): {currencyFormatter.format(totalVat19)} )} Gesamtsumme Waren: {currencyFormatter.format(priceCalculations.totalGross)} {deliveryCost > 0 && ( Versandkosten: {currencyFormatter.format(deliveryCost)} )} Gesamtsumme: {currencyFormatter.format(totalGross)}
) : ( // Simple summary without shipping costs Gesamtnettopreis: {new Intl.NumberFormat('de-DE', {style: 'currency', currency: 'EUR'}).format(priceCalculations.totalNet)} {priceCalculations.vat7 > 0 && ( 7% Mehrwertsteuer: {new Intl.NumberFormat('de-DE', {style: 'currency', currency: 'EUR'}).format(priceCalculations.vat7)} )} {priceCalculations.vat19 > 0 && ( 19% Mehrwertsteuer: {new Intl.NumberFormat('de-DE', {style: 'currency', currency: 'EUR'}).format(priceCalculations.vat19)} )} Gesamtbruttopreis ohne Versand: {new Intl.NumberFormat('de-DE', {style: 'currency', currency: 'EUR'}).format(priceCalculations.totalGross)}
)}
)} {onClose && ( )} {onCheckout && cartItems.length > 0 && ( )} )} ); } } export default CartDropdown;