<?php
/**
 * Review order table
 *
 * Template aligned with WooCommerce 5.2.0
 * @see https://woocommerce.com/document/template-structure/
 * @package Pawfect
 * @version 10.9.1
 */

defined( 'ABSPATH' ) || exit;
?>
<table class="shop_table woocommerce-checkout-review-order-table pawfect-w-full pawfect-mb-6">
    <tbody>
        <?php
        do_action( 'woocommerce_review_order_before_cart_contents' );

        foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
            $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );

            if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
                ?>
                <tr class="<?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?> pawfect-border-b pawfect-border-border-color pawfect-py-4">
                    <td class="product-name pawfect-py-4">
                        <div class="pawfect-flex pawfect-items-center pawfect-space-x-4">
                            <?php if ( $_product->get_image_id() ) : ?>
                                <div class="pawfect-w-16 pawfect-h-16 pawfect-rounded-md pawfect-overflow-hidden pawfect-flex-shrink-0">
                                    <?php echo wp_kses_post( $_product->get_image( 'thumbnail', array( 'class' => 'pawfect-w-full pawfect-h-full pawfect-object-cover' ) ) ); ?>
                                </div>
                            <?php endif; ?>
                            <div class="pawfect-flex-1">
                                <p class="pawfect-font-bold pawfect-text-text-dark">
                                    <?php echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ) ) . '&nbsp;'; ?>
                                    <span class="pawfect-text-text-light pawfect-font-normal">
                                        × <?php echo apply_filters( 'woocommerce_checkout_cart_item_quantity', ' <strong class="product-quantity">' . sprintf( '&times;&nbsp;%s', $cart_item['quantity'] ) . '</strong>', $cart_item, $cart_item_key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
                                    </span>
                                </p>
                                <?php echo wc_get_formatted_cart_item_data( $cart_item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
                            </div>
                        </div>
                    </td>
                    <td class="product-total pawfect-py-4 pawfect-text-right">
                        <span class="pawfect-font-bold pawfect-text-accent">
                            <?php echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
                        </span>
                    </td>
                </tr>
                <?php
            }
        }

        do_action( 'woocommerce_review_order_after_cart_contents' );
        ?>
    </tbody>
    <tfoot class="pawfect-border-t pawfect-border-border-color">

        <tr class="cart-subtotal">
            <th class="pawfect-py-4 pawfect-text-left pawfect-text-text-light pawfect-font-normal">
                <?php esc_html_e( 'Subtotal', 'pawfect' ); ?>
            </th>
            <td class="pawfect-py-4 pawfect-text-right pawfect-font-bold">
                <?php wc_cart_totals_subtotal_html(); ?>
            </td>
        </tr>

        <?php foreach ( WC()->cart->get_coupons() as $code => $coupon ) : ?>
            <tr class="cart-discount coupon-<?php echo esc_attr( sanitize_title( $code ) ); ?>">
                <th class="pawfect-py-4 pawfect-text-left pawfect-text-text-light pawfect-font-normal">
                    <?php wc_cart_totals_coupon_label( $coupon ); ?>
                </th>
                <td class="pawfect-py-4 pawfect-text-right pawfect-font-bold">
                    <?php wc_cart_totals_coupon_html( $coupon ); ?>
                </td>
            </tr>
        <?php endforeach; ?>

        <?php if ( WC()->cart->needs_shipping() && WC()->cart->show_shipping() ) : ?>

            <?php do_action( 'woocommerce_review_order_before_shipping' ); ?>

            <?php wc_cart_totals_shipping_html(); ?>

            <?php do_action( 'woocommerce_review_order_after_shipping' ); ?>

        <?php endif; ?>

        <?php foreach ( WC()->cart->get_fees() as $fee ) : ?>
            <tr class="fee">
                <th class="pawfect-py-4 pawfect-text-left pawfect-text-text-light pawfect-font-normal">
                    <?php echo esc_html( $fee->name ); ?>
                </th>
                <td class="pawfect-py-4 pawfect-text-right pawfect-font-bold">
                    <?php wc_cart_totals_fee_html( $fee ); ?>
                </td>
            </tr>
        <?php endforeach; ?>

        <?php if ( wc_tax_enabled() && ! WC()->cart->display_prices_including_tax() ) : ?>
            <?php if ( 'itemized' === get_option( 'woocommerce_tax_total_display' ) ) : ?>
                <?php foreach ( WC()->cart->get_tax_totals() as $code => $tax ) : // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited ?>
                    <tr class="tax-rate tax-rate-<?php echo esc_attr( sanitize_title( $code ) ); ?>">
                        <th class="pawfect-py-4 pawfect-text-left pawfect-text-text-light pawfect-font-normal">
                            <?php echo esc_html( $tax->label ); ?>
                        </th>
                        <td class="pawfect-py-4 pawfect-text-right pawfect-font-bold">
                            <?php echo wp_kses_post( $tax->formatted_amount ); ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            <?php else : ?>
                <tr class="tax-total">
                    <th class="pawfect-py-4 pawfect-text-left pawfect-text-text-light pawfect-font-normal">
                        <?php echo esc_html( WC()->countries->tax_or_vat() ); ?>
                    </th>
                    <td class="pawfect-py-4 pawfect-text-right pawfect-font-bold">
                        <?php wc_cart_totals_taxes_total_html(); ?>
                    </td>
                </tr>
            <?php endif; ?>
        <?php endif; ?>

        <?php do_action( 'woocommerce_review_order_before_order_total' ); ?>

        <tr class="order-total pawfect-border-t pawfect-border-border-color">
            <th class="pawfect-py-6 pawfect-text-left pawfect-font-serif pawfect-text-xl pawfect-font-bold">
                <?php esc_html_e( 'Total', 'pawfect' ); ?>
            </th>
            <td class="pawfect-py-6 pawfect-text-right pawfect-font-serif pawfect-text-2xl pawfect-font-bold pawfect-text-accent">
                <?php wc_cart_totals_order_total_html(); ?>
            </td>
        </tr>

        <?php do_action( 'woocommerce_review_order_after_order_total' ); ?>

    </tfoot>
