import {createHigherOrderComponent} from '@wordpress/compose'; import {InspectorControls} from '@wordpress/block-editor'; import {__} from '@wordpress/i18n'; import {PanelBody, PanelRow, ToggleControl} from '@wordpress/components'; import {createInterpolateElement} from '@wordpress/element'; import ControlForPopover from '@givewp/form-builder/components/settings/ControlForPopover'; import PopoverContentWithTemplateTags from '@givewp/form-builder/components/settings/PopoverContentWithTemplateTags'; import useSetDefaultAttributes from './useSetDefaultAttributes'; import {offlineAttributes} from './addOfflineAttributes'; import usePopoverState from '@givewp/form-builder/hooks/usePopoverState'; declare const window: { giveOfflineGatewaySettings: { offlineSettingsUrl: string; }; } & Window; type OfflineAttributes = { offlineEnabled?: boolean; offlineUseGlobalInstructions?: boolean; offlineDonationInstructions?: string; }; type OfflineSetAttributes = (attributes: OfflineAttributes) => void; const offlineInstructionTags = [ { id: 'offline_mailing_address', description: __('The mailing address provided to the donor to send their payment to.', 'give'), }, { id: 'sitename', description: __('The name of this website.', 'give'), }, ]; function OfflineInspectorControls({ attributes, setAttributes, }: { setAttributes: OfflineSetAttributes; attributes: OfflineAttributes; }) { const {isOpen: isInstructionsOpen, toggle: toggleInstructions, close: closeInstructions} = usePopoverState(); useSetDefaultAttributes(attributes, setAttributes, offlineAttributes); const windowSettings = window.giveOfflineGatewaySettings; const textWithLinkToOfflineSettings = (textTemplate: string) => createInterpolateElement(textTemplate, { a: , }); const globalDefaultHelper = textWithLinkToOfflineSettings( __( 'Global instructions are defined in the Global Settings. When disabled, custom instructions can be written for this form', 'give' ) ); return ( setAttributes({offlineEnabled: value})} /> {attributes.offlineEnabled && ( setAttributes({offlineUseGlobalInstructions: value})} help={globalDefaultHelper} /> )} {attributes.offlineEnabled && !attributes.offlineUseGlobalInstructions && ( {isInstructionsOpen && ( setAttributes({offlineDonationInstructions: content})} heading={__('Donation Instructions', 'give')} content={attributes.offlineDonationInstructions} templateTags={offlineInstructionTags} onClose={closeInstructions} richText /> )} )} ); } const withInspectorControls = createHigherOrderComponent((BlockEdit) => { return (props) => { if (props.name === 'givewp/payment-gateways') { return ( <> ); } return ; }; }, 'withInspectorControl'); export default withInspectorControls;