<?php
/**
 * Import settings banner when another email plugin's config is detected.
 *
 * @package EmailSmtp
 * @var list<array{id:string, label:string, count:int, plugin_file:string}> $import_sources
 * @var string $page_url
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( empty( $import_sources ) || ! is_array( $import_sources ) ) {
	return;
}
?>
<?php foreach ( $import_sources as $source ) : ?>
	<?php
	$source_id = sanitize_key( (string) ( $source['id'] ?? '' ) );
	$label     = (string) ( $source['label'] ?? '' );
	$count     = (int) ( $source['count'] ?? 0 );
	if ( $source_id === '' || $label === '' || $count < 1 ) {
		continue;
	}
	$import_url = wp_nonce_url(
		add_query_arg(
			[
				'action' => 'wpps_email_delivery_import_settings',
				'source' => $source_id,
			],
			admin_url( 'admin-post.php' )
		),
		'wpps_email_delivery_import_settings'
	);
	$dismiss_url = wp_nonce_url(
		add_query_arg(
			[
				'action' => 'wpps_email_delivery_dismiss_import',
				'source' => $source_id,
			],
			admin_url( 'admin-post.php' )
		),
		'wpps_email_delivery_dismiss_import'
	);
	?>
	<div class="notice notice-info wpps-ed-import-banner">
		<p>
			<strong><?php esc_html_e( 'Import mail settings', 'wp-powersuite' ); ?></strong>
			<?php
			echo ' ';
			echo esc_html(
				sprintf(
					/* translators: 1: plugin name, 2: connection count */
					_n(
						'We found %2$d connection from %1$s. Import it into Email Delivery?',
						'We found %2$d connections from %1$s. Import them into Email Delivery?',
						$count,
						'wp-powersuite'
					),
					$label,
					$count
				)
			);
			?>
		</p>
		<p class="wpps-ed-import-banner__actions">
			<a class="button button-primary" href="<?php echo esc_url( $import_url ); ?>"><?php esc_html_e( 'Import settings', 'wp-powersuite' ); ?></a>
			<a class="button" href="<?php echo esc_url( $dismiss_url ); ?>"><?php esc_html_e( 'Dismiss', 'wp-powersuite' ); ?></a>
		</p>
	</div>
<?php endforeach; ?>
