import React, { ReactNode, useState } from 'react'; import { Link } from 'react-router-dom'; import { Search, ShoppingCart, User, Menu, X, Heart } from 'lucide-react'; import { useLayout } from '../contexts/ThemeContext'; import { useCartStore } from '../lib/cart/store'; import { useHeaderSettings, useFooterSettings } from '../hooks/useAppearanceSettings'; import { SearchModal } from '../components/SearchModal'; import { NewsletterForm } from '../components/NewsletterForm'; import { LayoutWrapper } from './LayoutWrapper'; import { useModules } from '../hooks/useModules'; import { useModuleSettings } from '../hooks/useModuleSettings'; interface BaseLayoutProps { children: ReactNode; } /** * Base Layout Component * * Renders the appropriate layout based on header style from appearance settings */ export function BaseLayout({ children }: BaseLayoutProps) { const headerSettings = useHeaderSettings(); // Map header styles to layouts // classic -> ClassicLayout, centered -> ModernLayout, minimal -> LaunchLayout, split -> BoutiqueLayout switch (headerSettings.style) { case 'classic': return {children}; case 'centered': return {children}; case 'minimal': return {children}; case 'split': return {children}; default: return {children}; } } /** * Classic Layout - Traditional ecommerce */ function ClassicLayout({ children }: BaseLayoutProps) { const { cart } = useCartStore(); const itemCount = cart.items.reduce((sum, item) => sum + item.quantity, 0); const storeLogo = (window as any).woonoowCustomer?.storeLogo; const storeName = (window as any).woonoowCustomer?.storeName || (window as any).woonoowCustomer?.siteTitle || 'Store Title'; const user = (window as any).woonoowCustomer?.user; const headerSettings = useHeaderSettings(); const { isEnabled } = useModules(); const { settings: wishlistSettings } = useModuleSettings('wishlist'); const footerSettings = useFooterSettings(); const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [searchOpen, setSearchOpen] = useState(false); const heightClass = headerSettings.height === 'compact' ? 'h-16' : headerSettings.height === 'tall' ? 'h-24' : 'h-20'; const hasActions = headerSettings.elements.search || headerSettings.elements.account || headerSettings.elements.cart || headerSettings.elements.wishlist; const footerColsClass: Record = { '1': 'grid-cols-1', '2': 'grid-cols-1 md:grid-cols-2', '3': 'grid-cols-1 md:grid-cols-3', '4': 'grid-cols-1 md:grid-cols-4', }; const footerGridClass = footerColsClass[footerSettings.columns] || 'grid-cols-1 md:grid-cols-4'; const headerContent = ( <> setSearchOpen(false)} />
{/* Logo */} {headerSettings.elements.logo && (
{storeLogo ? ( {storeName} ) : ( <>
W
{storeName} )}
)} {/* Navigation */} {headerSettings.elements.navigation && ( )} {/* Actions - Hidden on mobile when using bottom-nav */} {hasActions && (
{/* Search */} {headerSettings.elements.search && ( )} {/* Account */} {headerSettings.elements.account && (user?.isLoggedIn ? ( Account ) : ( Account ))} {/* Wishlist */} {headerSettings.elements.wishlist && isEnabled('wishlist') && (wishlistSettings.show_in_header ?? true) && ( Wishlist )} {/* Cart */} {headerSettings.elements.cart && (
{itemCount > 0 && ( {itemCount} )}
Cart ({itemCount}) )} {/* Mobile Menu Toggle - Only for hamburger and slide-in */} {(headerSettings.mobile_menu === 'hamburger' || headerSettings.mobile_menu === 'slide-in') && ( )}
)}
{/* Mobile Menu - Hamburger Dropdown */} {headerSettings.mobile_menu === 'hamburger' && mobileMenuOpen && (
{headerSettings.elements.navigation && ( )}
)} {/* Mobile Menu - Slide-in Drawer */} {headerSettings.mobile_menu === 'slide-in' && mobileMenuOpen && ( <>
setMobileMenuOpen(false)} />
Menu
{headerSettings.elements.navigation && ( )}
)}
); const footerContent = ( <> {/* Mobile Menu - Bottom Navigation */} {headerSettings.mobile_menu === 'bottom-nav' && ( )}
{/* Render all sections dynamically */} {footerSettings.sections .filter((s: any) => s.visible) .filter((s: any) => { // Filter out newsletter section if module is disabled if (s.type === 'newsletter' && !isEnabled('newsletter')) { return false; } return true; }) .map((section: any) => (

{section.title}

{/* Contact Section */} {section.type === 'contact' && (
{footerSettings.contact_data?.show_email && footerSettings.contact_data?.email && (

Email: {footerSettings.contact_data.email}

)} {footerSettings.contact_data?.show_phone && footerSettings.contact_data?.phone && (

Phone: {footerSettings.contact_data.phone}

)} {footerSettings.contact_data?.show_address && footerSettings.contact_data?.address && (

{footerSettings.contact_data.address}

)}
)} {/* Menu Section */} {section.type === 'menu' && ( )} {/* Social Section */} {section.type === 'social' && footerSettings.social_links?.length > 0 && ( )} {/* Newsletter Section */} {section.type === 'newsletter' && ( )} {/* Custom HTML Section */} {section.type === 'custom' && (
)}
))}
{/* Payment Icons */} {footerSettings.elements.payment && (

We accept

💳 Visa 💳 Mastercard 💳 PayPal
)} {/* Copyright */} {footerSettings.elements.copyright && (
{footerSettings.copyright_text}
)}
); return ( {children} ); } /** * Modern Layout - Minimalist, clean */ function ModernLayout({ children }: BaseLayoutProps) { const { cart } = useCartStore(); const itemCount = cart.items.reduce((sum, item) => sum + item.quantity, 0); const storeLogo = (window as any).woonoowCustomer?.storeLogo; const storeName = (window as any).woonoowCustomer?.storeName || (window as any).woonoowCustomer?.siteTitle || 'Store Title'; const user = (window as any).woonoowCustomer?.user; const headerSettings = useHeaderSettings(); const { isEnabled } = useModules(); const { settings: wishlistSettings } = useModuleSettings('wishlist'); const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [searchOpen, setSearchOpen] = useState(false); const paddingClass = headerSettings.height === 'compact' ? 'py-4' : headerSettings.height === 'tall' ? 'py-8' : 'py-6'; const hasActions = headerSettings.elements.search || headerSettings.elements.account || headerSettings.elements.cart || headerSettings.elements.wishlist; return (
setSearchOpen(false)} />
{/* Logo - Centered */} {headerSettings.elements.logo && ( {storeLogo ? ( {storeName} ) : ( {storeName} )} )} {/* Navigation & Actions - Centered */} {(headerSettings.elements.navigation || hasActions) && ( )} {/* Mobile Menu Toggle */}
{/* Mobile Menu */} {mobileMenuOpen && (
{headerSettings.elements.navigation && ( )}
)}
{children}
); } /** * Boutique Layout - Luxury, elegant */ function BoutiqueLayout({ children }: BaseLayoutProps) { const { cart } = useCartStore(); const itemCount = cart.items.reduce((sum, item) => sum + item.quantity, 0); const storeLogo = (window as any).woonoowCustomer?.storeLogo; const storeName = (window as any).woonoowCustomer?.storeName || (window as any).woonoowCustomer?.siteTitle || 'BOUTIQUE'; const user = (window as any).woonoowCustomer?.user; const headerSettings = useHeaderSettings(); const { isEnabled } = useModules(); const { settings: wishlistSettings } = useModuleSettings('wishlist'); const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [searchOpen, setSearchOpen] = useState(false); const heightClass = headerSettings.height === 'compact' ? 'h-20' : headerSettings.height === 'tall' ? 'h-28' : 'h-24'; const hasActions = headerSettings.elements.search || headerSettings.elements.account || headerSettings.elements.cart || headerSettings.elements.wishlist; return (
setSearchOpen(false)} />
{/* Logo */}
{headerSettings.elements.logo && (
{storeLogo ? ( {storeName} ) : ( {storeName} )}
)}
{(headerSettings.elements.navigation || hasActions) && ( )} {/* Mobile Menu Toggle */}
{/* Mobile Menu */} {mobileMenuOpen && (
{headerSettings.elements.navigation && ( )}
)}
{children}
); } /** * Launch Layout - Single product funnel * Note: Landing page is custom (user's page builder) * WooNooW only takes over from checkout onwards */ function LaunchLayout({ children }: BaseLayoutProps) { const isCheckoutFlow = window.location.pathname.includes('/checkout') || window.location.pathname.includes('/my-account') || window.location.pathname.includes('/order-received'); if (!isCheckoutFlow) { // For non-checkout pages, use minimal layout return (
{children}
); } // For checkout flow: minimal header, no footer const storeLogo = (window as any).woonoowCustomer?.storeLogo; const storeName = (window as any).woonoowCustomer?.storeName || (window as any).woonoowCustomer?.siteTitle || 'Store Title'; const headerSettings = useHeaderSettings(); const heightClass = headerSettings.height === 'compact' ? 'h-12' : headerSettings.height === 'tall' ? 'h-20' : 'h-16'; return (
{headerSettings.elements.logo && ( {storeLogo ? ( {storeName} ) : ( {storeName} )} )}
{children}
{/* Minimal footer for checkout */}
); }