<?php
/**
 * Cart Page
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/cart/cart.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see     https://woocommerce.com/document/template-structure/
 * @package Pawfect
 * @version 10.9.1
 */

defined( 'ABSPATH' ) || exit;

do_action( 'woocommerce_before_cart' ); ?>

<div class="pawfect-container pawfect-mx-auto pawfect-px-6 pawfect-py-12 md:pawfect-py-16">
    
    <form class="woocommerce-cart-form" action="<?php echo esc_url( wc_get_cart_url() ); ?>" method="post">
        <?php do_action( 'woocommerce_before_cart_table' ); ?>

        <div class="pawfect-bg-white pawfect-rounded-lg pawfect-shadow-md pawfect-overflow-hidden pawfect-mb-8">
            <div class="pawfect-overflow-x-auto">
                <table class="shop_table shop_table_responsive cart woocommerce-cart-form__contents pawfect-w-full" cellspacing="0">
                    <thead class="pawfect-bg-gray-50">
                        <tr class="pawfect-border-b pawfect-border-border-color">
                            <th class="product-remove pawfect-p-4 pawfect-text-left pawfect-font-serif pawfect-text-lg"><span class="screen-reader-text"><?php esc_html_e( 'Remove item', 'pawfect' ); ?></span></th>
                            <th class="product-thumbnail pawfect-p-4 pawfect-text-left pawfect-font-serif pawfect-text-lg"><span class="screen-reader-text"><?php esc_html_e( 'Thumbnail image', 'pawfect' ); ?></span></th>
                            <th scope="col" class="product-name pawfect-p-4 pawfect-text-left pawfect-font-serif pawfect-text-lg"><?php esc_html_e( 'Product', 'pawfect' ); ?></th>
                            <th scope="col" class="product-price pawfect-p-4 pawfect-text-left pawfect-font-serif pawfect-text-lg"><?php esc_html_e( 'Price', 'pawfect' ); ?></th>
                            <th scope="col" class="product-quantity pawfect-p-4 pawfect-text-left pawfect-font-serif pawfect-text-lg"><?php esc_html_e( 'Quantity', 'pawfect' ); ?></th>
                            <th scope="col" class="product-subtotal pawfect-p-4 pawfect-text-left pawfect-font-serif pawfect-text-lg"><?php esc_html_e( 'Subtotal', 'pawfect' ); ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php do_action( 'woocommerce_before_cart_contents' ); ?>

                        <?php
                        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 );
                            $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );

                            if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
                                $product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key );
                                ?>
                                <tr class="woocommerce-cart-form__cart-item <?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?> pawfect-border-b pawfect-border-border-color">

                                    <td class="product-remove pawfect-p-4 pawfect-text-center">
                                        <?php
                                        echo apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                                            'woocommerce_cart_item_remove_link',
                                            sprintf(
                                                '<a href="%s" class="remove pawfect-inline-flex pawfect-items-center pawfect-justify-center pawfect-w-8 pawfect-h-8 pawfect-bg-red-100 pawfect-text-red-600 hover:pawfect-bg-red-200 pawfect-rounded-full pawfect-transition-colors" aria-label="%s" data-product_id="%s" data-product_sku="%s"><i class="fas fa-times pawfect-text-sm"></i></a>',
                                                esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
                                                esc_html__( 'Remove this item', 'pawfect' ),
                                                esc_attr( $product_id ),
                                                esc_attr( $_product->get_sku() )
                                            ),
                                            $cart_item_key
                                        );
                                        ?>
                                    </td>

                                    <td class="product-thumbnail pawfect-p-4">
                                        <div class="pawfect-w-16 pawfect-h-16 pawfect-rounded-md pawfect-overflow-hidden pawfect-bg-gray-100">
                                            <?php
                                            if ( ! $product_permalink ) {
                                                if (has_post_thumbnail($_product->get_id())) {
                                                    echo '<img src="' . esc_url(get_the_post_thumbnail_url($_product->get_id(), 'thumbnail')) . '" alt="' . esc_attr($_product->get_name()) . '" class="pawfect-w-full pawfect-h-full pawfect-object-cover">';
                                                } else {
                                                    echo '<div class="pawfect-w-full pawfect-h-full pawfect-bg-gray-200 pawfect-flex pawfect-items-center pawfect-justify-center"><span class="pawfect-text-xs pawfect-text-gray-500">' . esc_html__( 'No Image', 'pawfect' ) . '</span></div>';
                                                }
                                            } else {
                                                printf( '<a href="%s" class="pawfect-block pawfect-w-full pawfect-h-full">', esc_url( $product_permalink ) );
                                                if (has_post_thumbnail($_product->get_id())) {
                                                    echo '<img src="' . esc_url(get_the_post_thumbnail_url($_product->get_id(), 'thumbnail')) . '" alt="' . esc_attr($_product->get_name()) . '" class="pawfect-w-full pawfect-h-full pawfect-object-cover">';
                                                } else {
                                                    echo '<div class="pawfect-w-full pawfect-h-full pawfect-bg-gray-200 pawfect-flex pawfect-items-center pawfect-justify-center"><span class="pawfect-text-xs pawfect-text-gray-500">' . esc_html__( 'No Image', 'pawfect' ) . '</span></div>';
                                                }
                                                echo '</a>';
                                            }
                                            ?>
                                        </div>
                                    </td>

                                    <td class="product-name pawfect-p-4" data-title="<?php esc_attr_e( 'Product', 'pawfect' ); ?>">
                                        <?php
                                        if ( ! $product_permalink ) {
                                            echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ) . '&nbsp;' );
                                        } else {
                                            echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s" class="pawfect-font-bold hover:pawfect-text-accent">%s</a>', esc_url( $product_permalink ), $_product->get_name() ), $cart_item, $cart_item_key ) );
                                        }

                                        do_action( 'woocommerce_after_cart_item_name', $cart_item, $cart_item_key );

                                        // Meta data.
                                        echo wc_get_formatted_cart_item_data( $cart_item ); // PHPCS: XSS ok.

                                        // Backorder notification.
                                        if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) {
                                            echo wp_kses_post( apply_filters( 'woocommerce_cart_item_backorder_notification', '<p class="backorder_notification">' . esc_html__( 'Available on backorder', 'pawfect' ) . '</p>', $product_id ) );
                                        }
                                        ?>
                                    </td>

                                    <td class="product-price pawfect-p-4" data-title="<?php esc_attr_e( 'Price', 'pawfect' ); ?>">
                                        <span class="pawfect-font-bold pawfect-text-accent">
                                            <?php echo apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key ); // PHPCS: XSS ok. ?>
                                        </span>
                                    </td>

                                    <td class="product-quantity pawfect-p-4" data-title="<?php esc_attr_e( 'Quantity', 'pawfect' ); ?>">
                                        <?php
                                        if ( $_product->is_sold_individually() ) {
                                            $product_quantity = sprintf( '1 <input type="hidden" name="cart[%s][qty]" value="1" />', $cart_item_key );
                                        } else {
                                            $product_quantity = woocommerce_quantity_input(
                                                array(
                                                    'input_name'   => "cart[{$cart_item_key}][qty]",
                                                    'input_value'  => $cart_item['quantity'],
                                                    'max_value'    => $_product->get_max_purchase_quantity(),
                                                    'min_value'    => '0',
                                                    'product_name' => $_product->get_name(),
                                                ),
                                                $_product,
                                                false
                                            );
                                        }

                                        echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item ); // PHPCS: XSS ok.
                                        ?>
                                    </td>

                                    <td class="product-subtotal pawfect-p-4" data-title="<?php esc_attr_e( 'Subtotal', 'pawfect' ); ?>">
                                        <span class="pawfect-font-bold pawfect-text-xl">
                                            <?php echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); // PHPCS: XSS ok. ?>
                                        </span>
                                    </td>
                                </tr>
                                <?php
                            }
                        }
                        ?>

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

                        <tr class="pawfect-bg-gray-50">
                            <td colspan="6" class="actions pawfect-p-4">
                                <?php if ( wc_coupons_enabled() ) { ?>
                                    <div class="coupon pawfect-flex pawfect-items-center pawfect-space-x-4 pawfect-mb-4">
                                        <label for="coupon_code" class="pawfect-font-bold"><?php esc_html_e( 'Coupon:', 'pawfect' ); ?></label>
                                        <input type="text" name="coupon_code" class="input-text pawfect-flex-1 pawfect-p-2 pawfect-border pawfect-border-border-color pawfect-rounded-md" id="coupon_code" value="" placeholder="<?php esc_attr_e( 'Coupon code', 'pawfect' ); ?>" />
                                        <button type="submit" class="button pawfect-btn" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'pawfect' ); ?>"><?php esc_html_e( 'Apply coupon', 'pawfect' ); ?></button>
                                        <?php do_action( 'woocommerce_cart_coupon' ); ?>
                                    </div>
                                <?php } ?>

                                <button type="submit" class="button pawfect-btn" name="update_cart" value="<?php esc_attr_e( 'Update cart', 'pawfect' ); ?>"><?php esc_html_e( 'Update cart', 'pawfect' ); ?></button>

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

                                <?php wp_nonce_field( 'woocommerce-cart', 'woocommerce-cart-nonce' ); ?>
                            </td>
                        </tr>

                        <?php do_action( 'woocommerce_after_cart_contents' ); ?>
                    </tbody>
                </table>
            </div>
        </div>
        
        <?php do_action( 'woocommerce_after_cart_table' ); ?>
    </form>

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

    <div class="cart-collaterals pawfect-grid pawfect-grid-cols-1 lg:pawfect-grid-cols-2 pawfect-gap-8">
        <?php
        /**
         * Cart collaterals hook.
         *
         * @hooked woocommerce_cross_sell_display
         * @hooked woocommerce_cart_totals - 10
         */
        do_action( 'woocommerce_cart_collaterals' );
        ?>
    </div>

    <?php do_action( 'woocommerce_after_cart_collaterals' ); ?>
</div>

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

