import { ToggleControl, Icon, Button } from '@wordpress/components'; import { cog } from '@wordpress/icons'; import { useEffect } from '@wordpress/element'; import { useActiveHighlight } from '../../../data/common/hooks'; import SettingsBlock from '../SettingsBlock'; import PaymentMethodIcon from '../PaymentMethodIcon'; import WarningMessage from '../../../Components/Screens/Settings/Components/Payment/WarningMessage'; const PaymentMethodItemBlock = ( { paymentMethod, onTriggerModal, onSelect, isSelected, isDisabled, disabledMessage, warningMessage, } ) => { const { activeHighlight, setActiveHighlight } = useActiveHighlight(); const isHighlighted = activeHighlight === paymentMethod.id; const hasWarning = !! warningMessage; // Reset the active highlight after 2 seconds useEffect( () => { if ( isHighlighted ) { const timer = setTimeout( () => { setActiveHighlight( null ); }, 2000 ); return () => clearTimeout( timer ); } }, [ isHighlighted, setActiveHighlight ] ); // Determine class names based on states const methodItemClasses = [ 'ppcp--method-item', isHighlighted ? 'ppcp-highlight' : '', isDisabled ? 'ppcp--method-item--disabled' : '', hasWarning && ! isDisabled ? 'ppcp--method-item--warning' : '', ] .filter( Boolean ) .join( ' ' ); return ( { isDisabled && (

{ disabledMessage }

) }
{ paymentMethod?.icon && ( ) } { paymentMethod.itemTitle }

{ paymentMethod.itemDescription }

{ hasWarning && ! isDisabled && isSelected && ( ) }
{ paymentMethod?.fields && onTriggerModal && ( ) }
); }; export default PaymentMethodItemBlock;