import React, { Component } from 'react'; import AppBar from '@mui/material/AppBar'; import Toolbar from '@mui/material/Toolbar'; import Container from '@mui/material/Container'; import Box from '@mui/material/Box'; import { useLocation } from 'react-router-dom'; // Import extracted components import { Logo, SearchBar, ButtonGroupWithRouter, CategoryList } from './header/index.js'; // Main Header Component class Header extends Component { constructor(props) { super(props); this.state = { cartItems: [] }; } handleCartQuantityChange = (productId, quantity) => { this.setState(prevState => ({ cartItems: prevState.cartItems.map(item => item.id === productId ? { ...item, quantity } : item ) })); }; handleCartRemoveItem = (productId) => { this.setState(prevState => ({ cartItems: prevState.cartItems.filter(item => item.id !== productId) })); }; render() { const { isHomePage, isProfilePage, isAktionenPage, isFilialePage } = this.props; return ( {/* First row: Logo and ButtonGroup on xs, all items on larger screens */} {/* Top row for xs, single row for larger screens */} {/* SearchBar visible on sm and up */} {/* Second row: SearchBar only on xs - make it wider */} {(isHomePage || this.props.categoryId || isProfilePage || isAktionenPage || isFilialePage || this.props.isArtikel) && } ); } } // Use a wrapper function to provide context const HeaderWithContext = (props) => { const location = useLocation(); const isHomePage = location.pathname === '/'; const isProfilePage = location.pathname === '/profile'; const isAktionenPage = location.pathname === '/aktionen'; const isFilialePage = location.pathname === '/filiale'; const isArtikel = location.pathname.startsWith('/Artikel/'); return (
); }; export default HeaderWithContext;