<?php
/**
 * @package WordPress
 * @subpackage Campoal
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
} ?>

<?php if (is_page_template('fullwidth.php') || is_page_template('container.php')) : ?>
	<div class="wrapper woocommerce">
<?php endif; ?>
<?php 
	wc_print_notices();
	do_action( 'woocommerce_before_cart' ); ?>

	<div class="ui raised padded segment cart-section">
		<form class="cart-form" action="<?php echo esc_url( wc_get_cart_url() ); ?>" method="post">

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

		<table class="ui very basic single line unstackable large table cart-table" id="cart-table">
			<tbody>
			<?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="<?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>">
							<td class="cart-thumbnail">
								<?php
									$thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', get_the_post_thumbnail_url($product_id, 'woocommerce_thumbnail'), $cart_item, $cart_item_key );

									if ( ! $product_permalink ) {
										echo wp_kses_post($thumbnail);
									} else {
										printf( '<a href="%s" data-bjax><img class="ui tiny rounded image" src="%s"></a>', esc_url( $product_permalink ), $thumbnail );
									}
								?>
							</td>
							
							<td class="cart-title">
								<div class="cart-product-name">
									<?php
										if ( ! $product_permalink ) {
											echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key ) . '&nbsp;';
										} else {
											echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<div class="ui tiny header"><div class="content truncate">%s<div class="sub header">%s</div></div></div>', $_product->get_name(), strip_tags(wc_get_product_category_list($_product->get_id())) ), $cart_item, $cart_item_key );
										}

										// Meta data
										echo wc_get_formatted_cart_item_data( $cart_item ); 

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

								<?php
									echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
										'<a href="%s" class="text grey font small checkmark checkmark--cross bg--error" title="%s" data-product_id="%s" data-product_sku="%s"><i class="delete icon"></i>' . esc_html__( 'Remove', 'campoal' ) . '</a>',
										esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
										esc_html__( 'Remove this item', 'campoal' ),
										esc_attr( $product_id ),
										esc_attr( $_product->get_sku() )
									), $cart_item_key );
								?>
							</td>
							<td class="right aligned cart-price">
								<div class="ui tiny header">
									<div class="content">
									<?php
										echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key );
									?>
										<div class="sub header">
											<?php
												echo '(' . apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key ) . ' x ' . $cart_item['quantity'] . ')';
											?>
										</div>
									</div>
								</div>

								<div class="ui tiny input cart-quantity">			
									<?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->backorders_allowed() ? '' : $_product->get_stock_quantity(),
												'min_value'   => '0'
											), $_product, false );
										}

										echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item );
									?>
								</div>

							</td>
						</tr><!--end item-->
						
						<?php
					}
				}

				do_action( 'woocommerce_cart_contents' );
			?>
			</tbody>
		</table><!--end of table-->

		<div class="ui section divider"></div>
		<div class="ui grid">
			<?php if ( wc_coupons_enabled() ) { ?>
			<div class="sixteen wide mobile ten wide computer column">
				<div class="field">
					<label><?php esc_html_e('Got a coupon code?', 'campoal'); ?></label>
					<input type="text" class="ui input coupon-code-input" name="coupon_code" id="coupon_code" value="" placeholder="<?php esc_attr_e( 'Coupon code', 'campoal' ); ?>" />
					<input type="submit" class="ui large primary button apply-coupon-btn" name="apply_coupon" value="<?php esc_attr_e( 'Apply Coupon', 'campoal' ); ?>" />
				</div>
				<?php do_action( 'woocommerce_cart_coupon' ); ?>
			</div>
			<?php } ?>
			<div class="sixteen wide mobile six wide computer right aligned column">
				<input type="submit" class="ui large primary button" name="update_cart" value="<?php esc_attr_e( 'Update Cart', 'campoal' ); ?>" />
				
				<?php do_action( 'woocommerce_cart_actions' ); ?>
				<?php wp_nonce_field( 'woocommerce-cart' ); ?>
			</div>
		</div><!--end of row-->

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

		</form>
	</div>

	<div class="ui hidden section divider"></div>
	<div class="ui grid">
		<div class="sixteen wide mobile eight wide computer right floated column">
			<?php do_action( 'woocommerce_cart_collaterals' ); ?>
		</div>
	</div>

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

<?php if (is_page_template('fullwidth.php') || is_page_template('container.php')) : ?>
	</div>
<?php endif; ?>