import React, { useState, useEffect, useRef } from 'react'; import { useLocation } from 'react-router-dom'; import ToolSidebar from './ToolSidebar'; import NavigationConfirmModal from './NavigationConfirmModal'; import useNavigationGuard from '../hooks/useNavigationGuard'; import { Menu, X, ChevronDown, Terminal, Sparkles, Home } from 'lucide-react'; import ThemeToggle from './ThemeToggle'; import SEOHead from './SEOHead'; import ConsentBanner from './ConsentBanner'; import { NON_TOOLS, TOOLS, SITE_CONFIG, getCategoryConfig } from '../config/tools'; import { useAnalytics } from '../hooks/useAnalytics'; const Layout = ({ children }) => { const location = useLocation(); const { showModal, pendingNavigation, handleConfirm, handleCancel, hasUnsavedData, navigateWithGuard } = useNavigationGuard(); const [isDropdownOpen, setIsDropdownOpen] = useState(false); const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); const dropdownRef = useRef(null); // Initialize analytics tracking useAnalytics(); const isActive = (path) => { return location.pathname === path; }; // Close dropdown when clicking outside useEffect(() => { const handleClickOutside = (event) => { if (dropdownRef.current && !dropdownRef.current.contains(event.target)) { setIsDropdownOpen(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, []); // Close mobile menu when route changes useEffect(() => { setIsMobileMenuOpen(false); setIsDropdownOpen(false); }, [location.pathname]); // Check if we're on a tool page (not homepage) const isToolPage = location.pathname !== '/'; // Check if we're on invoice preview page (no sidebar needed) const isInvoicePreviewPage = location.pathname === '/invoice-preview'; return (
{/* SEO Head Management */} {/* Header */}
{/* Desktop Navigation - only show on homepage */} {!isToolPage && ( )} {/* Mobile Menu Button */}
{/* Mobile Navigation Menu */} {isMobileMenuOpen && ( <> {/* Overlay */}
setIsMobileMenuOpen(false)} /> {/* Menu */}
{/* Non-Tools Section */} {NON_TOOLS.map((tool) => { const IconComponent = tool.icon; return ( ); })}
{isToolPage ? 'Switch Tools' : 'Tools'}
{TOOLS.map((tool) => { const IconComponent = tool.icon; const categoryConfig = getCategoryConfig(tool.category); return ( ); })}
)} {/* Main Content */}
{/* Main Content Area */}
{isToolPage && !isInvoicePreviewPage ? (
{children}
) : isInvoicePreviewPage ? (
{children}
) : (
{children}
{/* Global Footer for Homepage */}
{SITE_CONFIG.title} { // Fallback to Terminal icon with text if logo fails to load e.target.style.display = 'none'; e.target.nextSibling.style.display = 'flex'; }} />
{SITE_CONFIG.title}
© {SITE_CONFIG.year} {SITE_CONFIG.title}

Built with ❤️ for developers worldwide

100% Client-Side
Privacy First
Open Source
)}
{/* Footer for Tool Pages */} {isToolPage && (
{SITE_CONFIG.title} { // Fallback to Terminal icon with text if logo fails to load e.target.style.display = 'none'; e.target.nextSibling.style.display = 'flex'; }} />
© {SITE_CONFIG.year} {SITE_CONFIG.title}
)} {/* GDPR Consent Banner */} {/* Navigation Confirmation Modal */}
); }; export default Layout;