<?php
/**
 * PDF receipt HTML document template.
 *
 * Variables in scope (passed by Receipt_PDF_Generator::build_html()):
 *
 * @var \DonationRouter\PayPal_Account $account
 * @var string                                           $receipt_number
 * @var string                                           $donor_name
 * @var string                                           $donor_email
 * @var string                                           $amount_display
 * @var string                                           $form_title
 * @var string                                           $donation_date
 * @var string                                           $tax_statement
 *
 * @since   1.0.0
 * @package DonationRouter
 */

declare( strict_types=1 );

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

/*
 * This template is rendered to an HTML string and passed to dompdf for
 * server-side PDF rendering. It is NEVER served to a browser, so
 * wp_enqueue_style() / wp_enqueue_script() do not apply — dompdf parses
 * its own CSS from the document and has no access to the WordPress
 * stylesheet registry. Inline <style> is the supported pattern for dompdf.
 */
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<?php // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet -- dompdf-only template; CSS cannot be enqueued. ?>
<style>
	/* Flat, minimal layout on the WordPress core colour palette. */
	body { font-family: DejaVu Sans, sans-serif; font-size: 13px; color: #1d2327; margin: 40px; }
	h1   { font-size: 20px; color: #1d2327; border-bottom: 2px solid #2271b1; padding-bottom: 8px; }
	h2   { font-size: 14px; color: #50575e; margin-top: 24px; }
	table { width: 100%; border-collapse: collapse; margin-top: 8px; }
	td    { padding: 7px 10px; border-bottom: 1px solid #dcdcde; vertical-align: top; }
	td:first-child { font-weight: bold; width: 40%; color: #50575e; }
	.statement { margin-top: 24px; padding: 12px; background: #f6f7f7; border-left: 3px solid #2271b1; font-size: 12px; }
	.footer    { margin-top: 32px; font-size: 11px; color: #8c8f94; border-top: 1px solid #dcdcde; padding-top: 8px; }
	.receipt-number { font-size: 12px; color: #646970; text-align: right; margin-bottom: 16px; }
</style>
</head>
<body>
	<h1><?php echo esc_html( $account->legal_entity_name ); ?></h1>
	<?php if ( $receipt_number ) : ?>
	<div class="receipt-number"><?php echo esc_html__( 'Receipt No:', 'alamin-donation-router' ); ?> <strong><?php echo esc_html( $receipt_number ); ?></strong></div>
	<?php endif; ?>

	<h2><?php esc_html_e( 'Donation Details', 'alamin-donation-router' ); ?></h2>
	<table>
	<tr><td><?php esc_html_e( 'Date', 'alamin-donation-router' ); ?></td><td><?php echo esc_html( $donation_date ); ?></td></tr>
	<tr><td><?php esc_html_e( 'Donor', 'alamin-donation-router' ); ?></td><td><?php echo esc_html( $donor_name ); ?></td></tr>
	<?php if ( $donor_email ) : ?>
	<tr><td><?php esc_html_e( 'Email', 'alamin-donation-router' ); ?></td><td><?php echo esc_html( $donor_email ); ?></td></tr>
	<?php endif; ?>
	<?php if ( $form_title ) : ?>
	<tr><td><?php esc_html_e( 'Fund', 'alamin-donation-router' ); ?></td><td><?php echo esc_html( $form_title ); ?></td></tr>
	<?php endif; ?>
	<tr><td><?php esc_html_e( 'Amount', 'alamin-donation-router' ); ?></td><td><strong><?php echo esc_html( $amount_display ); ?></strong></td></tr>
	</table>

	<h2><?php esc_html_e( 'Receiving Organization', 'alamin-donation-router' ); ?></h2>
	<table>
	<tr><td><?php esc_html_e( 'Organization', 'alamin-donation-router' ); ?></td><td><?php echo esc_html( $account->legal_entity_name ); ?></td></tr>
	<?php if ( $account->legal_entity_tax_id ) : ?>
	<tr><td><?php esc_html_e( 'Tax / Registration ID', 'alamin-donation-router' ); ?></td><td><?php echo esc_html( $account->legal_entity_tax_id ); ?></td></tr>
	<?php endif; ?>
	<?php if ( $account->legal_entity_address ) : ?>
	<tr><td><?php esc_html_e( 'Address', 'alamin-donation-router' ); ?></td><td><?php echo esc_html( $account->legal_entity_address ); ?></td></tr>
	<?php endif; ?>
	<tr><td><?php esc_html_e( 'Country', 'alamin-donation-router' ); ?></td><td><?php echo esc_html( $account->account_country ); ?></td></tr>
	</table>

	<?php if ( $tax_statement ) : ?>
	<div class="statement"><?php echo wp_kses_post( $tax_statement ); ?></div>
	<?php endif; ?>

	<div class="footer">
		<?php
		printf(
			/* translators: %s: site name */
			esc_html__( 'Generated by %s', 'alamin-donation-router' ),
			esc_html( get_bloginfo( 'name' ) )
		);
		?>
	&nbsp;&mdash;&nbsp;<?php echo esc_html( gmdate( 'Y-m-d H:i:s' ) ); ?> UTC
	</div>
</body>
</html>
