<?php

/**
 * Generic notification email template.
 * Fallback for events without a specific template.
 *
 * Variables via $data array:
 * - $data['site_name'], $data['site_url'], $data['label']
 * - $data['message'] (string, optional - custom message body)
 * - $data['details'] (array, optional - key-value pairs to display)
 */

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

$sitefort_site_name = isset( $data['site_name'] ) && is_scalar( $data['site_name'] )
    ? sanitize_text_field( (string) $data['site_name'] )
    : 'your site';
$sitefort_brand_name = isset( $data['brand_name'] ) && is_scalar( $data['brand_name'] )
    ? sanitize_text_field( (string) $data['brand_name'] )
    : 'SiteFort';
?>
<h1><?php echo esc_html( $data['label'] ?? 'Security Notification' ); ?></h1>

<?php if ( ! empty( $data['message'] ) ) : ?>
<p><?php echo esc_html( $data['message'] ); ?></p>
<?php else : ?>
<p class="intro-copy">
    <?php echo esc_html( $sitefort_brand_name ); ?> logged a security event on <?php echo esc_html( $sitefort_site_name ); ?>. The details are below.
</p>
<?php endif; ?>

<div class="detail-box">
    <strong>Site:</strong> <?php echo esc_html( $data['site_url'] ?? '' ); ?><br>
    <?php if ( ! empty( $data['details'] ) && is_array( $data['details'] ) ) : ?>
        <?php foreach ( $data['details'] as $sitefort_key => $sitefort_value ) : ?>
        <strong><?php echo esc_html( ucfirst( str_replace( '_', ' ', $sitefort_key ) ) ); ?>:</strong>
        <?php echo esc_html( is_scalar( $sitefort_value ) ? (string) $sitefort_value : wp_json_encode( $sitefort_value ) ); ?><br>
        <?php endforeach; ?>
    <?php endif; ?>
</div>
