<?php
/**
 * Email Report Section: Activity Log
 *
 * @package EmailReports
 */

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

$primary_color = (string) ( $branding['primary_color'] ?? '#2271b1' );
$total   = isset( $data['total_events'] ) ? number_format_i18n( $data['total_events'] ) : '0';
$logins  = isset( $data['user_logins'] ) ? number_format_i18n( $data['user_logins'] ) : '0';
$content = isset( $data['content_changes'] ) ? number_format_i18n( $data['content_changes'] ) : '0';
$failed  = isset( $data['failed_logins'] ) ? number_format_i18n( $data['failed_logins'] ) : '0';

wpps_er_render_stat_card( $total, __( 'Total Events', 'wppowersuite-lite' ), $primary_color );
wpps_er_render_stat_card( $logins, __( 'Logins', 'wppowersuite-lite' ), $primary_color );
wpps_er_render_stat_card( $content, __( 'Content Changes', 'wppowersuite-lite' ), $primary_color );
wpps_er_render_stat_card( $failed, __( 'Failed Logins', 'wppowersuite-lite' ), '#b32d2e' );

if ( ! empty( $data['recent_events'] ) ) :
	wpps_er_render_subheading( __( 'Recent Activity', 'wppowersuite-lite' ) );
	foreach ( array_slice( $data['recent_events'], 0, 10 ) as $ev ) :
		$action = $ev['action'] ?? '';
		$desc   = $ev['description'] ?? ucwords( str_replace( '_', ' ', $action ) );
		$date   = isset( $ev['created_at'] ) ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $ev['created_at'] ) ) : '';
		wpps_er_render_list_item( $desc, $date );
	endforeach;
endif;

if ( (int) ( $data['total_events'] ?? 0 ) === 0 ) :
	?>
	<p style="color:#646970;margin:0;"><?php esc_html_e( 'No activity recorded during this period.', 'wppowersuite-lite' ); ?></p>
	<?php
endif;
