import type { ReactNode } from 'react';
import { StorefrontProvider } from './context';
import { CartPage } from './pages/cart';
import { CheckoutPage } from './pages/checkout';
import { OrderPage } from './pages/order';
import { ProductPage } from './pages/product';
import { ShopPage } from './pages/shop';
import { About } from './sections/about';
import { Contact } from './sections/contact';
import { Faq } from './sections/faq';
import { FeaturedProduct } from './sections/featured-product';
import { Footer } from './sections/footer';
import { Header } from './sections/header';
import { Hero } from './sections/hero';
import { Newsletter } from './sections/newsletter';
import { ProductGrid } from './sections/product-grid';
import { Testimonials } from './sections/testimonials';
import { themeStyle } from './theme';
import type {
FontMap,
PlanSection,
StoreCart,
StorePlan,
StoreProduct,
StorefrontView,
} from './types';
/**
* Draw one section. To add a new section type: add it to PlanSchema.php and
* types.ts, write its component, and add one line here.
*/
function Section({ section }: { section: PlanSection }) {
switch (section.type) {
case 'hero':
return ;
case 'product_grid':
return ;
case 'featured_product':
return ;
case 'about':
return ;
case 'testimonials':
return ;
case 'faq':
return ;
case 'newsletter':
return ;
case 'contact':
return ;
default:
// A type this version of the app does not know. Skip it and keep the page working.
return null;
}
}
function PageBody({ plan, view }: { plan: StorePlan; view: StorefrontView }) {
if (view.type === 'shop') {
return ;
}
if (view.type === 'cart') {
return ;
}
if (view.type === 'checkout') {
return ;
}
if (view.type === 'order') {
return ;
}
if (view.type === 'product') {
return ;
}
const page =
plan.pages.find((candidate) => candidate.id === view.pageId) ??
plan.pages[0];
return (
{/* Extra pages get a page heading for screen readers. The home page has its hero headline. */}
{page && page.id !== 'home' && (
{page.title}
)}
{page?.sections.map((section) => (
))}
);
}
/**
* Turn a store plan into one storefront page: the shared header, the page itself, the shared footer.
*/
export function StorefrontRenderer({
plan,
fonts,
view,
baseUrl,
language,
products,
cart,
}: {
plan: StorePlan;
fonts: FontMap;
view: StorefrontView;
baseUrl: string;
language: string;
products: StoreProduct[];
cart: StoreCart;
}): ReactNode {
const isHome = view.type === 'page' && view.pageId === 'home';
return (
);
}