<?php

/**
 * Login lockout notification template.
 *
 * Variables via $data array:
 * - $data['site_name'], $data['site_url'], $data['label']
 * - $data['identifier'] (string)
 * - $data['type'] (string: ip|user)
 * - $data['lockout_duration'] (string, optional)
 * - $data['detection_window'] (string, optional)
 * - $data['threshold'] (string, optional)
 * - $data['detected_at'] (string, optional)
 */

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

$sitefort_identifier = isset( $data['identifier'] ) && is_scalar( $data['identifier'] )
	? (string) $data['identifier']
	: 'Unavailable';
$sitefort_brand_name = isset( $data['brand_name'] ) && is_scalar( $data['brand_name'] )
	? sanitize_text_field( (string) $data['brand_name'] )
	: 'SiteFort';
$sitefort_type = isset( $data['type'] ) && is_scalar( $data['type'] ) ? sanitize_key( (string) $data['type'] ) : 'ip';
$sitefort_scope_label = 'user' === $sitefort_type ? 'Account' : 'IP Address';
$sitefort_scope_copy = 'user' === $sitefort_type
	? sprintf( '%s temporarily blocked further sign-in attempts for this account identifier after repeated authentication failures.', $sitefort_brand_name )
	: sprintf( '%s temporarily blocked further sign-in attempts from this IP address after repeated authentication failures.', $sitefort_brand_name );
$sitefort_lockout_duration = isset( $data['lockout_duration'] ) && is_scalar( $data['lockout_duration'] )
	? trim( (string) $data['lockout_duration'] )
	: '';
$sitefort_detection_window = isset( $data['detection_window'] ) && is_scalar( $data['detection_window'] )
	? trim( (string) $data['detection_window'] )
	: '';
$sitefort_threshold = isset( $data['threshold'] ) && is_scalar( $data['threshold'] )
	? trim( (string) $data['threshold'] )
	: '';
$sitefort_detected_at = isset( $data['detected_at'] ) && is_scalar( $data['detected_at'] )
	? trim( (string) $data['detected_at'] )
	: '';
?>
<h1>Login Lockout Activated</h1>

<div class="alert-warn">
	<strong><?php echo esc_html( $sitefort_scope_label ); ?> Lockout</strong><br>
	<?php echo esc_html( $sitefort_scope_copy ); ?>
</div>

<p>
	<?php echo esc_html( $sitefort_brand_name ); ?> enforced the configured login protection policy on
	<?php echo esc_html( $data['site_name'] ?? 'your site' ); ?>. Review the context below to determine
	whether the activity is expected or whether additional containment is required.
</p>

<table class="meta-table" role="presentation">
	<tr>
		<td class="meta-label">Site</td>
		<td class="meta-value"><a href="<?php echo esc_url( $data['site_url'] ?? '' ); ?>"><?php echo esc_html( $data['site_url'] ?? '' ); ?></a></td>
	</tr>
	<tr>
		<td class="meta-label">Lockout Scope</td>
		<td class="meta-value"><?php echo esc_html( $sitefort_scope_label ); ?></td>
	</tr>
	<tr>
		<td class="meta-label">Identifier</td>
		<td class="meta-value"><span class="mono-pill"><?php echo esc_html( $sitefort_identifier ); ?></span></td>
	</tr>
	<?php if ( $sitefort_threshold !== '' ) : ?>
	<tr>
		<td class="meta-label">Trigger Threshold</td>
		<td class="meta-value"><?php echo esc_html( $sitefort_threshold ); ?></td>
	</tr>
	<?php endif; ?>
	<?php if ( $sitefort_detection_window !== '' ) : ?>
	<tr>
		<td class="meta-label">Detection Window</td>
		<td class="meta-value"><?php echo esc_html( $sitefort_detection_window ); ?></td>
	</tr>
	<?php endif; ?>
	<?php if ( $sitefort_lockout_duration !== '' ) : ?>
	<tr>
		<td class="meta-label">Lockout Duration</td>
		<td class="meta-value"><?php echo esc_html( $sitefort_lockout_duration ); ?></td>
	</tr>
	<?php endif; ?>
	<?php if ( $sitefort_detected_at !== '' ) : ?>
	<tr>
		<td class="meta-label">Detected At</td>
		<td class="meta-value"><?php echo esc_html( $sitefort_detected_at ); ?></td>
	</tr>
	<?php endif; ?>
</table>

<div class="detail-box">
	<strong>Recommended response</strong><br>
	If this activity was expected, no action is required. If it was not expected, review the login page exposure,
	recent authentication failures, active administrator sessions, and any automation or monitoring traffic coming
	from this source before manually lifting the lockout.
</div>
