<?php

/**
 * Firewall block digest email body.
 *
 * Variables via $data array:
 * - $data['site_name'], $data['site_url'], $data['label']
 * - $data['blocked_count'] (int)
 * - $data['digest_period'] (string)
 * - $data['digest_schedule'] (string)
 * - $data['by_type'] (array<string,int>)
 */

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

$sitefort_count = (int) ( $data['blocked_count'] ?? 0 );
$sitefort_period = isset( $data['digest_period'] ) && is_scalar( $data['digest_period'] )
	? (string) $data['digest_period']
	: 'configured period';
$sitefort_schedule = isset( $data['digest_schedule'] ) && is_scalar( $data['digest_schedule'] )
	? (string) $data['digest_schedule']
	: '';
$sitefort_by_type = isset( $data['by_type'] ) && is_array( $data['by_type'] ) ? $data['by_type'] : [];
$sitefort_manage_url = admin_url( 'admin.php?page=sitefort-settings&tab=notifications' );
?>
<h1>Firewall Block Digest</h1>

<div class="alert-warn">
	Your WAF blocked <strong><?php echo esc_html( (string) $sitefort_count ); ?> request<?php echo 1 === $sitefort_count ? '' : 's'; ?></strong>
	on <?php echo esc_html( $data['site_name'] ?? 'your site' ); ?> during the <?php echo esc_html( $sitefort_period ); ?>.
</div>

<?php if ( ! empty( $sitefort_by_type ) ) : ?>
<table class="meta-table" role="presentation">
	<tr>
		<td class="meta-label">Attack Type</td>
		<td class="meta-value">Blocks</td>
	</tr>
	<?php foreach ( $sitefort_by_type as $sitefort_type => $sitefort_type_count ) : ?>
	<tr>
		<td class="meta-label"><?php echo esc_html( (string) $sitefort_type ); ?></td>
		<td class="meta-value"><?php echo esc_html( (string) (int) $sitefort_type_count ); ?></td>
	</tr>
	<?php endforeach; ?>
</table>
<?php endif; ?>

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

<div class="btn-container">
	<a href="<?php echo esc_url( $sitefort_manage_url ); ?>" class="btn">Manage Notifications</a>
</div>
