<?php
/**
 * Availability check filter form.
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/hbfwc/availability-filter-form.php.
 *
 * @package HBFWC\Templates
 * @version 1.0.0
 */

defined( 'ABSPATH' ) || exit;

do_action( 'hbfwc_template_before_availability_filter_form', $query_args );
?>

<form id="hbfwc-availability-filter__form" method="get" action="<?php print esc_attr( get_permalink() ); ?>">
	<div class="availability-filter__dates" data-mindate="<?php print esc_attr( wp_date( 'm/d/Y', hbfwc_default_checkin_date() ) ); ?>" data-output-format="<?php print esc_attr( hbfwc_get_date_format() ); ?>">
		<input type="hidden" name="checkin" value="<?php print esc_attr( $query_args['checkin'] ); ?>" />
		<input type="hidden" name="checkout" value="<?php print esc_attr( $query_args['checkout'] ); ?>" />
		<div class="availability-filter__output availability-filter__output-dates">
			<h4 class="availability-filter__label"><?php print esc_html__( 'Checkin &amp; Checkout', 'hotel-booking-for-woocommerce' ); ?></h4>
			<div class="availability-filter__content">
				<?php print esc_html( $query_args['checkin_date']->format( hbfwc_get_date_format() ) ) . ' &ndash; ' . esc_html( $query_args['checkout_date']->format( hbfwc_get_date_format() ) ); ?>
			</div>
		</div>
	</div>
	<div class="availability-filter__room">
		<div class="availability-filter__output">
			<h4 class="availability-filter__label">
				<?php
				if ( hbfwc_show_rooms_field() ) {
					print esc_html__( 'Rooms &amp; Guests', 'hotel-booking-for-woocommerce' );
				} else {
					print esc_html__( 'Guests', 'hotel-booking-for-woocommerce' );
				}
				?>
			</h4>
			<div class="availability-filter__content">
			<?php
				if ( hbfwc_show_rooms_field() ) {
					$_rooms_count = isset( $query_args['rooms'] ) ? absint( $query_args['rooms'] ) : 1;
					print '<span class="availability-filter__content_span content-rooms">' . sprintf(
						esc_html(
						/* translators: Number of rooms */
							_n( '%s Room', '%s Rooms', $_rooms_count, 'hotel-booking-for-woocommerce' )
						),
						$_rooms_count
					) . '</span>';
				}
				print '<span class="availability-filter__content_span content-adults">' . sprintf(
					esc_html(
					/* translators: Number of adults */
						_n( '%s Adult', '%s Adults', $query_args['adults'], 'hotel-booking-for-woocommerce' )
					),
					absint( $query_args['adults'] )
				) . '</span>';

				print '<span class="availability-filter__content_span content-children">' . sprintf(
					esc_html(
					/* translators: Number of children */
						_n( '%s Child', '%s Children', $query_args['children'], 'hotel-booking-for-woocommerce' )
					),
					absint( $query_args['children'] )
				) . '</span>';
				?>
			</div>
		</div>
		<div class="availability-filter__dd">
			<?php if ( hbfwc_show_rooms_field() ) : ?>
			<div>
				<label for="rooms"><?php print esc_html__( 'Rooms', 'hotel-booking-for-woocommerce' ); ?></label>
				<input type="number" name="rooms" id="rooms" class="hbfgwc-with-buttons" value="<?php print esc_attr( isset( $query_args['rooms'] ) ? $query_args['rooms'] : 1 ); ?>" min="1" step="1" />
			</div>
			<?php endif; ?>
			<div>
				<label for="adults"><?php print esc_html__( 'Adults', 'hotel-booking-for-woocommerce' ); ?></label>
				<input type="number" name="adults" id="adults" class="hbfgwc-with-buttons" value="<?php print esc_attr( $query_args['adults'] ); ?>" min="1" step="1" />			
			</div>
			<div>
				<label for="children"><?php print esc_html__( 'Children', 'hotel-booking-for-woocommerce' ); ?></label>
				<input type="number" name="children" id="children" class="hbfgwc-with-buttons" value="<?php print esc_attr( $query_args['children'] ); ?>" min="0" step="1" />			
			</div>
		<?php
		if ( ! empty( $query_args['child_ages'] ) ) {
			$count = 1;
			foreach ( $query_args['child_ages'] as $child_age ) {
				print '<div class="hhbfwc-children-age-slider" id="hhbfwc-children-age-slider__' . esc_attr( $count ) . '">
						<span class="hhbfwc-children-age-slider__label">' . sprintf(
						/* translators: Number of loop */
					esc_html__( 'Children #%d age', 'hotel-booking-for-woocommerce' ),
					absint( $count )
				) . '</span>
						<span class="hhbfwc-children-age-slider__input">
							<input type="range" id="children_age_' . esc_attr( $count ) . '" name="children_age[]" value="' . esc_attr( $child_age ) . '" min="0" max="' . esc_attr( hbfwc_get_max_children_age() ) . '" step="1" oninput="this.nextElementSibling.innerHTML = this.value" />
							<label for="children_age_' . esc_attr( $count ) . '">' . esc_html( $child_age ) . '</label>
						</span>
					</div>' . "\n";
				++$count;
			}
		}
		?>
		</div>

	</div>
	<div class="availability-filter__button">
		<button type="submit" class="hbfwc-filter-button button wc-forward wp-element-button"><?php print esc_html( hbfwc_filter_button_text() ); ?></button>
	</div>
</form>

<?php
do_action( 'hbfwc_template_after_availability_filter_form' );
