<?php
/**
 * Email Header
 *
 * @author  Automattic
 * @package Sensei/Templates/Emails
 * @version 2.0.0
 */

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

// Ignore undefined variables - they are provided by the $sensei_email_data global.
// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable

// Get data for email content
global $sensei_email_data;
extract( $sensei_email_data );

// Load colours
$bg = '#f5f5f5';
if ( isset( Sensei()->settings->settings['email_background_color'] ) && '' != Sensei()->settings->settings['email_background_color'] ) {
	$bg = Sensei()->settings->settings['email_background_color'];
}

$body = '#fdfdfd';
if ( isset( Sensei()->settings->settings['email_body_background_color'] ) && '' != Sensei()->settings->settings['email_body_background_color'] ) {
	$body = Sensei()->settings->settings['email_body_background_color'];
}

$base = '#557da1';
if ( isset( Sensei()->settings->settings['email_base_color'] ) && '' != Sensei()->settings->settings['email_base_color'] ) {
	$base = Sensei()->settings->settings['email_base_color'];
}
$base_text = sensei_light_or_dark( $base, '#202020', '#ffffff' );

$text = '#505050';
if ( isset( Sensei()->settings->settings['email_text_color'] ) && '' != Sensei()->settings->settings['email_text_color'] ) {
	$text = Sensei()->settings->settings['email_text_color'];
}

$bg_darker_10    = sensei_hex_darker( $bg, 10 );
$base_lighter_20 = sensei_hex_lighter( $base, 20 );
$text_lighter_20 = sensei_hex_lighter( $text, 20 );

// For gmail compatibility, including CSS styles in head/body are stripped out therefore styles need to be inline. These variables contain rules which are added to the template inline. !important; is a gmail hack to prevent styles being stripped if it doesn't like something.
$wrapper            = '
	background-color: ' . esc_attr( $bg ) . ';
	width:100%;
	-webkit-text-size-adjust:none !important;
	margin:0;
	padding: 70px 0 70px 0;
';
$template_container = '
	-webkit-box-shadow:0 0 0 3px rgba(0,0,0,0.025) !important;
	box-shadow:0 0 0 3px rgba(0,0,0,0.025) !important;
	-webkit-border-radius:6px !important;
	border-radius:6px !important;
	background-color: ' . esc_attr( $body ) . ";
	border: 1px solid $bg_darker_10;
	-webkit-border-radius:6px !important;
	border-radius:6px !important;
";
$template_header    = '
	background-color: ' . esc_attr( $base ) . ";
	color: $base_text;
	-webkit-border-top-left-radius:6px !important;
	-webkit-border-top-right-radius:6px !important;
	border-top-left-radius:6px !important;
	border-top-right-radius:6px !important;
	border-bottom: 0;
	font-family:Arial;
	font-weight:bold;
	line-height:100%;
	vertical-align:middle;
";
$body_content       = '
	background-color: ' . esc_attr( $body ) . ';
	-webkit-border-radius:6px !important;
	border-radius:6px !important;
';
$body_content_inner = "
	color: $text_lighter_20;
	font-family:Arial;
	font-size:14px;
	line-height:150%;
	text-align:left;
";
$header_content_h1  = '
	color: ' . esc_attr( $base_text ) . ";
	margin:0;
	padding: 28px 24px;
	text-shadow: 0 1px 0 $base_lighter_20;
	display:block;
	font-family:Arial;
	font-size:30px;
	font-weight:bold;
	text-align:left;
	line-height: 150%;
";
?>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title><?php echo esc_html( get_bloginfo( 'name' ) ); ?></title>
	</head>
	<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0">
		<div style="<?php echo esc_attr( $wrapper ); ?>">
			<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
				<tr>
					<td align="center" valign="top">
						<?php
						if ( isset( Sensei()->settings->settings['email_header_image'] ) && '' != Sensei()->settings->settings['email_header_image'] ) {
							$img = Sensei()->settings->settings['email_header_image'];
							echo '<p style="margin-top:0;"><img src="' . esc_url( $img ) . '" alt="' . esc_attr( get_bloginfo( 'name' ) ) . '" /></p>';
						}
						?>
						<table border="0" cellpadding="0" cellspacing="0" width="600" id="template_container" style="<?php echo esc_attr( $template_container ); ?>">
							<tr>
								<td align="center" valign="top">
									<!-- Header -->
									<table border="0" cellpadding="0" cellspacing="0" width="600" id="template_header" style="<?php echo esc_attr( $template_header ); ?>" bgcolor="<?php echo esc_attr( $base ); ?>">
										<tr>
											<td>
												<h1 style="<?php echo esc_attr( $header_content_h1 ); ?>"><?php echo esc_html( $heading ); ?></h1>

											</td>
										</tr>
									</table>
									<!-- End Header -->
								</td>
							</tr>
							<tr>
								<td align="center" valign="top">
									<!-- Body -->
									<table border="0" cellpadding="0" cellspacing="0" width="600" id="template_body">
										<tr>
											<td valign="top" style="<?php echo esc_attr( $body_content ); ?>">
												<!-- Content -->
												<table border="0" cellpadding="20" cellspacing="0" width="100%">
													<tr>
														<td valign="top">
															<div style="<?php echo esc_attr( $body_content_inner ); ?>">
