<?php
/**
 * Warranty Reminder Email Template
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/warranty-reminder.php
 *
 * @package WarrantyCart
 * @var WC_Order         $order              The order object.
 * @var string           $expiration_date    The warranty expiration date.
 * @var int              $days_remaining     Days until expiration.
 * @var string           $email_heading      The email heading.
 * @var string           $additional_content Additional content.
 * @var bool             $sent_to_admin      Whether sent to admin.
 * @var bool             $plain_text         Whether plain text.
 * @var WarrantyReminder $email              The email object.
 */

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound,WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Email template variables and WooCommerce hooks are local scope and don't need prefixing

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

/*
 * @hooked WC_Emails::email_header() Output the email header
 */
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

<?php /* translators: %s: Customer first name */ ?>
<p><?php printf( esc_html__( 'Dear %s,', 'warranty-cart' ), esc_html( $order->get_billing_first_name() ) ); ?></p>

<p><?php esc_html_e( 'This is a friendly reminder about your warranty coverage.', 'warranty-cart' ); ?></p>

<div style="background-color: #f8f8f8; padding: 20px; margin: 20px 0; border-left: 4px solid #007cba;">
	<h3 style="margin-top: 0; color: #007cba;"><?php esc_html_e( 'Warranty Information', 'warranty-cart' ); ?></h3>
	<p style="margin-bottom: 10px;"><strong><?php esc_html_e( 'Order Number:', 'warranty-cart' ); ?></strong> #<?php echo esc_html( $order->get_order_number() ); ?></p>
	<p style="margin-bottom: 10px;"><strong><?php esc_html_e( 'Expiration Date:', 'warranty-cart' ); ?></strong> <?php echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( $expiration_date ) ) ); ?></p>
	<p style="margin-bottom: 0;"><strong><?php esc_html_e( 'Days Remaining:', 'warranty-cart' ); ?></strong> <?php echo esc_html( $days_remaining ); ?> <?php esc_html_e( 'days', 'warranty-cart' ); ?></p>
</div>

<p><?php esc_html_e( 'Your warranty is approaching its expiration date. To ensure continued coverage, please consider renewing your warranty or contacting us for assistance.', 'warranty-cart' ); ?></p>

<h3><?php esc_html_e( 'Covered Products', 'warranty-cart' ); ?></h3>

<div style="margin-bottom: 40px;">
	<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1">
		<thead>
			<tr>
				<th class="td" scope="col" style="text-align: left;"><?php esc_html_e( 'Product', 'warranty-cart' ); ?></th>
				<th class="td" scope="col" style="text-align: left;"><?php esc_html_e( 'Warranty Period', 'warranty-cart' ); ?></th>
			</tr>
		</thead>
		<tbody>
			<?php
			foreach ( $order->get_items() as $item_id => $item ) :
				$product = $item->get_product();
				if ( $product && has_term( 'warranties', 'product_cat', $product->get_id() ) ) :
					?>
					<tr>
						<td class="td" style="text-align: left; vertical-align: middle; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; word-wrap: break-word;">
							<?php
							echo wp_kses_post( $item->get_name() );

							if ( $product->get_sku() ) {
								echo '<br><small>' . esc_html__( 'SKU:', 'warranty-cart' ) . ' ' . esc_html( $product->get_sku() ) . '</small>';
							}
							?>
						</td>
						<td class="td" style="text-align: left; vertical-align: middle; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;">
							<?php
							// You might want to add custom meta for warranty period
							$warranty_period = $product->get_meta( '_warranty_period', true );
							if ( $warranty_period ) {
								/* translators: %s: Warranty period */
								printf( esc_html__( '%s months', 'warranty-cart' ), esc_html( $warranty_period ) );
							} else {
								esc_html_e( 'Standard coverage', 'warranty-cart' );
							}
							?>
						</td>
					</tr>
				<?php endif; ?>
			<?php endforeach; ?>
		</tbody>
	</table>
</div>

<p><?php esc_html_e( 'If you have any questions about your warranty coverage or need assistance, please don\'t hesitate to contact our support team.', 'warranty-cart' ); ?></p>

<?php
/**
 * Show user-defined additional content - this is set in each email's settings.
 */
if ( $additional_content ) {
	echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
}

/*
 * @hooked WC_Emails::email_footer() Output the email footer
 */
do_action( 'woocommerce_email_footer', $email );
// phpcs:enable
