<?php
defined( 'ABSPATH' ) || exit;
/*$border_style = ! empty( $border_top ) ? esc_attr( 'border-top:' . $border_top . ';' ) : '';
$border_style .= ! empty( $border_right ) ? esc_attr( 'border-right:' . $border_right . ';' ) : '';
$border_style .= ! empty( $border_left ) ? esc_attr( 'border-left:' . $border_left . ';' ) : '';
$border_style .= ! empty( $border_bottom ) ? esc_attr( 'border-bottom:' . $border_bottom . ';' ) : '';*/
$border_style = ! empty( $border ) ? 'border:' . $border . ';' : '';
$padding      = ! empty( $padding ) ? 'padding:' . $padding . ';' : '';
$color        = ! empty( $color ) ? 'color:' . $color . ';' : '';
?>
<div class="email-product-list"
     style="padding: 15px 25px;<?php echo esc_attr( ! empty( $background_color ) ? 'background-color:' . $background_color . ';' : '' ); ?>
     <?php echo esc_attr( $color ); ?>
     <?php echo ! empty( $font_family ) ? esc_attr( 'font-family:' . $font_family . ';' ) : ''; ?>
     <?php echo ! empty( $font_size ) ? esc_attr( 'font-size:' . $font_size . ';' ) : ''; ?>
     <?php echo ! empty( $text_align ) ? esc_attr( 'text-align:' . $text_align . ';' ) : ''; ?>
     <?php echo ! empty( $line_height ) ? esc_attr( 'line-height:' . $line_height . ';' ) : ''; ?>
     <?php echo ! empty( $font_weight ) ? esc_attr( 'font-weight:' . $font_weight . ';' ) : ''; ?>">
	<?php if ( $show_payment_instruction == 'yes' || ( $show_payment_instruction == 'only_customer' && ! $sent_to_admin ) ) {
		if ( is_object( $order ) && ! empty( $email ) && is_object( $email ) ) {
			do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email );
		}
	} ?>
    <table class="email_builder_table_items" cellspacing="0" cellpadding="6"
           style="width: 100% !important; <?php echo esc_attr( $border_style ); ?>"
           border="1"
           dir="<?php echo esc_attr( $direction ); ?>"
           width="100%">
        <thead>
        <tr style="<?php echo esc_attr( $border_style ); ?><?php echo esc_attr( $padding ); ?><?php echo esc_attr( $color ); ?>">
            <th class="td" scope="col"
                style="<?php echo esc_attr( $border_style ); ?><?php echo esc_attr( $padding ); ?><?php echo esc_attr( $color ); ?>"><?php esc_html_e( 'Product', 'email-editor-plus' ); ?></th>
            <th class="td" scope="col"
                style="<?php echo esc_attr( $border_style ); ?><?php echo esc_attr( $padding ); ?><?php echo esc_attr( $color ); ?>"><?php esc_html_e( 'Quantity', 'email-editor-plus' ); ?></th>
            <th class="td" scope="col"
                style="<?php echo esc_attr( $border_style ); ?><?php echo esc_attr( $padding ); ?><?php echo esc_attr( $color ); ?>"><?php esc_html_e( 'Price', 'email-editor-plus' ); ?></th>
        </tr>
        </thead>
        <tbody>
		<?php
		foreach ( $items as $item_id => $item ) {
			if ( ! apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
				continue;
			}
			$product = $item->get_product();
			?>
            <tr class="<?php echo esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $order ) ); ?>"
                style="<?php echo esc_attr( $border_style ); ?><?php echo esc_attr( $padding ); ?><?php echo esc_attr( $color ); ?>">
                <td class="td"
                    style="text-align:<?php echo esc_attr( $text_align ); ?>;vertical-align:middle;word-wrap:break-word;<?php echo esc_attr( $border_style ); ?><?php echo esc_attr( $padding ); ?><?php echo esc_attr( $color ); ?>">

					<?php
					// Show title/image etc
					if ( $show_image && is_object( $product ) ) {
						echo wp_kses_post( apply_filters( 'woocommerce_order_item_thumbnail', '<img src="' . ( $product->get_image_id() ? current( wp_get_attachment_image_src( $product->get_image_id(), $product_image_size ) ) : wc_placeholder_img_src() ) . '" alt="' . esc_attr__( 'Product image', 'email-editor-plus' ) . '" height="' . esc_attr( $product_image_height ) . '" width="' . esc_attr( $product_image_width ) . '" style="vertical-align:middle; margin-' . ( is_rtl() ? 'left' : 'right' ) . ': 10px;"  />', $item ) );
					}

					// Product name
					echo wp_kses_post( apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ) );

					// SKU
					if ( $show_sku && is_object( $product ) && ( $sku = $product->get_sku() ) ) {
						echo wp_kses_post( ' (#' . $sku . ')' );
					}

					// 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, [ 'label_before' => '<strong class="wc-item-meta-label" style="float: ' . esc_attr( $text_align ) . '; margin-' . esc_attr( $margin_side ) . ': .25em; clear: both">' ] );
					if ( $show_download_links ) {
						wc_display_item_downloads( $item );
					}
					// 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:<?php echo esc_attr( $text_align ); ?>;vertical-align:middle;<?php echo esc_attr( $border_style ); ?><?php echo esc_attr( $padding ); ?><?php echo esc_attr( $color ); ?>">
					<?php
					$qty          = $item->get_quantity();
					$refunded_qty = $order->get_qty_refunded_for_item( $item_id );

					if ( $refunded_qty ) {
						$qty_display = '<del>' . esc_html( $qty ) . '</del> <ins>' . esc_html( $qty - ( $refunded_qty * - 1 ) ) . '</ins>';
					} else {
						$qty_display = esc_html( $qty );
					}
					echo wp_kses_post( apply_filters( 'woocommerce_email_order_item_quantity', $qty_display, $item ) ); ?>
                </td>
                <td class="td"
                    style="text-align:<?php echo esc_attr( $text_align ); ?>;vertical-align:middle;<?php echo esc_attr( $border_style ); ?><?php echo esc_attr( $padding ); ?><?php echo esc_attr( $color ); ?>">
					<?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?>
                </td>
            </tr>
			<?php
			if ( $show_purchase_note && is_object( $product ) && ( $purchase_note = $product->get_purchase_note() ) ) { ?>
                <tr style="<?php echo esc_attr( $border_style ); ?><?php echo esc_attr( $padding ); ?><?php echo esc_attr( $color ); ?>">
                    <td colspan="3"
                        style="text-align:<?php echo esc_attr( $text_align ); ?>; vertical-align:middle;<?php echo esc_attr( $border_style ); ?><?php echo esc_attr( $padding ); ?><?php echo esc_attr( $color ); ?>">
						<?php echo wp_kses_post( wpautop( do_shortcode( $purchase_note ) ) ); ?>
                    </td>
                </tr>
			<?php }
		}
		?>
        </tbody>
        <tfoot>
		<?php
		if ( $totals ) {
			$i = 0;
			foreach ( $totals as $total ) {
				$i ++;
				?>
            <tr style="<?php echo esc_attr( $border_style ); ?><?php echo esc_attr( $padding ); ?><?php echo esc_attr( $color ); ?>">
                <th class="td" scope="row" colspan="2"
                    style="<?php echo esc_attr( $border_style ); ?><?php echo esc_attr( $padding ); ?><?php echo esc_attr( $color ); ?><?php if ( $i === 1 ) {
					    echo 'border-top-width: 1px;';
				    } ?>"><?php echo wp_kses_post( $total['label'] ); ?></th>
                <td class="td"
                    style="<?php echo esc_attr( $border_style ); ?><?php echo esc_attr( $padding ); ?><?php echo esc_attr( $color ); ?><?php if ( $i === 1 ) {
					    echo 'border-top-width: 1px;';
				    } ?>"><?php echo wp_kses_post( $total['value'] ); ?></td>
                </tr><?php
			}
		}
		?>
        </tfoot>
    </table>
	<?php do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text, $email ); ?>
</div>
