<?php
/**
 * Mini-cart
 *
 * Contains the markup for the mini-cart, used by the cart widget.
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/cart/mini-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://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce\Templates
 * @version 9.2.0
 */

defined( 'ABSPATH' ) || exit;
?>
<?php $items_count = \WC()->cart->get_cart_contents_count(); ?>
<div class="brandy-mini-cart-wrapper<?php echo $items_count > 0 ? '' : ' empty'; ?>">
	<div class="brandy-mini-cart-top">
		<?php // Translators: %s cart items number. ?>
		<div class="brandy-mini-cart__title">
			<h2 class="brandy-mini-cart__title__text"><?php echo wp_kses_post( sprintf( __( 'Your cart %s', 'brandy' ), '<span class="brandy-mini-cart__title__text__count">' . $items_count . '</span>' ) ); ?></h2>
			<button class="brandy-mini-cart__close" type="button" tabindex="0" title="Close mini cart"><span class="sr-only">Close panel</span><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true" class="h-6 w-6"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"></path></svg></button>
		</div>
		<div class="brandy-mini-cart__content">
			<?php do_action( 'woocommerce_before_mini_cart' ); ?>

			<?php if ( ! WC()->cart->is_empty() ) : ?>

				<ul class="woocommerce-mini-cart cart_list product_list_widget brandy-mini-cart__list <?php echo esc_attr( $args['list_class'] ); ?>">
					<?php
					do_action( 'woocommerce_before_mini_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 );
						$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_widget_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
							/**
							 * This filter is documented in woocommerce/templates/cart/cart.php.
							 *
							 * @since 2.1.0
							 */
							$product_name      = apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key );
							$thumbnail         = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
							$product_price     = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $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 );
							global $brandy_cart_settings;
							$click_effect = $brandy_cart_settings['click_effect'] ?? 'slide_in';
							?>
							<li class="woocommerce-mini-cart-item <?php echo esc_attr( apply_filters( 'woocommerce_mini_cart_item_class', 'mini_cart_item', $cart_item, $cart_item_key ) ); ?> brandy-mini-cart__item">
								<div class="item-thumbnail">
									<?php if ( empty( $product_permalink ) ) : ?>
										<?php echo $thumbnail; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
									<?php else : ?>
										<a href="<?php echo esc_url( $product_permalink ); ?>" aria-label="<?php echo esc_html( $product_name ); ?>">
											<?php echo $thumbnail; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
										</a>
									<?php endif; ?>
								</div>
								<div class="item-details">
									<div class="item-name brandy-link-underline">
										<?php
										if ( empty( $product_permalink ) ) {
											echo wp_kses_post( $product_name );
										} else {
											echo sprintf( "<a href='%s' alt='item-name'>%s</a>", esc_url( $product_permalink ), wp_kses_post( $product_name ) );
										}
										?>
									</div>
									<?php $cart_data = wc_get_formatted_cart_item_data( $cart_item ); ?>
									<?php if ( ! empty( $cart_data ) ) : ?>
										<div class="item-description"><?php echo wp_kses_post( $cart_data ); ?></div>
									<?php endif; ?>
									<div class="item-actions">
										<?php if ( 'slide_in' === $click_effect ) : ?>
										<div class="item-figure mini-cart-slide-figure">
											<?php
											if ( $_product->is_sold_individually() ) {
												$min_quantity = 1;
												$max_quantity = 1;
											} else {
												$min_quantity = 0;
												$max_quantity = $_product->get_max_purchase_quantity();
											}
											$product_quantity = woocommerce_quantity_input(
												array(
													'input_name'   => "cart[{$cart_item_key}][qty]",
													'input_value'  => $cart_item['quantity'],
													'max_value'    => $max_quantity,
													'min_value'    => $min_quantity,
													'product_name' => $product_name,
												),
												$_product,
												false
											);

											echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item ); //PHPCS: XSS ok.
											?>
											<div class="item-price"><?php echo wp_kses_post( $product_price ); ?></div>
										</div>
										<?php endif; ?>
										<?php if ( 'dropdown' === $click_effect ) : ?>
										<div class="item-figure mini-cart-dropdown-figure">
											<div class="item-price"><?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s &times; %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
										</div>
										<?php endif; ?>
										<div class="item-remove">
										<?php
										echo apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
											'woocommerce_cart_item_remove_link',
											sprintf(
												'<span class="remove_button" aria-label="%s" data-product_id="%s" data-cart_item_key="%s" data-product_sku="%s"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="18" fill="none" viewBox="0 0 16 18"><g stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.7"><path d="M13.721 6.92c0 6.942 1 10.08-5.73 10.08s-5.71-3.138-5.71-10.08M15 4.26H1M10.97 4.26S11.43 1 8 1C4.575 1 5.033 4.26 5.033 4.26"></path></g></svg></span>',
												/* translators: %s is the product name */
												esc_attr( sprintf( __( 'Remove %s from cart', 'brandy' ), wp_strip_all_tags( $product_name ) ) ),
												esc_attr( $product_id ),
												esc_attr( $cart_item_key ),
												esc_attr( $_product->get_sku() )
											),
											$cart_item_key
										);
										?>
										</div>
									</div>
								</div>
							</li>
							<?php
						}
					}

					do_action( 'woocommerce_mini_cart_contents' );
					?>
				</ul>

			<?php else : ?>

				<div class="brandy-mini-cart__empty">
					<div>
						<svg width="120" height="85" viewBox="0 0 120 85" fill="none" xmlns="http://www.w3.org/2000/svg">
						<rect x="22.25" width="80" height="80" rx="40" fill="#FAFAFA"/>
						<path d="M0.75 78C22.6762 74.9815 76.973 70.7556 118.75 78" stroke="#A0A0A7" stroke-width="1.5" stroke-linecap="round"/>
						<path fill-rule="evenodd" clip-rule="evenodd" d="M74.5813 84H46.8883C36.716 84 28.9122 80.3216 31.1288 65.5167L33.7099 45.4526C35.0763 38.0653 39.7829 35.2381 43.9125 35.2381H77.6786C81.8689 35.2381 86.3022 38.2781 87.8812 45.4526L90.4623 65.5167C92.3449 78.6496 84.7536 84 74.5813 84Z" fill="white" stroke="#A0A0A7" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
						<path d="M67.9143 66.1473C68.199 67.1809 65.6406 66.6474 62.8711 67.3958C60.1015 68.1441 58.1711 69.8905 57.8864 68.8569C57.6017 67.8232 59.2801 65.1617 62.0496 64.4133C64.8191 63.665 67.6296 65.1136 67.9143 66.1473Z" fill="#A0A0A7"/>
						<path fill-rule="evenodd" clip-rule="evenodd" d="M75.3653 34.4762C75.3653 26.4813 68.8356 20.0001 60.7808 20.0001C56.9021 19.9838 53.1765 21.5018 50.428 24.2183C47.6795 26.9349 46.1345 30.6262 46.1345 34.4762V34.4762" fill="white"/>
						<path d="M75.3653 34.4762C75.3653 26.4813 68.8356 20.0001 60.7808 20.0001V20.0001C56.9021 19.9838 53.1765 21.5018 50.428 24.2183C47.6795 26.9349 46.1345 30.6262 46.1345 34.4762V34.4762" stroke="#A0A0A7" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
						<path d="M72.4507 58.6248L72.5522 58.6297C73.0567 58.6807 73.4507 59.1069 73.4507 59.6248C73.4507 60.1427 73.0567 60.5689 72.5522 60.6199L72.4507 60.6248H72.2925C71.7402 60.6248 71.2925 60.1771 71.2925 59.6248C71.2925 59.0725 71.7402 58.6248 72.2925 58.6248H72.4507Z" stroke="#A0A0A7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
						<path d="M51.2305 58.6249L51.332 58.6298C51.8365 58.6809 52.2305 59.107 52.2305 59.6249C52.2304 60.1428 51.8364 60.569 51.332 60.6201L51.2305 60.6249H51.0723C50.52 60.6249 50.0723 60.1772 50.0723 59.6249C50.0723 59.0727 50.52 58.6249 51.0723 58.6249H51.2305Z" stroke="#A0A0A7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
						<path fill-rule="evenodd" clip-rule="evenodd" d="M82.208 61.0558C81.222 61.0558 80.326 60.4704 79.9163 59.5531C79.5966 58.828 79.1419 56.8535 81.8613 54.1539C82.0054 54.0141 82.2395 54.0097 82.3881 54.1452C85.2021 56.7487 84.8194 58.7406 84.5267 59.4745C84.1395 60.4311 83.2256 61.0558 82.208 61.0558Z" fill="#E4E4E7"/>
						<path d="M19.5583 62.231C19.2511 62.1611 18.9662 62.0154 18.7287 61.8067C18.4911 61.598 18.3083 61.3328 18.1963 61.0344C18.0843 60.7361 18.0465 60.4138 18.0864 60.096C18.1263 59.7783 18.2425 59.4748 18.4249 59.2124C18.6073 58.95 18.8501 58.7368 19.1321 58.5915C19.414 58.4462 19.7264 58.3734 20.0415 58.3794C20.3567 58.3855 20.665 58.4702 20.9392 58.6261C21.2134 58.7821 21.4451 59.0044 21.6137 59.2736C21.8187 59.5986 21.9231 59.9789 21.9136 60.366C21.9042 60.7531 21.7813 61.1294 21.5607 61.4468C21.3401 61.7642 21.0317 62.0084 20.6751 62.1481C20.3184 62.2878 19.9296 62.3166 19.5583 62.231ZM20.1403 59.6765C20.0132 59.6476 19.8803 59.6576 19.7584 59.7054C19.6365 59.7532 19.531 59.8366 19.4554 59.945C19.3798 60.0534 19.3374 60.1819 19.3336 60.3142C19.3298 60.4465 19.3649 60.5767 19.4342 60.6883C19.5036 60.7999 19.6042 60.8878 19.7232 60.9409C19.8423 60.994 19.9745 61.0099 20.103 60.9866C20.2315 60.9633 20.3506 60.9018 20.4451 60.8099C20.5396 60.7181 20.6054 60.6 20.634 60.4706C20.6722 60.2981 20.6417 60.1178 20.5492 59.969C20.4567 59.8203 20.3097 59.7151 20.1403 59.6765Z" fill="#A0A0A7"/>
						<path d="M10.8032 70.6298C10.2991 70.5149 9.84087 70.2509 9.48624 69.8709C9.13161 69.491 8.89647 69.0122 8.81044 68.4949C8.72442 67.9775 8.79136 67.4448 9.00284 66.9638C9.21432 66.4829 9.56086 66.0752 9.9988 65.7922C10.4367 65.5091 10.9465 65.3635 11.4637 65.3735C11.981 65.3835 12.4827 65.5488 12.9055 65.8484C13.3284 66.1481 13.6534 66.5688 13.8398 67.0575C14.0261 67.5462 14.0654 68.0809 13.9527 68.5944C13.8771 68.9376 13.7354 69.2627 13.5359 69.551C13.3365 69.8393 13.0831 70.0851 12.7903 70.2742C12.4976 70.4634 12.1714 70.5922 11.8303 70.6532C11.4893 70.7142 11.1402 70.7063 10.8032 70.6298ZM11.7009 66.6896C11.4387 66.6299 11.1643 66.6507 10.9126 66.7494C10.6609 66.8481 10.4432 67.0203 10.2871 67.2441C10.1311 67.4679 10.0437 67.7333 10.036 68.0065C10.0284 68.2797 10.1009 68.5485 10.2442 68.7787C10.3876 69.0089 10.5954 69.1903 10.8413 69.2997C11.0872 69.4091 11.36 69.4416 11.6253 69.3932C11.8906 69.3448 12.1363 69.2176 12.3312 69.0278C12.5262 68.8379 12.6616 68.5939 12.7204 68.3268C12.798 67.9711 12.7345 67.5996 12.5436 67.2931C12.3528 66.9865 12.0499 66.7697 11.7009 66.6896Z" fill="#A0A0A7"/>
						<path d="M88.2429 30.5842L90.4674 28.2795L91.2085 29.0473L88.984 31.3521L88.2429 30.5842Z" fill="#A0A0A7"/>
						<path d="M85.5 26H86.548V29.2605H85.5V26Z" fill="#A0A0A7"/>
						<path d="M90.353 32.9138H93.5V34H90.353V32.9138Z" fill="#A0A0A7"/>
						</svg>
					</div>
					<p><?php echo esc_html( 'No products in the cart.', 'brandy' ); ?></p>
					<a href="<?php echo esc_url( brandy_get_shop_page_url() ); ?>" class="wp-block-button__link"><?php esc_html_e( 'Continue shopping', 'brandy' ); ?></a>
				</div>

			<?php endif; ?>
			<?php
			do_action( 'woocommerce_after_mini_cart' );
			?>
		</div>
	</div>
	<?php if ( ! WC()->cart->is_empty() ) : ?>
		<div class="brandy-mini-cart-bottom">
			<p class="woocommerce-mini-cart__total total brandy-mini-cart__total">
				<?php
				/**
				 * Hook: woocommerce_widget_shopping_cart_total.
				 *
				 * @hooked woocommerce_widget_shopping_cart_subtotal - 10
				 */
				do_action( 'woocommerce_widget_shopping_cart_total' );
				?>
			</p>

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

			<div class="woocommerce-mini-cart__buttons buttons brandy-mini-cart__buttons">
				<?php
				brandy_render_link_button(
					array(
						'href'  => wc_get_checkout_url(),
						'text'  => esc_html__(
							'Checkout',
							'brandy'
						),
						'class' => 'w-full text-center checkout',
					)
				);
				?>
				<?php echo '<a href="' . esc_url( wc_get_cart_url() ) . '" class="wc-forward view-cart">' . esc_html__( 'View cart', 'brandy' ) . '</a>'; ?>
				<?php do_action( 'woocommerce_widget_shopping_cart_buttons' ); ?>
			</div>
			<?php do_action( 'woocommerce_widget_shopping_cart_after_buttons' ); ?>
		</div>
		<?php
	endif;
	?>
	
</div>
