/**
* The four field groups behind Single Product's tabs — split out of the
* section component so the hub's own inline `TabPanel` (standalone admin
* page) and each tab's own mounted leaf (Customizer host, see
* `tab-section.tsx`) render the exact same markup from one place.
*/
import { __ } from '@wordpress/i18n';
import {
RangeControl,
ToggleControl,
TextControl,
FormTokenField,
} from '@wordpress/components';
import SegmentedControl from '../../../controls/segmented-control';
import ElementList from '../../../controls/element-list';
import DesignGallery from '../../../controls/design-gallery';
import type { WorkingSettings, SetPath, SectionExtra } from '../../../types';
import type { WooSchema, Option } from '../types';
import {
toOptions,
SidebarField,
sidebarOptionsFor,
ExtrasFields,
} from '../shared';
interface BaseProps {
schema: WooSchema;
working: WorkingSettings;
setPath: SetPath;
}
const singleOf = ( working: WorkingSettings ) =>
( ( ( working?.woocommerce ?? {} ) as Record< string, any > ).single ??
{} ) as Record< string, any >;
export function SummaryFields( { schema, working, setPath }: BaseProps ) {
const single = singleOf( working );
return (
{ __(
'The details column beside the gallery. Drag to reorder, or remove an element to hide it.',
'aureon'
) }
setPath( 'woocommerce.single.structure', items )
}
/>
);
}
interface LayoutFieldsProps extends BaseProps {
layoutSchema?: { sidebars?: Option[] };
}
export function LayoutFields( {
schema,
working,
setPath,
layoutSchema,
}: LayoutFieldsProps ) {
const single = singleOf( working );
const layoutContexts = (
( working?.layout ?? {} ) as Record< string, any >
).contexts as Record< string, Record< string, unknown > > | undefined;
return (
setPath( 'woocommerce.single.image_ratio', value )
}
/>
setPath( 'woocommerce.single.details_style', value )
}
/>
setPath( 'woocommerce.single.gallery_position', value )
}
/>
setPath( 'woocommerce.single.thumbnail_layout', value )
}
/>
setPath( 'woocommerce.single.zoom', checked )
}
/>
setPath( 'woocommerce.single.breadcrumb', checked )
}
/>
setPath( 'woocommerce.single.sticky_add_to_cart', checked )
}
/>
setPath( 'woocommerce.single.digital_details', checked )
}
/>
setPath( 'woocommerce.single.swatches', checked )
}
/>
);
}
export function CartButtonFields( { schema, working, setPath }: BaseProps ) {
const single = singleOf( working );
// Stored as a list so the label can cover overlapping kinds at once (every
// downloadable product, say, plus every external one).
const cartLabelTypes: string[] = Array.isArray( single.cart_label_types )
? single.cart_label_types
: [ 'downloadable' ];
// The token field speaks labels while the setting stores slugs, so the two
// are mapped both ways against the schema vocabulary — an unknown stored
// slug shows as itself rather than vanishing on the next save.
const cartLabelOptions = schema.cart_label_types ?? [];
const cartLabelSuggestions = cartLabelOptions.map(
( option ) => option.label
);
const cartLabelTokens = cartLabelTypes.map(
( value ) =>
cartLabelOptions.find( ( option ) => option.value === value )
?.label ?? value
);
const tokensToTypes = ( tokens: string[] ) =>
tokens.map(
( token ) =>
cartLabelOptions.find( ( option ) => option.label === token )
?.value ?? token
);
return (
setPath( 'woocommerce.single.cart_label', value )
}
/>
setPath(
'woocommerce.single.cart_label_types',
tokensToTypes( tokens as string[] )
)
}
/>
{ __(
'Downloadable and Virtual are properties, not types — they match a simple or variable product that carries them.',
'aureon'
) }
);
}
interface RelatedFieldsProps extends BaseProps {
extras?: SectionExtra[];
}
export function RelatedFields( {
schema,
working,
setPath,
extras,
}: RelatedFieldsProps ) {
const single = singleOf( working );
return (
<>
{ __(
'The product rails under a product and in the cart. They can use a different card design from the shop catalog.',
'aureon'
) }
setPath( 'woocommerce.single.related_count', value )
}
/>
setPath( 'woocommerce.single.related_columns', value )
}
/>
setPath( 'woocommerce.single.related_design', value )
}
/>
>
);
}