<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}


use Prodigy\includes\helpers\Prodigy_Elementor_Layouts;
use Prodigy\Includes\Helpers\Prodigy_Formatting;
use Prodigy\Includes\Helpers\Prodigy_Platform_Settings;
use Prodigy\Includes\Helpers\Prodigy_Template;
use Prodigy\Includes\Helpers\Prodigy_Url_Helper;
use Prodigy\Includes\Models\Prodigy_Products;
use Prodigy\Includes\Prodigy;

?>

<?php
	$qv_type = $args['content_archive_products_quick_view_type_position'] ?? 'absolute';
	$widget_uid = ! empty( $idWidget ) ? sanitize_html_class( $idWidget ) : wp_unique_id( 'qv-' );
	$quick_view_modal_id = 'quickViewModal-' . $widget_uid;
?>

<?php if ( isset( $idWidget ) ) : ?>
	<input type="hidden" class="products-widget-id" value="<?php echo esc_attr( $idWidget ); ?>">
<?php endif; ?>

<div class="<?php echo esc_attr( $args['product_list_classname'] ); ?> prodigy-custom-template flex-grow-1">
	<div class="prodigy-loader-wrapper" role="presentation" aria-live="polite" aria-busy="false"
			aria-label="<?php echo esc_attr( 'Content is loading...', 'prodigy-commerce' ); ?>">
		<div class="prodigy-loader">
			<svg width="64px" height="64px" viewBox="0 0 64 64" version="1.1" xmlns="http://www.w3.org/2000/svg"
			>
				<g id="Selected-Loader" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
					<g id="Catalog-Page-With-Loader-Loader" transform="translate(-688, -418)">
						<g id="icn_loader_loader"
							transform="translate(720, 450) rotate(-360) translate(-720, -450)translate(688, 418)">
							<path
								d="M16.48,50.28 L14,53.34 C16.4771768,55.4468051 19.3074278,57.0989133 22.36,58.22 L23.74,54.48 C21.0922325,53.5169929 18.6347128,52.0952873 16.48,50.28 L16.48,50.28 Z"
								id="Path1" fill="#FFFFFF" fill-rule="nonzero"></path>
							<path
								d="M8.38,36 L4.38,36.82 C4.95041759,40.0511083 6.08073052,43.1577768 7.72,46 L11.18,44 C9.7959677,41.5131108 8.8488945,38.8071874 8.38,36 L8.38,36 Z"
								id="Path2" fill="#FFFFFF" fill-rule="nonzero"></path>
							<path
								d="M23.64,9.52 L22.26,5.78 C19.2427153,6.91161657 16.4470946,8.56326659 14,10.66 L16.48,13.72 C18.6046017,11.9147528 21.0275012,10.4934989 23.64,9.52 L23.64,9.52 Z"
								id="Path3" fill="#FFFFFF" fill-rule="nonzero"></path>
							<path
								d="M11.18,20 L7.72,18 C6.11189372,20.8508965 5.00260645,23.955548 4.44,27.18 L8.44,27.86 C8.89053481,25.1009094 9.8176945,22.4412469 11.18,20 L11.18,20 Z"
								id="Path4" fill="#FFFFFF" fill-rule="nonzero"></path>
							<path
								d="M32,4 L32,8 C45.2548339,8 56,18.7451661 56,32 C56,45.2548339 45.2548339,56 32,56 L32,60 C47.4639728,60 60,47.4639728 60,32 C60,16.5360272 47.4639728,4 32,4 Z"
								id="Path5" fill="#FFFFFF" fill-rule="nonzero"></path>
							<rect id="_Transparent_Rectangle_loader" x="0" y="0" width="64" height="64"></rect>
						</g>
					</g>
				</g>
			</svg>
		</div>
	</div>
	<input type="hidden" class="prodigy-category-slug-js"
				value="<?php echo esc_attr( $args['page_object']->slug ?? '' ); ?>">
	<input type="hidden" class="prodigy-category-type-js"
				value="<?php echo esc_attr( Prodigy::get_prodigy_category_type() ); ?>">
