<?php
/**
 * Email report HTML template.
 * Variables: $site_name, $period, $summary (array|null), $top_posts (array)
 *
 * @package Relatedly
 */

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
defined( 'ABSPATH' ) || exit;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?php echo esc_html( $site_name ); ?> — Relatedly Report</title>
<style>
body { font-family: Arial, sans-serif; font-size: 14px; color: #333; background: #f5f5f5; margin: 0; padding: 0; }
.wrap { max-width: 600px; margin: 30px auto; background: #fff; border-radius: 6px; overflow: hidden; }
.header { background: #0073aa; color: #fff; padding: 24px 30px; }
.header h1 { margin: 0; font-size: 20px; }
.header p { margin: 4px 0 0; font-size: 13px; opacity: 0.85; }
.body { padding: 24px 30px; }
table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
th { background: #f0f0f0; text-align: left; padding: 8px 10px; font-size: 12px; text-transform: uppercase; }
td { padding: 8px 10px; border-bottom: 1px solid #eee; }
.footer { background: #f5f5f5; padding: 16px 30px; font-size: 12px; color: #999; text-align: center; }
</style>
</head>
<body>
<div class="wrap">
	<div class="header">
		<h1><?php echo esc_html( $site_name ); ?></h1>
		<p><?php echo esc_html__( 'Relatedly Performance Report', 'relatedly' ); ?> &mdash; <?php echo esc_html( $period ); ?></p>
	</div>
	<div class="body">

		<?php if ( $summary ) : ?>
		<h2><?php esc_html_e( 'Summary', 'relatedly' ); ?></h2>
		<table>
			<tr><th><?php esc_html_e( 'Metric', 'relatedly' ); ?></th><th><?php esc_html_e( 'Value', 'relatedly' ); ?></th></tr>
			<tr><td><?php esc_html_e( 'Total Clicks', 'relatedly' ); ?></td><td><?php echo esc_html( number_format_i18n( $summary['total_clicks'] ) ); ?></td></tr>
			<tr><td><?php esc_html_e( 'Total Impressions', 'relatedly' ); ?></td><td><?php echo esc_html( number_format_i18n( $summary['total_impressions'] ) ); ?></td></tr>
			<tr><td><?php esc_html_e( 'Click-Through Rate', 'relatedly' ); ?></td><td><?php echo esc_html( $summary['ctr'] . '%' ); ?></td></tr>
		</table>
		<?php endif; ?>

		<?php if ( ! empty( $top_posts ) ) : ?>
		<h2><?php esc_html_e( 'Top Clicked Posts', 'relatedly' ); ?></h2>
		<table>
			<tr>
				<th><?php esc_html_e( 'Post', 'relatedly' ); ?></th>
				<th><?php esc_html_e( 'Clicks', 'relatedly' ); ?></th>
			</tr>
			<?php foreach ( $top_posts as $row ) : ?>
			<tr>
				<td><a href="<?php echo esc_url( get_permalink( $row['post_id'] ) ); ?>"><?php echo esc_html( $row['title'] ); ?></a></td>
				<td><?php echo esc_html( number_format_i18n( $row['clicks'] ) ); ?></td>
			</tr>
			<?php endforeach; ?>
		</table>
		<?php endif; ?>

	</div>
	<div class="footer">
		<?php
		printf(
			/* translators: %s: settings page URL */
			esc_html__( 'Sent by Relatedly on %1$s. Manage reports in %2$s.', 'relatedly' ),
			esc_html( get_bloginfo( 'name' ) ),
			'<a href="' . esc_url( admin_url( 'admin.php?page=relatedly&tab=email' ) ) . '">' . esc_html__( 'Settings', 'relatedly' ) . '</a>'
		);
		?>
	</div>
</div>
</body>
</html>
