<?php
/**
 * Shopping cart in header
 *
 * @package Multi
 */

?>
<?php
$show_cart_link   = class_exists( 'Woocommerce' ) && 'off' !== get_theme_mod( 'multi_cart_in_menu', MULTIMAGAZINE_CART_IN_MENU );
$show_search_link = 'off' !== get_theme_mod( 'multi_search_in_menu', MULTIMAGAZINE_SEARCH_IN_MENU );

if ( $show_cart_link ) {
	?>
	<ul class="link-box menu">
		<?php

			global $woocommerce;
			$cart_items      = $woocommerce->cart->get_cart();
			$cart_item_count = $woocommerce->cart->get_cart_contents_count();
		?>
		<li><a href="<?php echo esc_url( wc_get_cart_url() ); ?>" class="link-box-link cart-link" aria-label="<?php esc_attr_e( 'Shopping cart', 'multimagazine' ); ?>">
			<i class="m-icon m-icon-cart" aria-hidden="true"></i>
			<span class="cart-link-qty">
				<?php
				if ( $cart_item_count ) {
					echo esc_html( $woocommerce->cart->cart_contents_count );
				}
				?>
			</span>
		</a>
			<?php
			if ( ! is_cart() ) {
				multimagazine_cart_shopping_bag();
			}
			?>
		</li>
		<?php if ( $show_search_link ) : ?>
			<li class="search-item"><a href="#" class="link-box-link search-popup-link" aria-label="<?php esc_attr_e( 'Search', 'multimagazine' ); ?>"><i class="m-icon m-icon-search" aria-hidden="true"></i></a></li>
		<?php endif; ?>
	</ul>
	<?php
}