<div class="shop-page-container-js">
		<h1 class="prodigy-visually-hidden"><?php esc_html_e( 'Products Catalog', 'prodigy-commerce' ); ?></h1>
		<div class="prodigy-search-filter flex-wrap flex-md-nowrap justify-content-end align-items-center">
		<?php if ( $args['is_show_search'] ) : ?>
			<?php echo ( Prodigy_Elementor_Layouts::is_elementor_template() || Prodigy_Elementor_Layouts::is_elementor_live_preview() ) ? '' : wp_kses( do_shortcode( '[prodigy_search]' ), Prodigy_Formatting::get_allowed_html() ); ?>
		<?php endif; ?>
			<div class="prodigy-custom-select-wrapper justify-content-between justify-content-md-end align-items-center">
			<?php ( Prodigy_Elementor_Layouts::is_elementor_template() || Prodigy_Elementor_Layouts::is_elementor_live_preview() ) ? '' : do_action( 'prodigy_shop_sortable_block' ); ?>
			</div>
		</div>
		<?php if ( ! empty( $args['products'] ) ) : ?>

		<div class="prodigy-product-list__grid mt-20 shop-resolution-js <?php echo Prodigy_Elementor_Layouts::is_elementor_live_preview() ? '' : 'd-none'; ?>">
			<?php foreach ( $args['products'] as $product ) : ?>
				<?php $attributes = $product['attributes']; ?>
				<?php $local_product = Prodigy_Products::get_product_meta_by_remote_id( 'prodigy_remote_product_id', (int) $product['id'] ); ?>
					<div class="prodigy-product-list__item">
				<?php if ( $args['enable_sale_badge'] && $product['attributes']['sale-price'] !== null ) : ?>
			<div class="<?php echo esc_attr( $args['sale_classname'] ); ?>"><?php esc_html_e( 'Sale', 'prodigy-commerce' ); ?></div>
				<?php endif; ?>
				<?php if ( isset( $local_product ) ) : ?>
					<?php if ( Prodigy_Formatting::is_stoked_category( $attributes['categories-slug-list'] ?? '', $args['stock_label_category'] ?? null ) ) : ?>
									<span class="prodigy-product-list__item-title-label prodigy-product-list__item-title-label--absolute">
								<?php esc_html_e( 'STOCKED ITEM', 'prodigy-commerce' ); ?>
							</span>
					<?php endif; ?>
				<?php endif; ?>
						<div class="prodigy-product-list__item-container">
							<div <?php echo ( $args['image_ratio'] !== '' ) ? 'style="padding-top: ' . esc_attr( $args['image_ratio'] ) . '%"' : ''; ?>
								class="prodigy-product-list__link-wrp">
					<?php if ( isset( $local_product ) ) : ?>
						<?php $image_ratio_style = isset( $args['customizer_general_options']['prodigy_general_images'] ) ? 'prodigy-product-list__link-wrp--' . $args['customizer_general_options']['prodigy_general_images'] : ''; ?>
										<a class="prodigy-product-list__item-preview <?php echo esc_attr( $image_ratio_style ); ?>"
											href="<?php echo esc_url( Prodigy_Url_Helper::get_product_page_url( $local_product ) ); ?>"
											rel="nofollow noopener">
											<span
												class="prodigy-visually-hidden"><?php echo esc_html( $product['attributes']['name'] ?? '' ); ?></span>
											<i class="icon icon-image" aria-hidden="true" role="presentation"></i>
									<?php echo get_product_logo_image_template( $attributes ); ?>
										</a>
						<?php if ( $args['enable_quick_view'] ) : ?>
											<div class="modal fade prodigy-modal__overlay" id="<?php echo esc_attr( $quick_view_modal_id ); ?>" tabindex="-1"
													aria-labelledby="<?php echo esc_attr( $quick_view_modal_id ); ?>Label"
													role="dialog"
													aria-modal="true">
												<div class="modal-dialog modal-dialog-scrollable quick-view prodigy-custom-template">
													<div class="modal-content">
														<div class="prodigy-close__quick-view text-right">
															<button type="button" class="close" data-dismiss="modal"
																			aria-label="Close">
																<span aria-hidden="true" role="presentation">&times;</span>
															</button>
														</div>
														<div class="modal-body"></div>
													</div>
												</div>
											</div>
											<?php if ( $qv_type === 'absolute' ) : ?>
												<button type="button"
														id="quickViewModalButton-<?php echo esc_attr( $widget_uid . '-' . $local_product->post_id ); ?>"
														class="prodigy-main-button prodigy-product-list__quick-view quick-view-js"
														data-id="<?php echo esc_attr( $local_product->post_id ); ?>"
														data-widget-id="<?php echo esc_attr( $widget_uid ); ?>"
														data-modal-id="<?php echo esc_attr( $quick_view_modal_id ); ?>"
												>
														<?php echo esc_html( $args['quick_view_title'] ?? __( 'Quick view', 'prodigy-commerce' ) ); ?>
												</button>
											<?php endif; ?>

						<?php endif; ?>
					<?php endif; ?>
							</div>

				<?php if ( $args['enable_category'] ) : ?>
									<p class="prodigy-product-list__item-category">
						<?php echo esc_attr( $attributes['categories-list'] ); ?>
									</p>
				<?php endif; ?>
							<p class="prodigy-product-list__item-title">
					<?php if ( isset( $local_product ) ) : ?>
						<?php if ( Prodigy_Formatting::is_stoked_category( $attributes['categories-slug-list'] ?? '', $args['stock_label_category'] ?? null ) ) : ?>
											<span class="prodigy-product-list__item-title-label">
										<?php esc_html_e( 'STOCKED ITEM', 'prodigy-commerce' ); ?>
									</span>
						<?php endif; ?>

										<a href="<?php echo esc_url( Prodigy_Url_Helper::get_product_page_url( $local_product ) ); ?>"
											<?php /* translators: %s: product name */ ?>
											aria-label="<?php echo esc_attr( sprintf( __( 'View details for %s', 'prodigy-commerce' ), $product['attributes']['name'] ) ); ?>"
											rel="nofollow noopener"
										>
						<?php echo esc_attr( $product['attributes']['name'] ); ?>
										</a>
					<?php endif; ?>
							</p>
				<?php if ( $args['enable_rating'] ) : ?>
					<?php do_action( 'prodigy_product_loop_rating_stars', array( 'product' => $attributes ) ); ?>
				<?php endif; ?>
				<?php if ( Prodigy_Platform_Settings::is_redemption_store_status() ) : ?>
					<?php
					do_action(
						'prodigy_products_price_block',
						array(
							'attributes'     => $attributes,
							'show_min_price' => $show_min_price,
						)
					);
					?>
				<?php endif; ?>
				<?php if ( $args['enable_quick_view'] && $qv_type === 'static' ) : ?>
					<button type="button"
							id="quickViewModalButton-<?php echo esc_attr( $widget_uid . '-' . $local_product->post_id ); ?>"
							class="prodigy-main-button prodigy-product-list__quick-view position-static quick-view-js"
							data-id="<?php echo esc_attr( $local_product->post_id ); ?>"
							data-widget-id="<?php echo esc_attr( $widget_uid ); ?>"
							data-modal-id="<?php echo esc_attr( $quick_view_modal_id ); ?>"
					>
							<?php echo esc_html( $args['quick_view_title'] ?? __( 'Quick view', 'prodigy-commerce' ) ); ?>
					</button>
				<?php endif; ?>
						</div>
					</div>
		<?php endforeach; ?>
			<?php
		else :
			esc_html( Prodigy_Template::prodigy_get_template( 'shop/no-search-results.php' ) );
		endif;
		?>
		</div>
	</div>
	<div class="prodigy-pagination prodigy-pagination-shop-js" role="navigation"
			aria-label="<?php echo esc_attr( 'Pagination', 'prodigy-commerce' ); ?>">
		<?php echo wp_kses( Prodigy_Template::prodigy_get_template_html( 'shop/pagination.php', array( 'data' => $args['pagination'] ?? array() ) ), Prodigy_Formatting::get_allowed_html() ); ?>
	</div>
</div>

<div class="quick-view mfp-hide prodigy-custom-template" id="quick-view-js">
	<div id="quick-view-content-js" class="flex-grow-1 container"></div>
</div>
