<?php
/**
 * Admin view: the Booking form panel of the settings screen.
 *
 * Included by admin/views/settings.php inside that tab's own form, so the
 * closures and the $s array defined there are in scope here.
 *
 * @package BitForgeNet_Guest_Tickets
 */

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
?>
	<div class="bfnet-panel">
		<div class="bfnet-panel__head"><h2><?php esc_html_e( 'Booking form', 'bitforgenet-guest-tickets' ); ?></h2></div>
		<div class="bfnet-panel__body">
			<div class="bfnet-field">
				<label for="s-page"><?php esc_html_e( 'Booking page', 'bitforgenet-guest-tickets' ); ?></label>
				<select id="s-page" name="bfnet_settings[registration_page_id]">
					<option value="0"><?php esc_html_e( '— not set —', 'bitforgenet-guest-tickets' ); ?></option>
					<?php foreach ( $pages as $page ) : ?>
						<option value="<?php echo (int) $page->ID; ?>" <?php selected( (int) $s['registration_page_id'], (int) $page->ID ); ?>><?php echo esc_html( $page->post_title ); ?></option>
					<?php endforeach; ?>
				</select>
				<p class="description"><?php esc_html_e( 'The page containing [bitforgenet_registration]. Used to build shareable event links.', 'bitforgenet-guest-tickets' ); ?></p>
			</div>

			<div class="bfnet-row">
				<div class="bfnet-field">
					<label for="s-max"><?php esc_html_e( 'Default max places per booking', 'bitforgenet-guest-tickets' ); ?></label>
					<input type="number" id="s-max" name="bfnet_settings[default_max_per_order]" min="1" max="50" value="<?php echo (int) $s['default_max_per_order']; ?>">
				</div>
				<div class="bfnet-field">
					<label for="s-terms-page"><?php esc_html_e( 'Terms and conditions page', 'bitforgenet-guest-tickets' ); ?></label>
					<select id="s-terms-page" name="bfnet_settings[terms_page_id]">
						<option value="0"><?php esc_html_e( '— none —', 'bitforgenet-guest-tickets' ); ?></option>
						<?php foreach ( $pages as $page ) : ?>
							<option value="<?php echo (int) $page->ID; ?>" <?php selected( (int) $s['terms_page_id'], (int) $page->ID ); ?>><?php echo esc_html( $page->post_title ); ?></option>
						<?php endforeach; ?>
					</select>
				</div>
			</div>

			<div class="bfnet-row">
				<div class="bfnet-field">
					<label for="s-reg-page"><?php esc_html_e( 'Regulation of the sale page', 'bitforgenet-guest-tickets' ); ?></label>
					<select id="s-reg-page" name="bfnet_settings[regulation_page_id]">
						<option value="0"><?php esc_html_e( '— none —', 'bitforgenet-guest-tickets' ); ?></option>
						<?php foreach ( $pages as $page ) : ?>
							<option value="<?php echo (int) $page->ID; ?>" <?php selected( (int) $s['regulation_page_id'], (int) $page->ID ); ?>><?php echo esc_html( $page->post_title ); ?></option>
						<?php endforeach; ?>
					</select>
				</div>
				<div class="bfnet-field">
					<label for="s-priv-page"><?php esc_html_e( 'Privacy page', 'bitforgenet-guest-tickets' ); ?></label>
					<select id="s-priv-page" name="bfnet_settings[privacy_page_id]">
						<option value="0"><?php esc_html_e( '— none —', 'bitforgenet-guest-tickets' ); ?></option>
						<?php foreach ( $pages as $page ) : ?>
							<option value="<?php echo (int) $page->ID; ?>" <?php selected( (int) $s['privacy_page_id'], (int) $page->ID ); ?>><?php echo esc_html( $page->post_title ); ?></option>
						<?php endforeach; ?>
					</select>
				</div>
			</div>

			<p class="description" style="margin-top:-6px">
				<?php esc_html_e( 'These are linked next to the consent checkbox. An event can override them with its own pages.', 'bitforgenet-guest-tickets' ); ?>
			</p>

			<?php
			$bfnet_check( 'collect_guest_names', __( 'Collect a name for every guest', 'bitforgenet-guest-tickets' ), __( 'Each guest then receives a personal ticket with their own QR code.', 'bitforgenet-guest-tickets' ), $s );
			$bfnet_check( 'require_phone', __( 'Phone number required', 'bitforgenet-guest-tickets' ), '', $s );
			$bfnet_check( 'require_terms', __( 'Terms checkbox required', 'bitforgenet-guest-tickets' ), '', $s );
			?>

			<div class="bfnet-field">
				<label for="s-success"><?php esc_html_e( 'Confirmation message', 'bitforgenet-guest-tickets' ); ?></label>
				<textarea id="s-success" name="bfnet_settings[success_message]" rows="3"><?php echo esc_textarea( $s['success_message'] ); ?></textarea>
			</div>
		</div>
	</div>
