<?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)
 * - $data['unlock_url'] (string, optional)
 * - $data['unlock_valid_for'] (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 sign-in attempts for this account after repeated failed logins.', $sitefort_brand_name )
	: sprintf( '%s temporarily blocked sign-in attempts from this IP address after repeated failed logins.', $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'] )
	: '';
$sitefort_unlock_url = isset( $data['unlock_url'] ) && is_scalar( $data['unlock_url'] )
	? trim( (string) $data['unlock_url'] )
	: '';
$sitefort_unlock_valid_for = isset( $data['unlock_valid_for'] ) && is_scalar( $data['unlock_valid_for'] )
	? trim( (string) $data['unlock_valid_for'] )
	: '';
?>
<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>
	The failed-login limit was reached on <?php echo esc_html( $data['site_name'] ?? 'your site' ); ?>.
	The details below show what was locked and for how long.
</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>

<p>
	Locked out by mistake? Use the button below to get back in.
	Otherwise, you can safely ignore this email; the lockout ends on its own.
</p>

<?php if ( '' !== $sitefort_unlock_url ) : ?>
<div class="btn-container">
	<a href="<?php echo esc_url( $sitefort_unlock_url ); ?>" class="btn">Review &amp; Unlock</a>
</div>
<p>
	No sign-in is required; the link works even while you are locked out<?php echo '' !== $sitefort_unlock_valid_for ? ' and expires in about ' . esc_html( $sitefort_unlock_valid_for ) : ''; ?>.
	Do not forward this email; the link grants unlock access to anyone who holds it.
</p>
<?php endif; ?>
