<?php
/**
 * Warranty Order Completed Email Template
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/warranty-order-completed.php
 *
 * @package WarrantyCart
 * @var WC_Order        $order              The order object.
 * @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 OrderCompletion $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

use WarrantyCart\Notifications\Emails\OrderCompletion;

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( 'Thank you for your warranty purchase! Your order has been completed successfully.', 'warranty-cart' ); ?></p>

<h2><?php esc_html_e( 'Order Details', 'warranty-cart' ); ?></h2>

<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( 'Quantity', 'warranty-cart' ); ?></th>
				<th class="td" scope="col" style="text-align: left;"><?php esc_html_e( 'Price', 'warranty-cart' ); ?></th>
			</tr>
		</thead>
		<tbody>
			<?php
			foreach ( $order->get_items() as $item_id => $item ) :
				$product = $item->get_product();
				?>
				<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
						// Product name.
						echo wp_kses_post( $item->get_name() );

						// SKU.
						if ( $product && $product->get_sku() ) {
							echo '<br><small>' . esc_html__( 'SKU:', 'warranty-cart' ) . ' ' . esc_html( $product->get_sku() ) . '</small>';
						}

						// allow other plugins to add additional product information here.
						do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, $plain_text );

						wc_display_item_meta(
							$item,
							array(
								'label_before' => '<strong class="wc-item-meta-label" style="float: left; margin-right: .25em; clear: both;">',
							)
						);

						// allow other plugins to add additional product information here.
						do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order, $plain_text );
						?>
					</td>
					<td class="td" style="text-align: left; vertical-align: middle; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;">
						<?php echo esc_html( $item->get_quantity() ); ?>
					</td>
					<td class="td" style="text-align: left; vertical-align: middle; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;">
						<?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?>
					</td>
				</tr>
			<?php endforeach; ?>
		</tbody>
		<tfoot>
			<?php
			$item_totals = $order->get_order_item_totals();
			if ( $item_totals ) {
				$i = 0;
				foreach ( $item_totals as $total ) {
					++$i;
					?>
					<tr>
						<th class="td" scope="row" colspan="2" style="text-align: left; border-top-width: 4px;"><?php echo wp_kses_post( $total['label'] ); ?></th>
						<td class="td" style="text-align: left; border-top-width: 4px;"><?php echo wp_kses_post( $total['value'] ); ?></td>
					</tr>
					<?php
				}
			}
			?>
		</tfoot>
	</table>
</div>

<p><?php esc_html_e( 'Your warranty certificate has been attached to this email. Please keep it safe for your records.', 'warranty-cart' ); ?></p>

<p><?php esc_html_e( 'If you have any questions about your warranty, please don\'t hesitate to contact us.', '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
