<?php
/**
 * Warranty Certificate PDF Template
 *
 * @package WarrantyCart
 * @version 1.0.0
 */

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

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound,WordPress.WP.GlobalVariablesOverride.Prohibited -- Template variables are local scope and don't need prefixing

$order = $args['order'] ?? null;
if ( ! $order ) {
	return;
}

/**
 * Filter PDF certificate arguments
 *
 * @param array $args Template arguments.
 * @param WC_Order $order Order object.
 */
$args = \apply_filters( 'warranty_cart_pdf_certificate_args', $args, $order );
?>

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title><?php esc_html_e( 'Warranty Certificate', 'warranty-cart' ); ?></title>
	<style>
		body { font-family: Arial, sans-serif; margin: 40px; }
		.header { text-align: center; border-bottom: 2px solid #007cba; padding-bottom: 20px; margin-bottom: 30px; }
		.warranty-info { margin: 20px 0; }
		.warranty-info table { width: 100%; border-collapse: collapse; }
		.warranty-info th, .warranty-info td { padding: 10px; text-align: left; border: 1px solid #ddd; }
		.warranty-info th { background-color: #f5f5f5; }
		.footer { margin-top: 40px; padding-top: 20px; border-top: 1px solid #ddd; font-size: 12px; color: #666; }
	</style>
</head>
<body>
	<?php
	/**
	 * Action before PDF certificate header
	 *
	 * @param WC_Order $order Order object.
	 */
	\do_action( 'warranty_cart_pdf_certificate_before_header', $order );
	?>
	<div class="header">
		<h1><?php \esc_html_e( 'Warranty Certificate', 'warranty-cart' ); ?></h1>
		<p><?php \esc_html_e( 'This document certifies your warranty coverage', 'warranty-cart' ); ?></p>
	</div>
	<?php
	/**
	 * Action after PDF certificate header
	 *
	 * @param WC_Order $order Order object.
	 */
	\do_action( 'warranty_cart_pdf_certificate_after_header', $order );
	?>

	<div class="warranty-info">
		<h2><?php esc_html_e( 'Order Information', 'warranty-cart' ); ?></h2>
		<table>
			<tr>
				<th><?php esc_html_e( 'Order Number', 'warranty-cart' ); ?></th>
				<td><?php echo esc_html( $order->get_order_number() ); ?></td>
			</tr>
			<tr>
				<th><?php esc_html_e( 'Order Date', 'warranty-cart' ); ?></th>
				<td><?php echo esc_html( $order->get_date_created()->date_i18n( get_option( 'date_format' ) ) ); ?></td>
			</tr>
			<tr>
				<th><?php esc_html_e( 'Customer', 'warranty-cart' ); ?></th>
				<td><?php echo esc_html( $order->get_formatted_billing_full_name() ); ?></td>
			</tr>
			<tr>
				<th><?php esc_html_e( 'Email', 'warranty-cart' ); ?></th>
				<td><?php echo esc_html( $order->get_billing_email() ); ?></td>
			</tr>
		</table>
	</div>

	<div class="warranty-info">
		<h2><?php esc_html_e( 'Warranty Products', 'warranty-cart' ); ?></h2>
		<table>
			<thead>
				<tr>
					<th><?php esc_html_e( 'Product', 'warranty-cart' ); ?></th>
					<th><?php esc_html_e( 'Quantity', 'warranty-cart' ); ?></th>
					<th><?php esc_html_e( 'Price', 'warranty-cart' ); ?></th>
				</tr>
			</thead>
			<tbody>
				<?php foreach ( $order->get_items() as $item ) : ?>
					<tr>
						<td><?php echo \esc_html( $item->get_name() ); ?></td>
						<td><?php echo \esc_html( $item->get_quantity() ); ?></td>
						<td><?php echo \wp_kses_post( \wc_price( $item->get_total() ) ); ?></td>
					</tr>
				<?php endforeach; ?>
			</tbody>
			<tfoot>
				<tr>
					<th colspan="2"><?php \esc_html_e( 'Total', 'warranty-cart' ); ?></th>
					<td><?php echo \wp_kses_post( \wc_price( $order->get_total() ) ); ?></td>
				</tr>
			</tfoot>
		</table>
	</div>

	<div class="warranty-info">
		<h2><?php esc_html_e( 'Warranty Terms', 'warranty-cart' ); ?></h2>
		<p><?php esc_html_e( 'This warranty certificate is valid for the products purchased. Please keep this document safe as proof of your warranty coverage.', 'warranty-cart' ); ?></p>
		<p><?php esc_html_e( 'For warranty claims, please contact our support team with this certificate.', 'warranty-cart' ); ?></p>
	</div>

	<div class="footer">
		<p><?php esc_html_e( 'Generated on', 'warranty-cart' ); ?> <?php echo esc_html( current_time( get_option( 'date_format' ) ) ); ?></p>
		<p><?php esc_html_e( 'Warranty Cart Plugin', 'warranty-cart' ); ?></p>
	</div>
</body>
</html>
// phpcs:enable
