<?php
/**
 * Public view: registration form for a single event.
 *
 * Layout: the poster keeps its own proportions in a third of the width, the details
 * take the other two thirds. On a phone the poster comes first, full width and
 * uncropped, then the details and the form.
 *
 * @package BitForgeNet_Guest_Tickets
 *
 * @var object     $event  Event row.
 * @var array|null $result Submission result.
 */

defined( 'ABSPATH' ) || exit;

// This file is a template: it is included from a method -- never at file
// scope -- so everything declared here belongs to that method's variable
// scope and not to the global one. PHPCS reads each file on its own and has
// no way to see where the include happens, so it reads these as globals.
// Stated once, for the whole file, per this plugin's suppression rule.
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound

$bfnet_venue     = BFNET_Venue::get( $event->venue_id );
$bfnet_organizer = BFNET_Organizer::get( $event->organizer_id );
$bfnet_types     = BFNET_Offers::tiers( $event->id );
$bfnet_open      = BFNET_Event::registration_open( $event );
$bfnet_left      = BFNET_Event::seats_left( $event );
$bfnet_max       = (int) $event->max_per_order;
if ( null !== $bfnet_left ) {
	$bfnet_max = max( 1, min( $bfnet_max, $bfnet_left ) );
}

$bfnet_cover  = BFNET_Event::cover_url( $event, 'full' );
$bfnet_lineup = BFNET_Event::lineup( $event );
$bfnet_map    = BFNET_Venue::map_url( $bfnet_venue );
$bfnet_price  = BFNET_Offers::price( $event, $bfnet_types ? $bfnet_types[0] : null );

$bfnet_tz    = BFNET_Util::event_timezone( $event );
$bfnet_abbr  = BFNET_Util::tz_abbr( $event->starts_at, $bfnet_tz );
$bfnet_start = BFNET_Util::event_ts( $event, 'starts_at' );

$bfnet_min_age  = (int) $event->min_age;
$bfnet_age_mode = isset( $event->age_check_mode ) ? $event->age_check_mode : 'off';
$bfnet_age_on   = $bfnet_min_age > 0 && 'off' !== $bfnet_age_mode;
$bfnet_dob      = $bfnet_age_on && 'dob' === $bfnet_age_mode;

// Latest birth date that still satisfies the minimum age on the night of the event,
// worked out from the event's own calendar date rather than a UTC instant.
$bfnet_dob_max = '';
if ( $bfnet_dob ) {
	$bfnet_event_day = BFNET_Util::event_date( $event, 'starts_at', 'Y-m-d' );
	if ( '—' !== $bfnet_event_day ) {
		try {
			$bfnet_dob_max = ( new DateTimeImmutable( $bfnet_event_day . ' 00:00:00', new DateTimeZone( 'UTC' ) ) )
				->modify( '-' . $bfnet_min_age . ' years' )
				->format( 'Y-m-d' );
		} catch ( Exception $e ) {
			$bfnet_dob_max = '';
		}
	}
}

