import React, { ReactNode } from 'react'; import { useLocation } from 'react-router-dom'; import { useCheckoutSettings, useThankYouSettings } from '../hooks/useAppearanceSettings'; import { MinimalHeader } from '../components/Layout/MinimalHeader'; import { MinimalFooter } from '../components/Layout/MinimalFooter'; interface LayoutWrapperProps { children: ReactNode; header: ReactNode; footer: ReactNode; } export function LayoutWrapper({ children, header, footer }: LayoutWrapperProps) { const location = useLocation(); const checkoutSettings = useCheckoutSettings(); const thankYouSettings = useThankYouSettings(); // Determine visibility settings based on current route let headerVisibility = 'show'; let footerVisibility = 'show'; let backgroundColor = ''; if (location.pathname === '/checkout') { headerVisibility = checkoutSettings.layout.header_visibility || 'minimal'; footerVisibility = checkoutSettings.layout.footer_visibility || 'minimal'; backgroundColor = checkoutSettings.layout.background_color || ''; } else if (location.pathname.startsWith('/order-received/')) { headerVisibility = thankYouSettings.headerVisibility || 'show'; footerVisibility = thankYouSettings.footerVisibility || 'minimal'; backgroundColor = thankYouSettings.backgroundColor || ''; } // Render appropriate header const renderHeader = () => { if (headerVisibility === 'hide') return null; if (headerVisibility === 'minimal') return ; return header; }; // Render appropriate footer const renderFooter = () => { if (footerVisibility === 'hide') return null; if (footerVisibility === 'minimal') return ; return footer; }; return (
{renderHeader()}
{children}
{renderFooter()}
); }