/** * WooCommerce workspace — top-level hub. * * Lists the five store views (Product Catalog, Single Product, Cart, * Checkout, My Account); each is its own family under this folder (`shop/`, * `product/`, `cart/`, `checkout/`, `account/`), with its own further tabs. Only rendered when * WooCommerce is active (the PHP module contributes `schema.woocommerce` * only then). Writes into the `woocommerce` settings tree; the WooCommerce * module applies each value through WC's own filters and template hooks. * * On the Customizer host each view is a real `WP_Customize_Section` of its * own — see Customizer::WOOCOMMERCE_VIEW_SUBSECTIONS — reached via * `onNavigateTab`, mirroring Typography's hub/tab-section split (extended * one level deeper: each view is itself a hub for its own tabs — see * `shop/index.tsx` etc.). On the standalone admin page (no `onNavigateTab`) * every view still renders inline, via that same view's own component. */ import { __ } from '@wordpress/i18n'; import { useState } from '@wordpress/element'; import { ShoppingBag } from 'lucide-react'; import Tabs from '../../controls/tabs'; import type { WorkingSettings, SetPath, ViewedSectionExtras, } from '../../types'; import type { WooSchema, Option } from './types'; import { VIEWS } from './constants'; import ShopSection from './shop'; import ProductSection from './product'; import CartSection from './cart'; import CheckoutSection from './checkout'; import AccountSection from './account'; import SectionIntro from '../../controls/section-intro'; const ID_PREFIX = 'aureon-woocommerce'; interface WooSectionProps { schema?: WooSchema; layoutSchema?: { sidebars?: Option[] }; working: WorkingSettings; setPath: SetPath; /** Notify the shell which view is active, so the preview can follow. */ onViewChange?: ( context: string ) => void; extras?: ViewedSectionExtras; /** * Customizer host only: focus the given view's own real section instead * of rendering it inline. See Customizer::WOOCOMMERCE_VIEW_SUBSECTIONS. */ onNavigateTab?: ( key: string ) => void; } export default function WooCommerceSection( { schema, layoutSchema, working, setPath, onViewChange, extras, onNavigateTab, }: WooSectionProps ) { // Same as the Templates workspace: the open store view rides local state // on the standalone page; the Customizer host never renders this inline // (see `onNavigateTab`), so it has no need for it. const [ context, setContext ] = useState( '' ); if ( ! schema ) { return null; } const pick = ( next: string ) => { if ( onNavigateTab ) { // The Customizer host mounts each view as its own real section // (see sections.tsx), so — unlike the standalone page below, // where each view's own mount effect reports in — the preview // needs to be told directly, at the moment of navigation. onNavigateTab( next ); onViewChange?.( next ); return; } setContext( next ); }; return (

{ schema.label }

{ __( 'Shape each store view. Pick one below — reorder the elements on each card to change what shows and in what order.', 'aureon' ) }

( { key: item.context, label: item.label, icon: item.icon, description: item.blurb, } ) ) } active={ onNavigateTab ? '' : context } onChange={ pick } idPrefix={ ID_PREFIX } variant="subnav" backLabel={ schema.label } /> { ! onNavigateTab && !! context && (

{ VIEWS.find( ( item ) => item.context === context ) ?.blurb }

) } { ! onNavigateTab && 'shop' === context && ( ) } { ! onNavigateTab && 'product' === context && ( ) } { ! onNavigateTab && 'cart' === context && ( ) } { ! onNavigateTab && 'checkout' === context && ( ) } { ! onNavigateTab && 'account' === context && ( ) }
); }