/**
 * External dependencies.
 */
import { memo } from '@wordpress/element';

/**
 * Internal dependencies.
 */
import DynamicLink from './DynamicLink';

/**
 * Safe wrapper for DynamicLink component that handles undefined attributes.
 *
 * @since x.x.x
 *
 * @param {Object} props - The component props.
 * @return {Element|null} The wrapped DynamicLink component or null.
 */
const SafeDynamicLink = memo( ( props ) => {
	// Ensure attributes exist and have required properties
	const attributes = props.attributes || {};
	
	// Set default values if properties are missing
	const safeAttributes = {
		...attributes,
		spectraProEnableDynamicLink: attributes.spectraProEnableDynamicLink ?? false,
		spectraProDynamicLink: attributes.spectraProDynamicLink ?? null,
		href: attributes.href ?? '',
		linkURL: attributes.linkURL ?? ''
	};

	// Create safe props with verified attributes
	const safeProps = {
		...props,
		attributes: safeAttributes
	};

	return <DynamicLink { ...safeProps } />;
} );

export default SafeDynamicLink;