import React, { Component } from 'react'; import { Container, Paper, Box, Typography, Button, Divider, List, ListItem, ListItemText, ListItemSecondaryAction, } from '@mui/material'; import { ShoppingCart as ShoppingCartIcon, } from '@mui/icons-material'; import { TentShapeSelector, ProductSelector, ExtrasSelector } from '../components/configurator/index.js'; import { tentShapes, tentSizes, lightTypes, ventilationTypes, extras } from '../data/configuratorData.js'; class GrowTentKonfigurator extends Component { constructor(props) { super(props); // Try to restore state from window object const savedState = window.growTentKonfiguratorState; this.state = { selectedTentShape: savedState?.selectedTentShape || '80x80', selectedTentSize: savedState?.selectedTentSize || 'tent_80x80x160', selectedLightType: savedState?.selectedLightType || 'led_quantum_board', selectedVentilationType: savedState?.selectedVentilationType || 'premium_ventilation', selectedExtras: savedState?.selectedExtras || [], totalPrice: savedState?.totalPrice || 0 }; this.handleTentShapeSelect = this.handleTentShapeSelect.bind(this); this.handleTentSizeSelect = this.handleTentSizeSelect.bind(this); this.handleLightTypeSelect = this.handleLightTypeSelect.bind(this); this.handleVentilationSelect = this.handleVentilationSelect.bind(this); this.handleExtraToggle = this.handleExtraToggle.bind(this); this.calculateTotalPrice = this.calculateTotalPrice.bind(this); this.saveStateToWindow = this.saveStateToWindow.bind(this); } saveStateToWindow() { // Save current state to window object for backup window.growTentKonfiguratorState = { selectedTentShape: this.state.selectedTentShape, selectedTentSize: this.state.selectedTentSize, selectedLightType: this.state.selectedLightType, selectedVentilationType: this.state.selectedVentilationType, selectedExtras: this.state.selectedExtras, totalPrice: this.state.totalPrice, timestamp: Date.now() // Add timestamp for debugging }; } componentDidMount() { // @note Calculate initial total price with preselected products this.calculateTotalPrice(); } componentDidUpdate(prevProps, prevState) { // Reset tent size selection if shape changes if (prevState.selectedTentShape !== this.state.selectedTentShape && this.state.selectedTentShape !== prevState.selectedTentShape) { this.setState({ selectedTentSize: '' }); } // Recalculate total price when selections change if ( prevState.selectedTentSize !== this.state.selectedTentSize || prevState.selectedLightType !== this.state.selectedLightType || prevState.selectedVentilationType !== this.state.selectedVentilationType || prevState.selectedExtras !== this.state.selectedExtras ) { this.calculateTotalPrice(); } // Save state to window object whenever selections change if ( prevState.selectedTentShape !== this.state.selectedTentShape || prevState.selectedTentSize !== this.state.selectedTentSize || prevState.selectedLightType !== this.state.selectedLightType || prevState.selectedVentilationType !== this.state.selectedVentilationType || prevState.selectedExtras !== this.state.selectedExtras || prevState.totalPrice !== this.state.totalPrice ) { this.saveStateToWindow(); } } handleTentShapeSelect(shapeId) { this.setState({ selectedTentShape: shapeId }); } handleTentSizeSelect(tentId) { this.setState({ selectedTentSize: tentId }); } handleLightTypeSelect(lightId) { this.setState({ selectedLightType: lightId }); } handleVentilationSelect(ventilationId) { this.setState({ selectedVentilationType: ventilationId }); } handleExtraToggle(extraId) { const { selectedExtras } = this.state; const newSelectedExtras = selectedExtras.includes(extraId) ? selectedExtras.filter(id => id !== extraId) : [...selectedExtras, extraId]; this.setState({ selectedExtras: newSelectedExtras }); } calculateTotalPrice() { let total = 0; const { selectedTentSize, selectedLightType, selectedVentilationType, selectedExtras } = this.state; let itemCount = 0; // Add tent price if (selectedTentSize) { const tent = tentSizes.find(t => t.id === selectedTentSize); if (tent) { total += tent.price; itemCount++; } } // Add light price if (selectedLightType) { const light = lightTypes.find(l => l.id === selectedLightType); if (light) { total += light.price; itemCount++; } } // Add ventilation price if (selectedVentilationType) { const ventilation = ventilationTypes.find(v => v.id === selectedVentilationType); if (ventilation) { total += ventilation.price; itemCount++; } } // Add extras prices selectedExtras.forEach(extraId => { const extra = extras.find(e => e.id === extraId); if (extra) { total += extra.price; itemCount++; } }); // Apply bundle discount let discountPercentage = 0; if (itemCount >= 3) discountPercentage = 15; // 15% for 3+ items if (itemCount >= 5) discountPercentage = 24; // 24% for 5+ items if (itemCount >= 7) discountPercentage = 36; // 36% for 7+ items const discountedTotal = total * (1 - discountPercentage / 100); this.setState({ totalPrice: discountedTotal }); } formatPrice(price) { return new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(price); } calculateSavings() { // Bundle discount calculation const { selectedTentSize, selectedLightType, selectedVentilationType, selectedExtras } = this.state; let itemCount = 0; let originalTotal = 0; // Calculate original total without discount if (selectedTentSize) { const tent = tentSizes.find(t => t.id === selectedTentSize); if (tent) { originalTotal += tent.price; itemCount++; } } if (selectedLightType) { const light = lightTypes.find(l => l.id === selectedLightType); if (light) { originalTotal += light.price; itemCount++; } } if (selectedVentilationType) { const ventilation = ventilationTypes.find(v => v.id === selectedVentilationType); if (ventilation) { originalTotal += ventilation.price; itemCount++; } } selectedExtras.forEach(extraId => { const extra = extras.find(e => e.id === extraId); if (extra) { originalTotal += extra.price; itemCount++; } }); // Progressive discount based on number of selected items let discountPercentage = 0; if (itemCount >= 3) discountPercentage = 15; // 15% for 3+ items if (itemCount >= 5) discountPercentage = 24; // 24% for 5+ items if (itemCount >= 7) discountPercentage = 36; // 36% for 7+ items const savings = originalTotal * (discountPercentage / 100); return { savings: savings, discountPercentage: discountPercentage, hasDiscount: discountPercentage > 0 }; } renderTentShapeSection() { const { selectedTentShape } = this.state; return ( ); } renderTentSizeSection() { const { selectedTentSize, selectedTentShape } = this.state; // Filter tents by selected shape const filteredTents = tentSizes.filter(tent => tent.shapeId === selectedTentShape); if (!selectedTentShape) { return null; // Don't show tent sizes until shape is selected } return ( ); } renderLightSection() { const { selectedLightType } = this.state; return ( ); } renderVentilationSection() { const { selectedVentilationType } = this.state; return ( ); } renderExtrasSection() { const { selectedExtras } = this.state; return ( ); } renderInlineSummary() { const { selectedTentSize, selectedLightType, selectedVentilationType, selectedExtras, totalPrice } = this.state; const selectedTent = tentSizes.find(t => t.id === selectedTentSize); const selectedLight = lightTypes.find(l => l.id === selectedLightType); const selectedVentilation = ventilationTypes.find(v => v.id === selectedVentilationType); const selectedExtrasItems = extras.filter(e => selectedExtras.includes(e.id)); const savingsInfo = this.calculateSavings(); return ( 🎯 Ihre Konfiguration {selectedTent && ( {this.formatPrice(selectedTent.price)} )} {selectedLight && ( {this.formatPrice(selectedLight.price)} )} {selectedVentilation && ( {this.formatPrice(selectedVentilation.price)} )} {selectedExtrasItems.map(extra => ( {this.formatPrice(extra.price)} ))} {savingsInfo.hasDiscount && ( Sie sparen: {this.formatPrice(savingsInfo.savings)} ({savingsInfo.discountPercentage}% Bundle-Rabatt) )} Gesamtpreis: {this.formatPrice(totalPrice)} ); } render() { return ( 🌱 Growbox Konfigurator Stelle dein perfektes Indoor Grow Setup zusammen {/* Bundle Discount Information */} 🎯 Bundle-Rabatt sichern! 15% ab 3 Produkten 24% ab 5 Produkten 36% ab 7 Produkten Je mehr Produkte du auswählst, desto mehr sparst du! {this.renderTentShapeSection()} {this.renderTentSizeSection()} {this.state.selectedTentShape && } {this.renderLightSection()} {this.renderVentilationSection()} {this.renderExtrasSection()} {/* Inline summary section - expands when scrolling to bottom */} {this.renderInlineSummary()} ); } } export default GrowTentKonfigurator;