$bfnet_legal = BFNET_Util::legal_links( $event );
?>
<div class="bfnet" data-bfnet-event="<?php echo (int) $event->id; ?>">

	<?php if ( ! empty( $result['error'] ) ) : ?>
		<div class="bfnet-alert bfnet-alert--error" role="alert"><?php echo esc_html( $result['error'] ); ?></div>
	<?php endif; ?>

	<article class="bfnet-event">

		<?php if ( $bfnet_cover ) : ?>
			<div class="bfnet-event__poster">
				<img src="<?php echo esc_url( $bfnet_cover ); ?>" alt="<?php echo esc_attr( $event->title ); ?>">
			</div>
		<?php endif; ?>

		<div class="bfnet-event__main<?php echo $bfnet_cover ? '' : ' bfnet-event__main--wide'; ?>">

			<?php if ( $event->series ) : ?>
				<p class="bfnet-eyebrow"><?php echo esc_html( $event->series ); ?><?php echo $event->edition ? ' · ' . esc_html( $event->edition ) : ''; ?></p>
			<?php endif; ?>

			<h2 class="bfnet-event__title"><?php echo esc_html( $event->title ); ?></h2>

			<?php if ( $event->subtitle ) : ?>
				<p class="bfnet-event__subtitle"><?php echo esc_html( $event->subtitle ); ?></p>
			<?php endif; ?>

			<?php if ( $bfnet_start && $bfnet_start > time() ) : ?>
				<div class="bfnet-countdown" data-bfnet-countdown="<?php echo (int) $bfnet_start; ?>">
					<span class="bfnet-countdown__label"><?php esc_html_e( 'Starts in', 'bitforgenet-guest-tickets' ); ?></span>
					<span class="bfnet-countdown__value"><?php echo esc_html( human_time_diff( time(), $bfnet_start ) ); ?></span>
				</div>
			<?php endif; ?>

			<dl class="bfnet-facts">
				<div class="bfnet-fact">
					<dt><?php esc_html_e( 'Date', 'bitforgenet-guest-tickets' ); ?></dt>
					<dd><?php echo esc_html( BFNET_Util::event_date( $event, 'starts_at', 'l j F Y' ) ); ?></dd>
				</div>

				<div class="bfnet-fact">
					<dt><?php esc_html_e( 'Time', 'bitforgenet-guest-tickets' ); ?></dt>
					<dd>
						<?php echo esc_html( BFNET_Util::event_date( $event, 'starts_at', get_option( 'time_format' ) ) ); ?>
						<?php if ( $bfnet_abbr ) : ?><span class="bfnet-tz"><?php echo esc_html( $bfnet_abbr ); ?></span><?php endif; ?>
						<?php if ( ! empty( $event->doors_open_at ) && '0000-00-00 00:00:00' !== $event->doors_open_at ) : ?>
							<span class="bfnet-muted bfnet-block">
								<?php
								/* translators: %s: doors opening time. */
								echo esc_html( sprintf( __( 'Doors open at %s', 'bitforgenet-guest-tickets' ), BFNET_Util::event_date( $event, 'doors_open_at', get_option( 'time_format' ) ) ) );
								?>
							</span>
						<?php endif; ?>
						<span class="bfnet-muted bfnet-block bfnet-localtime" data-bfnet-localtime="<?php echo (int) $bfnet_start; ?>" hidden></span>
					</dd>
				</div>

				<?php if ( $bfnet_venue ) : ?>
					<div class="bfnet-fact">
						<dt><?php esc_html_e( 'Venue', 'bitforgenet-guest-tickets' ); ?></dt>
						<dd>
							<?php echo esc_html( $bfnet_venue->name ); ?>
							<?php if ( $bfnet_map ) : ?>
								<a class="bfnet-maplink" href="<?php echo esc_url( $bfnet_map ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Open in Maps', 'bitforgenet-guest-tickets' ); ?></a>
							<?php endif; ?>
							<span class="bfnet-muted bfnet-block"><?php echo esc_html( BFNET_Venue::address_line( $bfnet_venue ) ); ?></span>
						</dd>
					</div>
				<?php endif; ?>

				<?php if ( $bfnet_organizer ) : ?>
					<div class="bfnet-fact">
						<dt><?php esc_html_e( 'Organizer', 'bitforgenet-guest-tickets' ); ?></dt>
						<dd><?php echo esc_html( $bfnet_organizer->name ); ?></dd>
					</div>
				<?php endif; ?>

				<?php if ( $bfnet_lineup ) : ?>
					<div class="bfnet-fact">
						<dt><?php esc_html_e( 'Line-up', 'bitforgenet-guest-tickets' ); ?></dt>
						<dd>
							<?php
							$bfnet_parts = array();
							foreach ( $bfnet_lineup as $bfnet_item ) {
								$bfnet_parts[] = $bfnet_item['name'] . ( $bfnet_item['role'] ? ' (' . $bfnet_item['role'] . ')' : '' );
							}
							echo esc_html( implode( ' · ', $bfnet_parts ) );
							?>
						</dd>
					</div>
				<?php endif; ?>

				<?php if ( $event->dress_code ) : ?>
					<div class="bfnet-fact">
						<dt><?php esc_html_e( 'Dress code', 'bitforgenet-guest-tickets' ); ?></dt>
						<dd><?php echo esc_html( $event->dress_code ); ?></dd>
					</div>
				<?php endif; ?>

				<?php if ( $bfnet_min_age > 0 ) : ?>
					<div class="bfnet-fact">
						<dt><?php esc_html_e( 'Admission', 'bitforgenet-guest-tickets' ); ?></dt>
						<dd>
							<?php
							/* translators: %d: minimum age. */
							echo esc_html( sprintf( __( '%d years and over', 'bitforgenet-guest-tickets' ), $bfnet_min_age ) );
							?>
						</dd>
					</div>
				<?php endif; ?>

				<div class="bfnet-fact">
					<dt><?php esc_html_e( 'Price', 'bitforgenet-guest-tickets' ); ?></dt>
					<dd>
						<?php if ( $bfnet_price > 0 ) : ?>
							<strong><?php echo esc_html( BFNET_Util::money( $bfnet_price, $event->currency ) ); ?></strong>
							<?php if ( count( $bfnet_types ) > 1 ) : ?>
								<span class="bfnet-muted"><?php esc_html_e( 'and up', 'bitforgenet-guest-tickets' ); ?></span>
							<?php endif; ?>
						<?php else : ?>
							<?php esc_html_e( 'Free entry', 'bitforgenet-guest-tickets' ); ?>
						<?php endif; ?>
					</dd>
				</div>
			</dl>

			<?php if ( ! empty( $event->menu_enabled ) && ( $event->menu_title || $event->menu_body ) ) : ?>
				<section class="bfnet-menu">
					<h3><?php echo esc_html( $event->menu_title ? $event->menu_title : __( 'On the table', 'bitforgenet-guest-tickets' ) ); ?></h3>
					<?php if ( $event->menu_body ) : ?>
						<div class="bfnet-menu__body"><?php echo wp_kses_post( wpautop( $event->menu_body ) ); ?></div>
					<?php endif; ?>
				</section>
			<?php endif; ?>

			<?php if ( $event->description ) : ?>
				<div class="bfnet-prose"><?php echo wp_kses_post( wpautop( $event->description ) ); ?></div>
			<?php endif; ?>

			<?php if ( null !== $bfnet_left && $bfnet_left > 0 && $bfnet_left <= 20 ) : ?>
				<p class="bfnet-scarcity">
					<?php
					/* translators: %d: seats remaining. */
					echo esc_html( sprintf( _n( 'Only %d ticket left', 'Only %d tickets left', $bfnet_left, 'bitforgenet-guest-tickets' ), $bfnet_left ) );
					?>
				</p>
			<?php endif; ?>
		</div>
	</article>

	<?php if ( ! $bfnet_open ) : ?>

		<div class="bfnet-alert bfnet-alert--info"><?php echo esc_html( BFNET_Event::closed_reason( $event ) ); ?></div>

	<?php else : ?>

		<?php
