<?php

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

?>

<div class="prodigy-custom-template">
	<div class="container d-lg-none">
		<div class="prodigy-product-list-options">
			<a class="prodigy-product-list-options__filter filter-js" href="#filter" role="button" rel="nofollow noopener">
				<div class="icon icon-filter prodigy-product-list-options__filter-icon" role="presentation" aria-hidden="true"></div>
				<span class="prodigy-product-list-options__filter-txt"><?php esc_html_e( 'FILTER', 'prodigy-commerce' ); ?></span>
			</a>
			<div class="prodigy-product-list-options__results">
				<div class="prodigy-product-list-options__results-label">
					<?php if ( ! empty( $search ) ) : ?>
						<?php esc_html_e( 'Search results for', 'prodigy-commerce' ); ?> <span
						class="prodigy-sort__results-item"><?php echo esc_attr( $search ); ?></span>
					<?php endif; ?>
					<?php echo esc_html__( 'Showing:', 'prodigy-commerce' ) . '&nbsp;'; ?>
				</div>

				<div class="prodigy-product-list-options__results-data">
					<?php if ( isset( $from, $to, $of ) ) : ?>
						<?php
						printf(
							/* translators: 1: from number, 2: to number, 3: total results count */
							esc_html__( '%1$s - %2$s of %3$s results', 'prodigy-commerce' ),
							esc_attr( $from ),
							esc_attr( $to ),
							esc_attr( $of )
						);
						?>
					<?php endif; ?>
				</div>
			</div>

			<div class="prodigy-dropdown dropdown prodigy-product-list-options__dropdown">
				<select class="prodigy-main-select" aria-label="<?php esc_html_e( 'Select sorting', 'prodigy-commerce' ); ?>" onchange="location = this.value;">
					<option
						value="<?php echo esc_attr( add_query_arg( 'sort', '-created_at', esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ) ) ) ); ?>"
						<?php echo ( sanitize_text_field( $sort[1] ) === '-created_at' ) ? 'selected' : ''; ?>>
						<?php esc_html_e( 'Sort by newness', 'prodigy-commerce' ); ?>
					</option>
					<option
						value="<?php echo esc_attr( add_query_arg( 'sort', '-rating', esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ) ) ) ); ?>"
						<?php echo ( sanitize_text_field( $sort[1] ) === '-rating' ) ? 'selected' : ''; ?>>
						<?php esc_html_e( 'Sort by average rating', 'prodigy-commerce' ); ?>
					</option>
					<option
						value="<?php echo esc_attr( add_query_arg( 'sort', 'price', esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ) ) ) ); ?>"
						<?php echo ( sanitize_text_field( $sort[1] ) === 'price' ) ? 'selected' : ''; ?>>
						<?php esc_html_e( 'Sort by price: low to high', 'prodigy-commerce' ); ?>
					</option>
					<option
						value="<?php echo esc_attr( add_query_arg( 'sort', '-price', esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ) ) ) ); ?>"
						<?php echo ( sanitize_text_field( $sort[1] ) === '-price' ) ? 'selected' : ''; ?>>
						<?php esc_html_e( 'Sort by price: high to low', 'prodigy-commerce' ); ?>
					</option>
				</select>
			</div>
		</div>
	</div>

</div>
