import { __ } from '@wordpress/i18n'; import { useState, useEffect } from '@wordpress/element'; import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { PanelBody, SelectControl, Spinner } from '@wordpress/components'; import { useScriptParams } from "./hooks/script-params"; import { loadPaypalScript } from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading' import PayPalMessages from "./components/PayPalMessages"; export default function Edit( { attributes, clientId, setAttributes } ) { const { layout, logo, position, color, size, flexColor, flexRatio, placement, id } = attributes; const isFlex = layout === 'flex'; const [paypalScriptState, setPaypalScriptState] = useState(null); const [rendered, setRendered] = useState(false); let amount = undefined; const postContent = String(wp.data.select('core/editor')?.getEditedPostContent()); if (postContent.includes('woocommerce/checkout') || postContent.includes('woocommerce/cart')) { amount = 50.0; } const previewStyle = { layout, logo: { position, type: logo, }, color: flexColor, ratio: flexRatio, text: { color, size }, }; let classes = ['ppcp-paylater-block-preview', 'ppcp-overlay-parent']; if (PcpPayLaterBlock.vaultingEnabled || !PcpPayLaterBlock.placementEnabled) { classes = ['ppcp-paylater-block-preview', 'ppcp-paylater-unavailable', 'block-editor-warning']; } const props = useBlockProps({className: classes}); const loadingElement =
{__('Pay Later Messaging cannot be used while PayPal Vaulting is active. Disable PayPal Vaulting in the PayPal Payment settings to reactivate this block', 'woocommerce-paypal-payments')}
{__('Pay Later Messaging cannot be used while the “WooCommerce Block” messaging placement is disabled. Enable the placement in the PayPal Payments Pay Later settings to reactivate this block.', 'woocommerce-paypal-payments')}