<?php
/**
 * Shared render helpers for Email Reports HTML templates.
 *
 * @package EmailReports
 */

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

/**
 * Render a full-width metric card (mobile-safe, no column splits).
 */
function wpps_er_render_stat_card( string $value, string $label, string $color = '#2271b1' ): void {
	$color = esc_attr( $color );
	?>
	<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="width:100%;margin:0 0 10px;border-collapse:separate;border-spacing:0;">
		<tr>
			<td style="padding:18px 16px;background-color:#f6f7f7;border:1px solid #e8e8e8;border-radius:8px;text-align:center;">
				<div style="font-size:24px;line-height:1.1;font-weight:700;color:<?php echo $color; ?>;margin:0 0 6px;"><?php echo esc_html( $value ); ?></div>
				<div style="font-size:11px;line-height:1.4;color:#646970;text-transform:uppercase;letter-spacing:0.06em;margin:0;"><?php echo esc_html( $label ); ?></div>
			</td>
		</tr>
	</table>
	<?php
}

/**
 * Render a stacked list row (primary text, optional secondary line below).
 *
 * @param array{color?:string,secondary_color?:string} $opts
 */
function wpps_er_render_list_item( string $primary, string $secondary = '', array $opts = [] ): void {
	$secondary_color = esc_attr( $opts['secondary_color'] ?? '#646970' );
	$primary_color   = esc_attr( $opts['color'] ?? '#1d2327' );
	?>
	<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="width:100%;margin:0 0 8px;border-collapse:separate;border-spacing:0;">
		<tr>
			<td style="padding:14px 16px;background-color:#ffffff;border:1px solid #e8e8e8;border-radius:8px;">
				<div style="font-size:14px;line-height:1.45;color:<?php echo $primary_color; ?>;font-weight:500;word-break:break-word;margin:0;"><?php echo esc_html( $primary ); ?></div>
				<?php if ( $secondary !== '' ) : ?>
					<div style="font-size:12px;line-height:1.4;color:<?php echo $secondary_color; ?>;margin:6px 0 0;word-break:break-word;"><?php echo esc_html( $secondary ); ?></div>
				<?php endif; ?>
			</td>
		</tr>
	</table>
	<?php
}

/**
 * Render monospace value inside a list item card.
 */
function wpps_er_render_code_list_item( string $code, string $secondary = '', array $opts = [] ): void {
	$secondary_color = esc_attr( $opts['secondary_color'] ?? '#646970' );
	?>
	<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="width:100%;margin:0 0 8px;border-collapse:separate;border-spacing:0;">
		<tr>
			<td style="padding:14px 16px;background-color:#ffffff;border:1px solid #e8e8e8;border-radius:8px;">
				<div style="font-size:12px;line-height:1.5;color:#1d2327;background-color:#f0f0f1;padding:8px 10px;border-radius:6px;word-break:break-all;margin:0;font-family:Consolas,Monaco,'Courier New',monospace;"><?php echo esc_html( $code ); ?></div>
				<?php if ( $secondary !== '' ) : ?>
					<div style="font-size:12px;line-height:1.4;color:<?php echo $secondary_color; ?>;margin:8px 0 0;"><?php echo esc_html( $secondary ); ?></div>
				<?php endif; ?>
			</td>
		</tr>
	</table>
	<?php
}

/**
 * Section subheading inside a report block.
 */
function wpps_er_render_subheading( string $text ): void {
	?>
	<p style="margin:20px 0 10px;font-size:13px;line-height:1.4;color:#1d2327;font-weight:600;text-transform:uppercase;letter-spacing:0.04em;"><?php echo esc_html( $text ); ?></p>
	<?php
}
