<?php
/**
 * Warranty Expired Email Template
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/warranty-expired.php
 *
 * @package WarrantyCart
 * @var WC_Order        $order              The order object.
 * @var string          $expiration_date    The warranty expiration date.
 * @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 WarrantyExpired $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( 'We hope this email finds you well. We wanted to inform you that your warranty coverage has now expired.', 'warranty-cart' ); ?></p>

<div style="background-color: #fff3cd; padding: 20px; margin: 20px 0; border-left: 4px solid #ffc107; border: 1px solid #ffeaa7;">
	<h3 style="margin-top: 0; color: #856404;"><?php esc_html_e( 'Warranty Status', '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; color: #856404;"><strong><?php esc_html_e( 'Status:', 'warranty-cart' ); ?></strong> <?php esc_html_e( 'Expired', 'warranty-cart' ); ?></p>
</div>

<h3><?php esc_html_e( 'What This Means', 'warranty-cart' ); ?></h3>

<p><?php esc_html_e( 'Your warranty coverage for the following products has now expired. While your warranty is no longer active, we\'re still here to help with any questions or support you may need.', 'warranty-cart' ); ?></p>

<h3><?php esc_html_e( 'Expired Warranty 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( 'Original Purchase Date', '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 echo esc_html( wc_format_datetime( $order->get_date_created() ) ); ?>
						</td>
					</tr>
				<?php endif; ?>
			<?php endforeach; ?>
		</tbody>
	</table>
</div>

<h3><?php esc_html_e( 'Need Extended Coverage?', 'warranty-cart' ); ?></h3>

<p><?php esc_html_e( 'If you\'d like to extend your warranty coverage or have questions about additional support options, please don\'t hesitate to contact us. We\'re here to help!', 'warranty-cart' ); ?></p>

<p><?php esc_html_e( 'Thank you for choosing our warranty services. We appreciate your business and hope to continue serving you in the future.', '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
