<?php
/**
 * The template for displaying the booking form and calendar to customers.
 *
 * This template can be overridden by copying it to yourtheme/woocommerce-bookings/booking-form/date-picker.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://woocommerce.com/document/introduction-to-woocommerce-bookings/pages-and-emails-customization/
 * @author  Automattic
 * @version 3.9.0
 * @since   1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

wp_enqueue_script( 'wc-bookings-booking-form' );
extract( $field );

// Get the current year.
$min_year = wp_date( 'Y' );

$month_before_day = strpos( __( 'F j, Y', 'woocommerce-bookings' ), 'F' ) < strpos( __( 'F j, Y', 'woocommerce-bookings' ), 'j' );
?>
<div class="wc-bookings-date-picker wc-bookings-date-picker-<?php echo esc_attr( $product_type ); ?> <?php echo esc_attr( implode( ' ', $class ) ); ?>">
	<?php if ( 'always_visible' !== $display ) : ?>
		<div class="wc-bookings-calendar-announce screen-reader-text" role="status" aria-live="polite" aria-atomic="true"></div>
	<?php endif; ?>
	<div class="picker" data-display="<?php echo esc_attr( $display ); ?>"
		data-duration-unit="<?php echo esc_attr( $duration_unit ); ?>"
		data-default-availability="<?php echo $default_availability ? 'true' : 'false'; ?>"
		data-min_date="<?php echo ! empty( $min_date_js ) ? esc_attr( $min_date_js ) : 0; ?>"
		data-max_date="<?php echo esc_attr( $max_date_js ); ?>"
		data-default_date="<?php echo esc_attr( $default_date ); ?>"
		data-is_range_picker_enabled="<?php echo $is_range_picker_enabled ? 1 : 0; ?>">
	</div>

	<?php
	if ( 'always_visible' !== $display ) :
		?>
		<span class="label"><?php echo esc_html( $label ); ?></span>:
	<?php endif; ?>
	<fieldset class="wc-bookings-date-picker-date-fields">
		<?php if ( 'customer' === $duration_type && $is_range_picker_enabled ) : ?>
			<legend>
				<?php
				/**
				 * Filter the label for the booking date picker start date.
				 *
				 * @param string $label The start date label. Default 'Start'.
				 * @since 1.9.1
				 */
				echo esc_html( apply_filters( 'woocommerce_bookings_date_picker_start_label', __( 'Start', 'woocommerce-bookings' ) ) );
				?>
				:
			</legend>
		<?php else : ?>
			<legend class="screen-reader-text"><?php echo esc_html( $label ); ?></legend>
		<?php endif; ?>

		<?php
		/**
		 * Filter to choose between month/day/year and day/month/year format.
		 *
		 * @param bool $month_before_day Whether month comes before day. Default true.
		 * @since 1.9.10
		 */
		if ( $month_before_day && apply_filters( 'woocommerce_bookings_mdy_format', true ) ) :
		?>
			<label>
				<input type="number" min="1" max="12" autocomplete="off" name="<?php echo esc_attr( $name ); ?>_month" placeholder="<?php esc_attr_e( 'mm', 'woocommerce-bookings' ); ?>" class="booking_date_month" />
				<span><?php esc_html_e( 'Month', 'woocommerce-bookings' ); ?></span>
			</label> /
			<label>
				<input type="number" min="1" max="31" autocomplete="off" name="<?php echo esc_attr( $name ); ?>_day" placeholder="<?php esc_attr_e( 'dd', 'woocommerce-bookings' ); ?>" class="booking_date_day" />
				<span><?php esc_html_e( 'Day', 'woocommerce-bookings' ); ?></span>
			</label>
		<?php else : ?>
			<label>
				<input type="number" min="1" max="31" autocomplete="off" name="<?php echo esc_attr( $name ); ?>_day" placeholder="<?php esc_attr_e( 'dd', 'woocommerce-bookings' ); ?>" class="booking_date_day" />
				<span><?php esc_html_e( 'Day', 'woocommerce-bookings' ); ?></span>
			</label> /
			<label>
				<input type="number" min="1" max="12" autocomplete="off" name="<?php echo esc_attr( $name ); ?>_month" placeholder="<?php esc_attr_e( 'mm', 'woocommerce-bookings' ); ?>" class="booking_date_month" />
				<span><?php esc_html_e( 'Month', 'woocommerce-bookings' ); ?></span>
			</label>
		<?php endif; ?> /
		<label>
			<input type="number" min="<?php echo esc_attr( $min_year ); ?>" autocomplete="off" value="<?php echo esc_attr( wp_date( 'Y' ) ); ?>" name="<?php echo esc_attr( $name ); ?>_year" placeholder="<?php esc_attr_e( 'YYYY', 'woocommerce-bookings' ); ?>" class="booking_date_year" />
			<span><?php esc_html_e( 'Year', 'woocommerce-bookings' ); ?></span>
		</label>
	</fieldset>

	<?php if ( 'customer' === $duration_type && $is_range_picker_enabled ) : ?>
		<fieldset class="wc-bookings-date-picker-date-fields">
			<legend>
				<?php
				/**
				 * Filter the label for the booking date picker end date.
				 *
				 * @param string $label The end date label. Default 'End'.
				 * @since 1.9.1
				 */
				echo esc_html( apply_filters( 'woocommerce_bookings_date_picker_end_label', __( 'End', 'woocommerce-bookings' ) ) );
				?>
				:
			</legend>
			<?php
			/**
			 * Filter to choose between month/day/year and day/month/year format.
			 *
			 * @param bool $month_before_day Whether month comes before day. Default true.
			 * @since 1.9.10
			 */
			if ( $month_before_day && apply_filters( 'woocommerce_bookings_mdy_format', true ) ) :
				?>
				<label>
					<input type="number" min="1" max="12" autocomplete="off" name="<?php echo esc_attr( $name ); ?>_to_month" placeholder="<?php esc_attr_e( 'mm', 'woocommerce-bookings' ); ?>" class="booking_to_date_month" />
					<span><?php esc_html_e( 'Month', 'woocommerce-bookings' ); ?></span>
				</label> /
				<label>
					<input type="number" min="1" max="31" autocomplete="off" name="<?php echo esc_attr( $name ); ?>_to_day" placeholder="<?php esc_attr_e( 'dd', 'woocommerce-bookings' ); ?>" class="booking_to_date_day" />
					<span><?php esc_html_e( 'Day', 'woocommerce-bookings' ); ?></span>
				</label>
			<?php else : ?>
				<label>
					<input type="number" min="1" max="31" autocomplete="off" name="<?php echo esc_attr( $name ); ?>_to_day" placeholder="<?php esc_attr_e( 'dd', 'woocommerce-bookings' ); ?>" class="booking_to_date_day" />
					<span><?php esc_html_e( 'Day', 'woocommerce-bookings' ); ?></span>
				</label> /
				<label>
					<input type="number" min="1" max="12" autocomplete="off" name="<?php echo esc_attr( $name ); ?>_to_month" placeholder="<?php esc_attr_e( 'mm', 'woocommerce-bookings' ); ?>" class="booking_to_date_month" />
					<span><?php esc_html_e( 'Month', 'woocommerce-bookings' ); ?></span>
				</label>
			<?php endif; ?> /
			<label>
				<input type="number" min="<?php echo esc_attr( $min_year ); ?>" autocomplete="off" value="<?php echo esc_attr( wp_date( 'Y' ) ); ?>" name="<?php echo esc_attr( $name ); ?>_to_year" placeholder="<?php esc_attr_e( 'YYYY', 'woocommerce-bookings' ); ?>" class="booking_to_date_year" />
				<span><?php esc_html_e( 'Year', 'woocommerce-bookings' ); ?></span>
			</label>
		</fieldset>
	<?php endif; ?>
</div>
