<?php
/**
 * Email Report Template
 *
 * Variables: $sections_data, $date_range, $color, $company, $logo_url, $footer
 *
 * @package EmailReports
 * @since 1.0.0
 */

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

require_once __DIR__ . '/partials/email-partials.php';

$date_label = sprintf(
	/* translators: 1: from date, 2: to date */
	__( '%1$s to %2$s', 'wp-powersuite' ),
	$date_range['from'],
	$date_range['to']
);
$dashboard_url = admin_url( 'admin.php?page=powersuite' );
$site_url      = home_url();
$brand_color   = esc_attr( $color );
?>
<!DOCTYPE html>
<html lang="<?php echo esc_attr( get_bloginfo( 'language' ) ); ?>" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<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">
	<title><?php echo esc_html( $company ); ?> – <?php esc_html_e( 'Site Report', 'wp-powersuite' ); ?></title>
	<!--[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%; font-size: 14px; line-height: 1.55; }
		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; -ms-interpolation-mode: bicubic; max-width: 100%; }
		a { color: <?php echo $brand_color; ?>; }
		@media only screen and (max-width: 620px) {
			.wpps-er-shell-pad { padding: 0 !important; }
			.wpps-er-shell { width: 100% !important; max-width: 100% !important; }
			.wpps-er-card { border-radius: 0 !important; border-left: 0 !important; border-right: 0 !important; }
			.wpps-er-header-pad { padding: 22px 18px !important; }
			.wpps-er-block-pad { padding: 18px 16px !important; }
			.wpps-er-title { font-size: 17px !important; }
			.wpps-er-company { font-size: 18px !important; }
			.wpps-er-btn-link { display: block !important; width: 100% !important; box-sizing: border-box !important; text-align: center !important; }
		}
	</style>
</head>
<body style="margin:0;padding:0;background-color:#f3f4f6;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',sans-serif;font-size:14px;line-height:1.55;color:#374151;">
	<div style="display:none;max-height:0;overflow:hidden;mso-hide:all;">
		<?php echo esc_html( sprintf( __( 'Site report for %1$s (%2$s)', 'wp-powersuite' ), $company, $date_label ) ); ?>
	</div>
	<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="width:100%;background-color:#f3f4f6;">
		<tr>
			<td class="wpps-er-shell-pad" align="center" style="padding:24px 16px;">
				<!--[if (gte mso 9)|(IE)]><table role="presentation" width="600" align="center" cellpadding="0" cellspacing="0" border="0"><tr><td><![endif]-->
				<table role="presentation" class="wpps-er-shell" width="100%" cellspacing="0" cellpadding="0" style="width:100%;max-width:600px;margin:0 auto;">
					<tr>
						<td>
							<table role="presentation" class="wpps-er-card" width="100%" cellspacing="0" cellpadding="0" style="width:100%;background-color:#ffffff;border:1px solid #e5e7eb;border-radius:10px;overflow:hidden;">
								<tr>
									<td class="wpps-er-header-pad" style="padding:24px 22px;background-color:<?php echo $brand_color; ?>;text-align:center;">
										<?php if ( ! empty( $logo_url ) ) : ?>
											<?php echo \WP_PowerSuite\Email\EmailComponents::logo( $logo_url, $company, [ 'centered' => true, 'margin' => '0 0 10px' ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
										<?php endif; ?>
										<h1 class="wpps-er-company" style="margin:0;font-size:18px;line-height:1.3;font-weight:700;color:#ffffff;letter-spacing:-0.01em;"><?php echo esc_html( $company ); ?></h1>
									</td>
								</tr>
								<tr>
									<td class="wpps-er-block-pad" style="padding:22px 22px 18px;text-align:center;border-bottom:1px solid #e5e7eb;">
										<h2 class="wpps-er-title" style="margin:0 0 6px;font-size:18px;line-height:1.35;font-weight:700;color:#374151;"><?php esc_html_e( 'Site Report', 'wp-powersuite' ); ?></h2>
										<p style="margin:0;font-size:13px;line-height:1.5;color:#6b7280;"><?php echo esc_html( $date_label ); ?></p>
									</td>
								</tr>
								<?php foreach ( $sections_data as $section_id => $section ) : ?>
									<tr>
									<td class="wpps-er-block-pad" style="padding:20px 22px;border-bottom:1px solid #e5e7eb;">
										<p style="margin:0 0 12px;font-size:11px;line-height:1.4;font-weight:700;color:<?php echo $brand_color; ?>;text-transform:uppercase;letter-spacing:0.06em;">
												<?php echo esc_html( $section['title'] ); ?>
											</p>
											<?php
											$branding = [ 'primary_color' => $color ];
											$data     = $section['data'];
											$template = __DIR__ . '/sections/' . $section_id . '.php';
											if ( file_exists( $template ) ) {
												include $template;
											} else {
												echo '<p style="color:#646970;margin:0;">' . esc_html__( 'No data available.', 'wp-powersuite' ) . '</p>';
											}
											?>
										</td>
									</tr>
								<?php endforeach; ?>
								<tr>
									<td class="wpps-er-block-pad" style="padding:20px 22px 22px;text-align:center;">
										<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="width:100%;">
											<tr>
												<td align="center" style="border-radius:8px;background-color:<?php echo $brand_color; ?>;">
													<a class="wpps-er-btn-link" href="<?php echo esc_url( $dashboard_url ); ?>" style="display:inline-block;padding:11px 22px;font-size:14px;line-height:1.4;font-weight:600;color:#ffffff !important;text-decoration:none;border-radius:8px;">
														<?php esc_html_e( 'View Dashboard', 'wp-powersuite' ); ?>
													</a>
												</td>
											</tr>
										</table>
									</td>
								</tr>
								<tr>
									<td class="wpps-er-block-pad" style="padding:16px 22px 20px;background-color:#f9fafb;text-align:center;">
										<?php if ( ! empty( $footer ) ) : ?>
											<div style="margin:0 0 12px;font-size:13px;line-height:1.6;color:#646970;"><?php echo wp_kses_post( $footer ); ?></div>
										<?php endif; ?>
										<p style="margin:0;font-size:12px;line-height:1.5;color:#787c82;word-break:break-all;">
											<a href="<?php echo esc_url( $site_url ); ?>" style="color:<?php echo $brand_color; ?>;text-decoration:none;"><?php echo esc_html( $site_url ); ?></a>
										</p>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
				<!--[if (gte mso 9)|(IE)]></td></tr></table><![endif]-->
			</td>
		</tr>
	</table>
</body>
</html>
