import cn from 'classnames' import React, { FC } from 'react' import dynamic from 'next/dynamic' import { useRouter } from 'next/router' import { CommerceProvider } from '@framework' import { useUI } from '@components/ui/context' import type { Page } from '@commerce/types/page' import { Navbar, Footer } from '@components/common' import type { Category } from '@commerce/types/site' import ShippingView from '@components/checkout/ShippingView' import CartSidebarView from '@components/cart/CartSidebarView' import { useAcceptCookies } from '@lib/hooks/useAcceptCookies' import { Sidebar, Button, LoadingDots } from '@components/ui' import PaymentMethodView from '@components/checkout/PaymentMethodView' import CheckoutSidebarView from '@components/checkout/CheckoutSidebarView' import LoginView from '@components/auth/LoginView' import s from './Layout.module.css' const Loading = () => (
) const dynamicProps = { loading: Loading, } const SignUpView = dynamic( () => import('@components/auth/SignUpView'), dynamicProps ) const ForgotPassword = dynamic( () => import('@components/auth/ForgotPassword'), dynamicProps ) const FeatureBar = dynamic( () => import('@components/common/FeatureBar'), dynamicProps ) const Modal = dynamic( () => import('@components/ui/Modal'), Object.assign(dynamicProps, { ssr: false }) ) interface Props { pageProps: { pages?: Page[] categories: Category[] } } const ModalView: FC<{ modalView: string; closeModal(): any }> = ({ modalView, closeModal, }) => { return ( {modalView === 'LOGIN_VIEW' && } {modalView === 'SIGNUP_VIEW' && } {modalView === 'FORGOT_VIEW' && } ) } const ModalUI: FC = () => { const { displayModal, closeModal, modalView } = useUI() return displayModal ? ( ) : null } const SidebarView: FC<{ sidebarView: string; closeSidebar(): any }> = ({ sidebarView, closeSidebar, }) => { return ( {sidebarView === 'CART_VIEW' && } {sidebarView === 'CHECKOUT_VIEW' && } {sidebarView === 'PAYMENT_VIEW' && } {sidebarView === 'SHIPPING_VIEW' && } ) } const SidebarUI: FC = () => { const { displaySidebar, closeSidebar, sidebarView } = useUI() return displaySidebar ? ( ) : null } const Layout: FC = ({ children, pageProps: { categories = [], ...pageProps }, }) => { const { acceptedCookies, onAcceptCookies } = useAcceptCookies() const { locale = 'en-US' } = useRouter() const navBarlinks = categories.slice(0, 2).map((c) => ({ label: c.name, href: `/search/${c.slug}`, })) return (
{children}
) } export default Layout