import { Button } from '@wordpress/components'; import { Header, Title, Action, Description } from '../Elements'; import SettingsBlock from '../SettingsBlock'; import TitleBadge from '../TitleBadge'; import { CommonHooks } from '../../../data'; /** * Renders a feature settings block with title, description, and action buttons. * * @param {Object} props Component properties * @param {string} props.title The feature title * @param {string} props.description HTML description of the feature * @return {JSX.Element} The rendered component */ const FeatureSettingsBlock = ( { title, description, ...props } ) => { const { actionProps } = props; const { isSandbox } = CommonHooks.useMerchant(); /** * Gets the appropriate URL for a button based on environment * Always prioritizes urls object over url when it exists * * @param {Object} buttonData The button configuration object * @param {string} [buttonData.url] Single URL for the button * @param {Object} [buttonData.urls] Environment-specific URLs * @param {string} [buttonData.urls.sandbox] URL for sandbox environment * @param {string} [buttonData.urls.live] URL for live environment * @return {string|undefined} The appropriate URL to use for the button */ const getButtonUrl = ( buttonData ) => { const { url, urls } = buttonData; if ( urls ) { return isSandbox ? urls.sandbox : urls.live; } return url; }; return (
{ title } { actionProps?.enabled && ( <TitleBadge { ...actionProps?.badge } /> ) } { actionProps?.notes?.length > 0 && ( { actionProps.notes.map( ( note, index ) => ( { note } ) ) } ) }
{ actionProps?.buttons.map( ( buttonData ) => { const { class: className, type, text, onClick, } = buttonData; const buttonUrl = getButtonUrl( buttonData ); return ( ); } ) }
); }; export default FeatureSettingsBlock;