// After an "Apply" round trip the page is redrawn, so everything the guest has
// already typed has to come back with it. Nothing else reads $_POST here.
$bfnet_back = ! empty( $_POST['bfnet_apply_code'] ); // phpcs:ignore WordPress.Security.NonceVerification
$bfnet_old  = static function ( $key, $fallback = '' ) use ( $bfnet_back ) {
	if ( ! $bfnet_back || ! isset( $_POST[ $key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
		return $fallback;
	}
	return sanitize_text_field( wp_unslash( $_POST[ $key ] ) ); // phpcs:ignore WordPress.Security.NonceVerification
};
$bfnet_guest_old = static function ( $index, $key, $fallback = '' ) use ( $bfnet_back ) {
	// phpcs:ignore WordPress.Security.NonceVerification
	if ( ! $bfnet_back || ! isset( $_POST['bfnet_guest'][ $index ][ $key ] ) ) {
		return $fallback;
	}
	return sanitize_text_field( wp_unslash( $_POST['bfnet_guest'][ $index ][ $key ] ) ); // phpcs:ignore WordPress.Security.NonceVerification
};
?>
<form class="bfnet-form" method="post" action="<?php echo esc_url( remove_query_arg( array( 'bfnet_confirmed' ) ) ); ?>" novalidate>
			<?php wp_nonce_field( 'bfnet_register', 'bfnet_nonce' ); ?>
			<input type="hidden" name="bfnet_action" value="register">
			<input type="hidden" name="bfnet_event_id" value="<?php echo (int) $event->id; ?>">
			<input type="hidden" name="bfnet_started" value="<?php echo (int) time(); ?>">

			<div class="bfnet-hp" aria-hidden="true">
				<label for="bfnet-website"><?php esc_html_e( 'Leave this field empty', 'bitforgenet-guest-tickets' ); ?></label>
				<input type="text" id="bfnet-website" name="bfnet_website" tabindex="-1" autocomplete="off" value="">
			</div>

			<fieldset class="bfnet-fieldset">
				<legend><?php esc_html_e( '1. Who is booking?', 'bitforgenet-guest-tickets' ); ?></legend>
				<div class="bfnet-grid">
					<p class="bfnet-field">
						<label for="bfnet-first"><?php esc_html_e( 'First name', 'bitforgenet-guest-tickets' ); ?> <span class="bfnet-req">*</span></label>
						<input type="text" id="bfnet-first" name="bfnet_first_name" required autocomplete="given-name" maxlength="80" value="<?php echo esc_attr( $bfnet_old( 'bfnet_first_name' ) ); ?>">
					</p>
					<p class="bfnet-field">
						<label for="bfnet-last"><?php esc_html_e( 'Last name', 'bitforgenet-guest-tickets' ); ?> <span class="bfnet-req">*</span></label>
						<input type="text" id="bfnet-last" name="bfnet_last_name" required autocomplete="family-name" maxlength="80" value="<?php echo esc_attr( $bfnet_old( 'bfnet_last_name' ) ); ?>">
					</p>
					<p class="bfnet-field">
						<label for="bfnet-email"><?php esc_html_e( 'Email', 'bitforgenet-guest-tickets' ); ?> <span class="bfnet-req">*</span></label>
						<input type="email" id="bfnet-email" name="bfnet_email" required autocomplete="email" maxlength="190" value="<?php echo esc_attr( $bfnet_old( 'bfnet_email' ) ); ?>">
						<span class="bfnet-help"><?php esc_html_e( 'Your tickets are sent to this address.', 'bitforgenet-guest-tickets' ); ?></span>
					</p>
					<p class="bfnet-field">
						<label for="bfnet-phone">
							<?php esc_html_e( 'Phone / WhatsApp', 'bitforgenet-guest-tickets' ); ?>
							<?php if ( (int) BFNET_Settings::get( 'require_phone', 1 ) ) : ?><span class="bfnet-req">*</span><?php endif; ?>
						</label>
						<input type="tel" id="bfnet-phone" name="bfnet_phone" <?php echo (int) BFNET_Settings::get( 'require_phone', 1 ) ? 'required' : ''; ?> autocomplete="tel" maxlength="40" value="<?php echo esc_attr( $bfnet_old( 'bfnet_phone' ) ); ?>">
					</p>
				</div>
			</fieldset>

			<fieldset class="bfnet-fieldset">
				<legend><?php esc_html_e( '2. How many tickets?', 'bitforgenet-guest-tickets' ); ?></legend>

				<div class="bfnet-qty">
					<button type="button" class="bfnet-qty__btn" data-bfnet-step="-1" aria-label="<?php esc_attr_e( 'Remove one place', 'bitforgenet-guest-tickets' ); ?>">−</button>
					<input type="number" id="bfnet-quantity" name="bfnet_quantity" value="<?php echo esc_attr( $bfnet_old( 'bfnet_quantity', '1' ) ); ?>" min="1" max="<?php echo (int) $bfnet_max; ?>" step="1" inputmode="numeric">
					<button type="button" class="bfnet-qty__btn" data-bfnet-step="1" aria-label="<?php esc_attr_e( 'Add one place', 'bitforgenet-guest-tickets' ); ?>">+</button>
					<span class="bfnet-qty__max">
						<?php
						/* translators: %d: maximum tickets per booking. */
						echo esc_html( sprintf( __( 'max %d per booking', 'bitforgenet-guest-tickets' ), (int) $bfnet_max ) );
						?>
					</span>
				</div>

				<p class="bfnet-help bfnet-help--block"><?php esc_html_e( 'One payment can cover several people. Every guest receives their own ticket with their own QR code, so each person is scanned individually at the door.', 'bitforgenet-guest-tickets' ); ?></p>

				<div class="bfnet-guests" id="bfnet-guests" data-max="<?php echo (int) $bfnet_max; ?>">
					<?php for ( $bfnet_i = 0; $bfnet_i < $bfnet_max; $bfnet_i++ ) : ?>
						<div class="bfnet-guest" data-index="<?php echo (int) $bfnet_i; ?>" <?php echo $bfnet_i > 0 ? 'hidden' : ''; ?>>
							<h4 class="bfnet-guest__title">
								<?php
								if ( 0 === $bfnet_i ) {
									esc_html_e( 'Guest 1 — the person booking', 'bitforgenet-guest-tickets' );
								} else {
									/* translators: %d: guest number. */
									echo esc_html( sprintf( __( 'Guest %d', 'bitforgenet-guest-tickets' ), $bfnet_i + 1 ) );
								}
								?>
							</h4>
							<div class="bfnet-grid">
								<p class="bfnet-field">
									<label for="bfnet-g<?php echo (int) $bfnet_i; ?>-first"><?php esc_html_e( 'First name', 'bitforgenet-guest-tickets' ); ?></label>
									<input type="text" id="bfnet-g<?php echo (int) $bfnet_i; ?>-first" name="bfnet_guest[<?php echo (int) $bfnet_i; ?>][first_name]" maxlength="80" value="<?php echo esc_attr( $bfnet_guest_old( $bfnet_i, 'first_name' ) ); ?>" <?php echo 0 === $bfnet_i ? 'data-bfnet-mirror="bfnet-first"' : ''; ?>>
								</p>
								<p class="bfnet-field">
									<label for="bfnet-g<?php echo (int) $bfnet_i; ?>-last"><?php esc_html_e( 'Last name', 'bitforgenet-guest-tickets' ); ?></label>
									<input type="text" id="bfnet-g<?php echo (int) $bfnet_i; ?>-last" name="bfnet_guest[<?php echo (int) $bfnet_i; ?>][last_name]" maxlength="80" value="<?php echo esc_attr( $bfnet_guest_old( $bfnet_i, 'last_name' ) ); ?>" <?php echo 0 === $bfnet_i ? 'data-bfnet-mirror="bfnet-last"' : ''; ?>>
								</p>

								<?php if ( $bfnet_dob ) : ?>
									<p class="bfnet-field">
										<label for="bfnet-g<?php echo (int) $bfnet_i; ?>-dob"><?php esc_html_e( 'Date of birth', 'bitforgenet-guest-tickets' ); ?> <span class="bfnet-req">*</span></label>
										<input type="date" id="bfnet-g<?php echo (int) $bfnet_i; ?>-dob" name="bfnet_guest[<?php echo (int) $bfnet_i; ?>][birth_date]"
											<?php echo $bfnet_dob_max ? 'max="' . esc_attr( $bfnet_dob_max ) . '"' : ''; ?>
											data-bfnet-dob>
										<span class="bfnet-help">
											<?php
											/* translators: %d: minimum age. */
											echo esc_html( sprintf( __( 'Must be %d or over on the night.', 'bitforgenet-guest-tickets' ), $bfnet_min_age ) );
											?>
										</span>
									</p>
								<?php endif; ?>

								<?php if ( count( $bfnet_types ) > 1 ) : ?>
									<p class="bfnet-field bfnet-field--wide">
										<label for="bfnet-g<?php echo (int) $bfnet_i; ?>-type"><?php esc_html_e( 'Ticket category', 'bitforgenet-guest-tickets' ); ?></label>
										<select id="bfnet-g<?php echo (int) $bfnet_i; ?>-type" name="bfnet_guest[<?php echo (int) $bfnet_i; ?>][ticket_type_id]" data-bfnet-price>
											<?php foreach ( $bfnet_types as $bfnet_type ) : ?>
												<option value="<?php echo (int) $bfnet_type->id; ?>" data-price="<?php echo (int) BFNET_Offers::price( $event, $bfnet_type ); ?>">
													<?php echo esc_html( $bfnet_type->name . ' — ' . BFNET_Util::money( BFNET_Offers::price( $event, $bfnet_type ), $event->currency ) ); ?>
												</option>
											<?php endforeach; ?>
										</select>
									</p>
								<?php else : ?>
									<input type="hidden" name="bfnet_guest[<?php echo (int) $bfnet_i; ?>][ticket_type_id]" value="<?php echo $bfnet_types ? (int) $bfnet_types[0]->id : 0; ?>" data-bfnet-price data-price="<?php echo (int) $bfnet_price; ?>">
								<?php endif; ?>
							</div>
						</div>
					<?php endfor; ?>
				</div>
			</fieldset>

			<fieldset class="bfnet-fieldset">
				<legend><?php esc_html_e( '3. Confirm', 'bitforgenet-guest-tickets' ); ?></legend>

				<p class="bfnet-field">
					<label for="bfnet-note"><?php esc_html_e( 'Anything we should know? (optional)', 'bitforgenet-guest-tickets' ); ?></label>
					<textarea id="bfnet-note" name="bfnet_note" rows="3" maxlength="800"><?php echo esc_textarea( $bfnet_old( 'bfnet_note' ) ); ?></textarea>
				</p>

				<?php
				// What the server said about a code the guest has already applied.
				$bfnet_applied = BFNET_Shortcodes::$applied;
				$bfnet_off     = ( $bfnet_applied && ! empty( $bfnet_applied['ok'] ) ) ? (int) $bfnet_applied['amount_cents'] : 0;
				$bfnet_payable = max( 0, $bfnet_price - $bfnet_off );
				?>

				<?php if ( BFNET_Offers::offered( (int) $event->id ) ) : ?>
					<div class="bfnet-promo" data-bfnet-code data-event="<?php echo (int) $event->id; ?>">
						<label for="bfnet-promo"><?php esc_html_e( 'Discount code', 'bitforgenet-guest-tickets' ); ?></label>
						<div class="bfnet-promo__row">
							<input type="text" id="bfnet-promo" name="bfnet_discount_code" autocomplete="off"
								autocapitalize="characters" spellcheck="false"
								placeholder="<?php esc_attr_e( 'If you have one', 'bitforgenet-guest-tickets' ); ?>"
								value="<?php echo esc_attr( $bfnet_applied ? $bfnet_applied['code'] : '' ); ?>">
							<!--
								A real submit button, not a script hook. The server prices the
								code and sends the page back with the answer on it, so a stale
								cached script cannot make a working code look broken.
							-->
							<button type="submit" name="bfnet_apply_code" value="1" class="bfnet-btn bfnet-btn--ghost" data-bfnet-code-apply>
								<?php esc_html_e( 'Apply', 'bitforgenet-guest-tickets' ); ?>
							</button>
						</div>
						<p class="bfnet-promo__msg<?php echo $bfnet_applied && $bfnet_applied['message'] ? ( ! empty( $bfnet_applied['ok'] ) ? ' is-good' : ' is-bad' ) : ''; ?>"
							data-bfnet-code-msg <?php echo ( $bfnet_applied && $bfnet_applied['message'] ) ? '' : 'hidden'; ?>>
							<?php echo esc_html( $bfnet_applied ? $bfnet_applied['message'] : '' ); ?>
						</p>
					</div>
				<?php endif; ?>

				<div class="bfnet-total" data-bfnet-total data-currency="<?php echo esc_attr( $event->currency ); ?>">
					<div class="bfnet-total__line bfnet-total__line--off" data-bfnet-off <?php echo $bfnet_off > 0 ? '' : 'hidden'; ?>>
						<span data-bfnet-off-label>
							<?php echo esc_html( $bfnet_off > 0 && ! empty( $bfnet_applied['label'] ) ? $bfnet_applied['label'] : __( 'Discount', 'bitforgenet-guest-tickets' ) ); ?>
						</span>
						<strong data-bfnet-off-value><?php echo esc_html( $bfnet_off > 0 ? '-' . BFNET_Util::money( $bfnet_off, $event->currency ) : '—' ); ?></strong>
					</div>
					<div class="bfnet-total__line">
						<span><?php esc_html_e( 'Total to pay', 'bitforgenet-guest-tickets' ); ?></span>
						<strong data-bfnet-payable><?php echo esc_html( BFNET_Util::money( $bfnet_payable, $event->currency ) ); ?></strong>
					</div>
				</div>

				<?php if ( $bfnet_age_on && 'declare' === $bfnet_age_mode ) : ?>
					<p class="bfnet-check">
						<label>
							<input type="checkbox" name="bfnet_age_confirm" value="1" required>
							<span>
								<?php
								/* translators: %d: minimum age. */
								echo esc_html( sprintf( __( 'I confirm every guest on this booking is %d years or over. Photo ID may be checked at the door.', 'bitforgenet-guest-tickets' ), $bfnet_min_age ) );
								?>
							</span>
						</label>
					</p>
				<?php endif; ?>

				<?php if ( (int) BFNET_Settings::get( 'require_terms', 1 ) ) : ?>
					<p class="bfnet-check">
						<label>
							<input type="checkbox" name="bfnet_terms" value="1" required>
							<span>
								<?php esc_html_e( 'I accept the terms and conditions of this event.', 'bitforgenet-guest-tickets' ); ?>
								<?php if ( $bfnet_legal ) : ?>
									<span class="bfnet-legal">
										<?php foreach ( $bfnet_legal as $bfnet_index => $bfnet_link ) : ?>
											<?php echo $bfnet_index ? ' · ' : ''; ?>
											<a href="<?php echo esc_url( $bfnet_link['url'] ); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html( $bfnet_link['label'] ); ?></a>
										<?php endforeach; ?>
									</span>
								<?php endif; ?>
							</span>
						</label>
					</p>
				<?php endif; ?>

				<p class="bfnet-check">
					<label>
						<input type="checkbox" name="bfnet_marketing" value="1">
						<span><?php esc_html_e( 'Keep me informed about upcoming events.', 'bitforgenet-guest-tickets' ); ?></span>
					</label>
				</p>

				<?php if ( $event->terms ) : ?>
					<div class="bfnet-note bfnet-note--terms"><?php echo wp_kses_post( wpautop( $event->terms ) ); ?></div>
				<?php endif; ?>

				<?php
				$bfnet_instructions = $event->payment_instructions ? $event->payment_instructions : (string) BFNET_Settings::get( 'payment_instructions', '' );
				if ( $bfnet_instructions ) :
					?>
					<div class="bfnet-note"><?php echo wp_kses_post( wpautop( $bfnet_instructions ) ); ?></div>
				<?php endif; ?>

				<button type="submit" class="bfnet-submit"><?php esc_html_e( 'Reserve my place', 'bitforgenet-guest-tickets' ); ?></button>

				<p class="bfnet-fineprint"><?php esc_html_e( 'Your reservation is recorded immediately. Tickets are issued and emailed as soon as our team confirms your payment.', 'bitforgenet-guest-tickets' ); ?></p>
			</fieldset>
		</form>

	<?php endif; ?>
</div>
