<?php
/**
 * Shared email wrapper view.
 *
 * @var string               $content
 * @var string               $title
 * @var string               $badge
 * @var string               $preheader
 * @var string               $footer
 * @var string               $footer_brand
 * @var string               $logo_url
 * @var string               $site_name
 * @var array<string,string> $config
 */

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

use WP_PowerSuite\Email\EmailComponents;
use WP_PowerSuite\Email\EmailDesign;

$body_bg         = $config['body_bg'];
$content_bg      = $config['content_bg'];
$content_color   = $config['content_color'];
$footer_color    = $config['footer_content_color'];
$font_family     = $config['font_family'];
$accent          = $config['accent_color'];
$max_width       = EmailDesign::MAX_WIDTH;
$lang            = esc_attr( get_bloginfo( 'language' ) ?: 'en' );
?>
<!DOCTYPE html>
<html lang="<?php echo $lang; ?>" xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="x-apple-disable-message-reformatting">
	<meta name="format-detection" content="telephone=no, date=no, address=no, email=no">
	<?php if ( $title !== '' ) : ?>
	<title><?php echo esc_html( $title ); ?></title>
	<?php endif; ?>
	<!--[if mso]>
	<noscript><xml><o:OfficeDocumentSettings><o:PixelsPerInch>96</o:PixelsPerInch></o:OfficeDocumentSettings></xml></noscript>
	<![endif]-->
	<style type="text/css">
		#outlook a { padding: 0; }
		body { margin: 0; padding: 0; width: 100% !important; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
		table, td { border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; }
		img { border: 0; height: auto; line-height: 100%; outline: none; text-decoration: none; max-width: 100%; }
		.wpps-email-body a { color: <?php echo esc_attr( $accent ); ?>; text-decoration: underline; }
		<?php echo EmailDesign::responsiveStyles(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
	</style>
</head>
<body style="margin:0;padding:0;background-color:<?php echo esc_attr( $body_bg ); ?>;font-family:<?php echo esc_attr( $font_family ); ?>;font-size:<?php echo esc_attr( EmailDesign::FONT_BODY ); ?>;line-height:1.55;color:<?php echo esc_attr( $content_color ); ?>;">
	<?php if ( $preheader !== '' ) : ?>
	<div style="display:none;max-height:0;overflow:hidden;mso-hide:all;"><?php echo esc_html( $preheader ); ?></div>
	<?php endif; ?>
	<!--[if mso]><table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="<?php echo esc_attr( $body_bg ); ?>"><![endif]-->
	<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="width:100%;background-color:<?php echo esc_attr( $body_bg ); ?>;">
		<tr>
			<td class="wpps-email-outer-pad" align="center" style="padding:<?php echo esc_attr( EmailDesign::PAD_OUTER_DESKTOP ); ?>;">
				<!--[if (gte mso 9)|(IE)]><table role="presentation" width="<?php echo (int) $max_width; ?>" align="center" cellpadding="0" cellspacing="0" border="0"><tr><td><![endif]-->
				<table role="presentation" class="wpps-email-shell" width="100%" cellspacing="0" cellpadding="0" style="width:100%;max-width:<?php echo (int) $max_width; ?>px;margin:0 auto;">
					<tr>
						<td>
							<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="width:100%;background-color:<?php echo esc_attr( $content_bg ); ?>;border:1px solid <?php echo esc_attr( EmailDesign::BORDER_DEFAULT ); ?>;border-radius:<?php echo esc_attr( EmailDesign::RADIUS ); ?>;overflow:hidden;">
								<?php if ( $badge !== '' || $title !== '' || $logo_url !== '' || $site_name !== '' ) : ?>
								<tr>
									<td class="wpps-email-inner-pad" style="padding:<?php echo esc_attr( EmailDesign::PAD_CONTENT ); ?>;border-bottom:1px solid <?php echo esc_attr( EmailDesign::BORDER_DEFAULT ); ?>;">
										<?php if ( $logo_url !== '' ) : ?>
										<?php echo EmailComponents::logo( $logo_url, $site_name ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
										<?php elseif ( $site_name !== '' ) : ?>
										<p style="margin:0 0 8px;font-family:<?php echo esc_attr( $font_family ); ?>;font-size:15px;font-weight:700;color:<?php echo esc_attr( $content_color ); ?>;letter-spacing:-0.01em;"><?php echo esc_html( $site_name ); ?></p>
										<?php endif; ?>
										<?php if ( $badge !== '' ) : ?>
										<p style="margin:0 0 8px;"><span style="display:inline-block;padding:3px 8px;font-size:11px;font-weight:600;letter-spacing:0.04em;text-transform:uppercase;color:#92400e;background:#fffbeb;border:1px solid #fcd34d;border-radius:4px;"><?php echo esc_html( $badge ); ?></span></p>
										<?php endif; ?>
										<?php if ( $title !== '' ) : ?>
										<h1 class="wpps-email-heading" style="margin:0;font-family:<?php echo esc_attr( $font_family ); ?>;font-size:<?php echo esc_attr( EmailDesign::FONT_HEADING ); ?>;font-weight:700;line-height:1.35;color:<?php echo esc_attr( $content_color ); ?>;"><?php echo esc_html( $title ); ?></h1>
										<?php endif; ?>
									</td>
								</tr>
								<?php endif; ?>
								<tr>
									<td class="wpps-email-inner-pad wpps-email-body" style="padding:<?php echo esc_attr( EmailDesign::PAD_CONTENT ); ?>;">
										<?php echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted module HTML ?>
									</td>
								</tr>
								<?php if ( $footer !== '' || $footer_brand !== '' ) : ?>
								<tr>
									<td style="padding:<?php echo esc_attr( EmailDesign::PAD_FOOTER ); ?>;background-color:<?php echo esc_attr( EmailDesign::HIGHLIGHT_BG ); ?>;border-top:1px solid <?php echo esc_attr( EmailDesign::BORDER_DEFAULT ); ?>;text-align:center;">
										<?php if ( $footer !== '' ) : ?>
										<div style="margin:0 0 8px;font-family:<?php echo esc_attr( $font_family ); ?>;font-size:<?php echo esc_attr( EmailDesign::FONT_SMALL ); ?>;line-height:1.5;color:<?php echo esc_attr( $footer_color ); ?>;"><?php echo wp_kses_post( $footer ); ?></div>
										<?php endif; ?>
										<?php if ( $footer_brand !== '' ) : ?>
										<p style="margin:0;font-family:<?php echo esc_attr( $font_family ); ?>;font-size:<?php echo esc_attr( EmailDesign::FONT_SMALL ); ?>;line-height:1.45;color:<?php echo esc_attr( $footer_color ); ?>;"><?php echo esc_html( $footer_brand ); ?></p>
										<?php endif; ?>
									</td>
								</tr>
								<?php endif; ?>
							</table>
						</td>
					</tr>
				</table>
				<!--[if (gte mso 9)|(IE)]></td></tr></table><![endif]-->
			</td>
		</tr>
	</table>
	<!--[if mso]></td></tr></table><![endif]-->
</body>
</html>
