/** * External dependencies */ import { createBlock, type BlockInstance } from '@wordpress/blocks'; import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ import type { OnClickCallbackParameter, InheritedAttributes } from './types'; const isConversionPossible = () => { return true; }; const getButtonLabel = () => __( 'Transform into blocks', 'woocommerce' ); const getBlockifiedTemplate = ( inheritedAttributes: InheritedAttributes ) => [ createBlock( 'woocommerce/order-confirmation-status', { ...inheritedAttributes, fontSize: 'large', } ), createBlock( 'woocommerce/order-confirmation-summary', inheritedAttributes ), createBlock( 'woocommerce/order-confirmation-totals-wrapper', inheritedAttributes ), createBlock( 'woocommerce/order-confirmation-downloads-wrapper', inheritedAttributes ), createBlock( 'core/columns', { ...inheritedAttributes, className: 'woocommerce-order-confirmation-address-wrapper', }, [ createBlock( 'core/column', inheritedAttributes, [ createBlock( 'woocommerce/order-confirmation-shipping-wrapper', inheritedAttributes ), ] ), createBlock( 'core/column', inheritedAttributes, [ createBlock( 'woocommerce/order-confirmation-billing-wrapper', inheritedAttributes ), ] ), ] ), createBlock( 'woocommerce/order-confirmation-additional-information', inheritedAttributes ), ].filter( Boolean ) as BlockInstance[]; const onClickCallback = ( { clientId, attributes, getBlocks, replaceBlock, selectBlock, }: OnClickCallbackParameter ) => { replaceBlock( clientId, getBlockifiedTemplate( attributes ) ); const blocks = getBlocks(); const groupBlock = blocks.find( ( block ) => block.name === 'core/group' && block.innerBlocks.some( ( innerBlock ) => innerBlock.name === 'woocommerce/store-notices' ) ); if ( groupBlock ) { selectBlock( groupBlock.clientId ); } }; const getDescription = () => { return __( 'This block represents the classic template used to display the order confirmation. The actual rendered template may appear different from this placeholder.', 'woocommerce' ); }; const getSkeleton = () => { return (

{ __( 'Order received', 'woocommerce' ) }

{ __( 'Thank you. Your order has been received.', 'woocommerce' ) }

{ __( 'Order details', 'woocommerce' ) }

{ __( 'Product', 'woocommerce' ) } { __( 'Total', 'woocommerce' ) }
Sample Product{ ' ' } × 2 { ' ' } $20.00
{ __( 'Subtotal', 'woocommerce' ) }: $20.00
{ __( 'Total', 'woocommerce' ) }: $20.00

{ __( 'Billing address', 'woocommerce' ) }

123 Main St
New York, NY 10001
United States (US)

{ __( 'Shipping address', 'woocommerce' ) }

123 Main St
New York, NY 10001
United States (US)
); }; const blockifyConfig = { getButtonLabel, onClickCallback, getBlockifiedTemplate, }; export { blockifyConfig, isConversionPossible, getDescription, getSkeleton };