/** * External dependencies */ import clsx from 'clsx'; import { useRef } from '@wordpress/element'; import { useSelect } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import PageSelector from '@woocommerce/editor-components/page-selector'; import { PanelBody, ToggleControl } from '@wordpress/components'; import { CHECKOUT_PAGE_ID } from '@woocommerce/block-settings'; import { getSetting } from '@woocommerce/settings'; import { ReturnToCartButton } from '@woocommerce/base-components/cart-checkout'; import EditableButton from '@woocommerce/editor-components/editable-button'; import Noninteractive from '@woocommerce/base-components/noninteractive'; import { useStoreCart } from '@woocommerce/base-context'; import { getCurrencyFromPriceResponse } from '@woocommerce/price-format'; import { FormattedMonetaryAmount } from '@woocommerce/blocks-components'; /** * Internal dependencies */ import { defaultPlaceOrderButtonLabel } from './constants'; import './editor.scss'; export const Edit = ( { attributes, setAttributes, }: { attributes: { showReturnToCart: boolean; showPrice: boolean; cartPageId: number; placeOrderButtonLabel: string; }; setAttributes: ( attributes: Record< string, unknown > ) => void; } ): JSX.Element => { const blockProps = useBlockProps(); const { cartPageId = 0, showReturnToCart = false, placeOrderButtonLabel, showPrice = false, } = attributes; const { cartTotals } = useStoreCart(); const totalsCurrency = getCurrencyFromPriceResponse( cartTotals ); const { current: savedCartPageId } = useRef( cartPageId ); const currentPostId = useSelect( ( select ) => { if ( ! savedCartPageId ) { const store = select( 'core/editor' ); return store.getCurrentPostId(); } return savedCartPageId; }, [ savedCartPageId ] ); return (