<?php
/**
 * Email Report Section: Login Security
 *
 * @package EmailReports
 */

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

$primary_color = (string) ( $branding['primary_color'] ?? '#2271b1' );
$failed        = isset( $data['failed_attempts'] ) ? number_format_i18n( $data['failed_attempts'] ) : '0';
$lockouts      = isset( $data['lockouts'] ) ? number_format_i18n( $data['lockouts'] ) : '0';

wpps_er_render_stat_card( $failed, __( 'Failed Attempts', 'wp-powersuite' ), $primary_color );
wpps_er_render_stat_card( $lockouts, __( 'Lockouts', 'wp-powersuite' ), $primary_color );

if ( ! empty( $data['top_blocked_ips'] ) ) :
	wpps_er_render_subheading( __( 'Top Blocked IPs', 'wp-powersuite' ) );
	foreach ( array_slice( $data['top_blocked_ips'], 0, 5 ) as $row ) :
		wpps_er_render_code_list_item(
			(string) ( $row['ip'] ?? '' ),
			sprintf( __( '%s attempts', 'wp-powersuite' ), number_format_i18n( $row['count'] ?? 0 ) )
		);
	endforeach;
endif;

if ( (int) ( $data['failed_attempts'] ?? 0 ) === 0 && (int) ( $data['lockouts'] ?? 0 ) === 0 ) :
	?>
	<p style="color:#00a32a;margin:0;"><?php esc_html_e( 'No failed login attempts or lockouts during this period.', 'wp-powersuite' ); ?></p>
	<?php
endif;