</table>

<div id="payment" class="woocommerce-checkout-payment">
    <?php if ( WC()->cart->needs_payment() ) : ?>
        <ul class="wc_payment_methods payment_methods methods pawfect-space-y-4 pawfect-mb-6">
            <?php
            if ( ! empty( $available_gateways ) ) {
                foreach ( $available_gateways as $gateway ) {
                    wc_get_template( 'checkout/payment-method.php', array( 'gateway' => $gateway ) );
                }
            } else {
                echo '<li class="woocommerce-notice woocommerce-notice--info woocommerce-info">' . apply_filters( 'woocommerce_no_available_payment_methods_message', WC()->customer->get_billing_country() ? esc_html__( 'Sorry, it seems that there are no available payment methods for your state. Please contact us if you require assistance or wish to make alternate arrangements.', 'pawfect' ) : esc_html__( 'Please fill in your details above to see available payment methods.', 'pawfect' ) ) . '</li>'; // @codingStandardsIgnoreLine
            }
            ?>
        </ul>
    <?php endif; ?>
    <div class="form-row place-order">
        <noscript>
            <?php
            /* translators: $1 and $2 opening and closing emphasis tags respectively */
            printf( esc_html__( 'Since your browser does not support JavaScript, or it is disabled, please ensure you click the %1$sUpdate Totals%2$s button before placing your order. You may be charged more than the amount stated above if you fail to do so.', 'pawfect' ), '<em>', '</em>' );
            ?>
            <br/><button type="submit" class="button alt" name="woocommerce_checkout_update_totals" value="<?php esc_attr_e( 'Update totals', 'pawfect' ); ?>"><?php esc_html_e( 'Update totals', 'pawfect' ); ?></button>
        </noscript>

        <?php wc_get_template( 'checkout/terms.php' ); ?>

        <?php do_action( 'woocommerce_review_order_before_submit' ); ?>

        <button type="submit" class="button alt pawfect-w-full pawfect-bg-accent pawfect-text-white pawfect-py-4 pawfect-rounded-md pawfect-text-lg pawfect-uppercase pawfect-font-bold hover:pawfect-opacity-90 pawfect-transition-opacity pawfect-mt-6" name="woocommerce_checkout_place_order" id="place_order" value="<?php esc_attr_e( 'Place order', 'pawfect' ); ?>" data-value="<?php esc_attr_e( 'Place order', 'pawfect' ); ?>">
            <?php esc_html_e( 'Place order', 'pawfect' ); ?>
        </button>

        <?php do_action( 'woocommerce_review_order_after_submit' ); ?>

        <?php wp_nonce_field( 'woocommerce-process_checkout', 'woocommerce-process-checkout-nonce' ); ?>
    </div>
</div>

