<?php
/**
 * EXAMPLE: Customized Two-Factor Authentication Code Email
 * 
 * This is an example of how you might customize the two-factor authentication
 * code email to match your brand.
 * 
 * To use this example:
 * 1. Copy this file to: your-theme/guard-dog/emails/two-factor-code.php
 * 2. Customize the HTML, CSS, and content to match your brand
 * 3. The plugin will automatically use your customized version
 *
 * Available variables:
 * @var string $code The 6-digit verification code
 * @var WP_User $user The user object
 * @var string $site_name The site name
 * @var int $expiry_minutes Code expiration time in minutes (default: 10)
 *
 * @package GuardDog
 * @since 1.8.5
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
// These are local variables in a template file, not global variables
// The Plugin Checker incorrectly flags local template variables as globals
// These variables are scoped to this template file and do not pollute the global namespace

// Set default expiry if not provided
if ( ! isset( $expiry_minutes ) ) {
	$expiry_minutes = 10;
}

// Example: Get custom brand colors from theme options or customizer
$primary_color = get_theme_mod( 'primary_color', '#ff6600' );
$secondary_color = get_theme_mod( 'secondary_color', '#333333' );
$accent_color = get_theme_mod( 'accent_color', '#00aaff' );

// Example: Get company logo from theme
$logo_url = get_theme_mod( 'custom_logo' ) 
	? wp_get_attachment_image_url( get_theme_mod( 'custom_logo' ), 'full' )
	: get_stylesheet_directory_uri() . '/images/logo.png';

// Example: Get support email from settings
$support_email = get_option( 'admin_email' );
// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<?php // Translators: %s is the site name. ?>
	<title><?php echo esc_html( sprintf( __( '[%s] Security Verification Code', 'guard-dog' ), $site_name ) ); ?></title>
	<style type="text/css">
		body {
			font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
			line-height: 1.6;
			color: <?php echo esc_attr( $secondary_color ); ?>;
			background-color: #f4f4f4;
			margin: 0;
			padding: 0;
		}
		.email-wrapper {
			max-width: 600px;
			margin: 20px auto;
			background-color: #ffffff;
			border-radius: 8px;
			overflow: hidden;
			box-shadow: 0 2px 4px rgba(0,0,0,0.1);
		}
		.email-header {
			background-color: <?php echo esc_attr( $primary_color ); ?>;
			color: #ffffff;
			padding: 30px 20px;
			text-align: center;
		}
		.email-header img {
			max-width: 200px;
			height: auto;
			margin-bottom: 10px;
		}
		.email-header h1 {
			margin: 0;
			font-size: 24px;
			font-weight: 600;
		}
		.email-content {
			padding: 40px 30px;
		}
		.email-content p {
			margin: 0 0 15px 0;
			font-size: 16px;
		}
		.greeting {
			font-size: 18px;
			font-weight: 600;
			color: <?php echo esc_attr( $secondary_color ); ?>;
		}
		.verification-code-container {
			background: linear-gradient(135deg, <?php echo esc_attr( $primary_color ); ?> 0%, <?php echo esc_attr( $accent_color ); ?> 100%);
			border-radius: 8px;
			padding: 30px;
			text-align: center;
			margin: 30px 0;
		}
		.verification-code-label {
			font-size: 14px;
			color: #ffffff;
			margin-bottom: 15px;
			text-transform: uppercase;
			letter-spacing: 2px;
			opacity: 0.9;
		}
		.verification-code-value {
			font-size: 42px;
			font-weight: bold;
			color: #ffffff;
			letter-spacing: 12px;
			font-family: "Courier New", Courier, monospace;
			background-color: rgba(255, 255, 255, 0.2);
			padding: 15px 20px;
			border-radius: 4px;
			display: inline-block;
		}
		.info-box {
			background-color: #f8f9fa;
			border-left: 4px solid <?php echo esc_attr( $accent_color ); ?>;
			padding: 15px 20px;
			margin: 20px 0;
			border-radius: 4px;
		}
		.info-box p {
			margin: 0;
		}
		.warning-box {
			background-color: #fff3cd;
			border-left: 4px solid #ffc107;
			padding: 15px 20px;
			margin: 20px 0;
			border-radius: 4px;
		}
		.warning-box strong {
			color: #856404;
		}
		.email-footer {
			background-color: #f8f9fa;
			padding: 30px;
			text-align: center;
			font-size: 14px;
			color: #666666;
			border-top: 1px solid #e1e1e1;
		}
		.email-footer p {
			margin: 5px 0;
		}
		.social-links {
			margin: 20px 0;
		}
		.social-links a {
			display: inline-block;
			margin: 0 10px;
			color: <?php echo esc_attr( $primary_color ); ?>;
			text-decoration: none;
		}
		.button {
			display: inline-block;
			padding: 12px 30px;
			background-color: <?php echo esc_attr( $accent_color ); ?>;
			color: #ffffff;
			text-decoration: none;
			border-radius: 4px;
			margin: 20px 0;
			font-weight: 600;
		}
		@media only screen and (max-width: 600px) {
			.email-wrapper {
				margin: 0;
				border-radius: 0;
			}
			.email-content {
				padding: 30px 20px;
			}
			.verification-code-value {
				font-size: 32px;
				letter-spacing: 8px;
			}
		}
	</style>
</head>
<body>
	<div class="email-wrapper">
		<div class="email-header">
			<?php if ( $logo_url ) : ?>
				<img src="<?php echo esc_url( $logo_url ); ?>" alt="<?php echo esc_attr( $site_name ); ?>">
			<?php endif; ?>
			<h1><?php echo esc_html( $site_name ); ?></h1>
		</div>
		
		<div class="email-content">
			<p class="greeting"><?php 
				// Translators: %s is the user's display name.
				echo esc_html( sprintf( __( 'Hello %s,', 'guard-dog' ), $user->display_name ) ); 
			?></p>
			
			<p><?php esc_html_e( 'We received a request to verify your identity. Please use the verification code below to complete your login.', 'guard-dog' ); ?></p>
			
			<div class="verification-code-container">
				<div class="verification-code-label">
					<?php esc_html_e( 'Your Verification Code', 'guard-dog' ); ?>
				</div>
				<div class="verification-code-value">
					<?php echo esc_html( $code ); ?>
				</div>
			</div>
			
			<div class="info-box">
				<p><strong><?php esc_html_e( 'Quick Tips:', 'guard-dog' ); ?></strong></p>
				<p><?php 
					echo esc_html( sprintf( 
						// Translators: %d is the expiration time in minutes.
						_n( 
							'• This code will expire in %d minute', 
							'• This code will expire in %d minutes', 
							$expiry_minutes, 
							'guard-dog' 
						), 
						$expiry_minutes 
					) ); 
				?></p>
				<p><?php esc_html_e( '• Enter the code exactly as shown above', 'guard-dog' ); ?></p>
				<p><?php esc_html_e( '• Do not share this code with anyone', 'guard-dog' ); ?></p>
			</div>
			
			<div class="warning-box">
				<p>
					<strong><?php esc_html_e( '⚠️ Security Notice:', 'guard-dog' ); ?></strong><br>
					<?php esc_html_e( 'If you did not attempt to log in, please ignore this email and consider changing your password immediately.', 'guard-dog' ); ?>
				</p>
			</div>
			
			<?php 
			// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
			// $support_url is a local variable in a template file, not a global variable
			// The Plugin Checker incorrectly flags local template variables as globals
			// Example: Add a custom support button
			$support_url = home_url( '/support/' );
			// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
			?>
			<p style="text-align: center;">
				<a href="<?php echo esc_url( $support_url ); ?>" class="button">
					<?php esc_html_e( 'Contact Support', 'guard-dog' ); ?>
				</a>
			</p>
		</div>
		
		<div class="email-footer">
			<p><strong><?php echo esc_html( $site_name ); ?></strong></p>
			
			<?php 
			// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
			// These are local variables in a template file, not global variables
			// The Plugin Checker incorrectly flags local template variables as globals
			// Example: Add social media links
			$facebook_url = get_theme_mod( 'facebook_url', '' );
			$twitter_url = get_theme_mod( 'twitter_url', '' );
			$instagram_url = get_theme_mod( 'instagram_url', '' );
			// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
			
			if ( $facebook_url || $twitter_url || $instagram_url ) : ?>
				<div class="social-links">
					<?php if ( $facebook_url ) : ?>
						<a href="<?php echo esc_url( $facebook_url ); ?>">Facebook</a>
					<?php endif; ?>
					<?php if ( $twitter_url ) : ?>
						<a href="<?php echo esc_url( $twitter_url ); ?>">Twitter</a>
					<?php endif; ?>
					<?php if ( $instagram_url ) : ?>
						<a href="<?php echo esc_url( $instagram_url ); ?>">Instagram</a>
					<?php endif; ?>
				</div>
			<?php endif; ?>
			
			<p><?php 
				printf( 
					// Translators: %s is the site URL.
					esc_html__( 'Visit us at %s', 'guard-dog' ), 
					'<a href="' . esc_url( home_url() ) . '">' . esc_html( home_url() ) . '</a>'
				); 
			?></p>
			
			<?php if ( $support_email ) : ?>
				<p><?php 
					printf( 
						// Translators: %s is the support email address.
						esc_html__( 'Need help? Contact us at %s', 'guard-dog' ), 
						'<a href="mailto:' . esc_attr( $support_email ) . '">' . esc_html( $support_email ) . '</a>'
					); 
				?></p>
			<?php endif; ?>
			
			<p style="font-size: 12px; color: #999; margin-top: 20px;">
				<?php esc_html_e( 'This is an automated security email. Please do not reply to this message.', 'guard-dog' ); ?>
			</p>
			
			<p style="font-size: 12px; color: #999;">
				<?php 
				printf( 
					// Translators: %1$s is the current year, %2$s is the site name.
					esc_html__( '© %1$s %2$s. All rights reserved.', 'guard-dog' ), 
					esc_html( gmdate( 'Y' ) ),
					esc_html( $site_name )
				); 
				?>
			</p>
		</div>
	</div>
</body>
</html>

