<?php

/**
 * Periodic security digest email body.
 *
 * Variables via $data array:
 * - $data['site_name'], $data['site_url'], $data['label']
 * - $data['period_label'] (string)
 * - $data['date_range'] (string)
 * - $data['stats'] (array)
 */

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

$sitefort_stats = isset( $data['stats'] ) && is_array( $data['stats'] ) ? $data['stats'] : [];
$sitefort_period_label = isset( $data['period_label'] ) && is_scalar( $data['period_label'] )
	? (string) $data['period_label']
	: 'Weekly';
$sitefort_date_range = isset( $data['date_range'] ) && is_scalar( $data['date_range'] )
	? (string) $data['date_range']
	: '';

$sitefort_rows = [
	'Total Events'         => (int) ( $sitefort_stats['total_events'] ?? 0 ),
	'Firewall Blocks'     => (int) ( $sitefort_stats['firewall_blocks'] ?? 0 ),
	'Failed Logins'       => (int) ( $sitefort_stats['login_failures'] ?? 0 ),
	'Active Scan Findings' => (int) ( $sitefort_stats['scan_findings'] ?? 0 ),
];
?>
<h1><?php echo esc_html( $sitefort_period_label ); ?> Security Digest</h1>

<div class="alert-info">
	Security activity summary for <?php echo esc_html( $data['site_name'] ?? 'your site' ); ?>.
</div>

<?php if ( '' !== $sitefort_date_range ) : ?>
<p style="text-align:center;color:#6b7280;font-size:14px;margin-top:-8px;">
	<?php echo esc_html( $sitefort_date_range ); ?>
</p>
<?php endif; ?>

<table class="meta-table" role="presentation">
	<?php foreach ( $sitefort_rows as $sitefort_label => $sitefort_value ) : ?>
	<tr>
		<td class="meta-label"><?php echo esc_html( $sitefort_label ); ?></td>
		<td class="meta-value"><?php echo esc_html( (string) $sitefort_value ); ?></td>
	</tr>
	<?php endforeach; ?>
</table>

<div class="btn-container">
	<a href="<?php echo esc_url( admin_url( 'admin.php?page=sitefort' ) ); ?>" class="btn">Review Dashboard</a>
</div>
