<?php
/**
 * Admin view: the Rules and terms tab of the event editor.
 *
 * Included by admin/views/event-edit.php inside that tab's own form, so the
 * $event row and the $bfnet_dt helper 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( 'Terms and regulation', 'bitforgenet-guest-tickets' ); ?></h2></div>
	<div class="bfnet-panel__body">
		<p style="margin-top:0" class="description"><?php esc_html_e( 'Choose the pages you have written for this event. They are linked from the booking form next to the consent checkbox. Leave them on the site-wide setting to use the global pages.', 'bitforgenet-guest-tickets' ); ?></p>
		<?php $bfnet_pages = get_pages( array( 'number' => 300, 'sort_column' => 'post_title' ) ); ?>
		<div class="bfnet-row">
			<div class="bfnet-field">
				<label for="bfnet-terms-page"><?php esc_html_e( 'Event terms page', 'bitforgenet-guest-tickets' ); ?></label>
				<select id="bfnet-terms-page" name="terms_page_id">
					<option value="0"><?php esc_html_e( '— use the site-wide page —', 'bitforgenet-guest-tickets' ); ?></option>
					<?php foreach ( $bfnet_pages as $bfnet_page ) : ?>
						<option value="<?php echo (int) $bfnet_page->ID; ?>" <?php selected( $event ? (int) $event->terms_page_id : 0, (int) $bfnet_page->ID ); ?>><?php echo esc_html( $bfnet_page->post_title ); ?></option>
					<?php endforeach; ?>
				</select>
			</div>
			<div class="bfnet-field">
				<label for="bfnet-reg-page"><?php esc_html_e( 'Regulation of the sale page', 'bitforgenet-guest-tickets' ); ?></label>
				<select id="bfnet-reg-page" name="regulation_page_id">
					<option value="0"><?php esc_html_e( '— use the site-wide page —', 'bitforgenet-guest-tickets' ); ?></option>
					<?php foreach ( $bfnet_pages as $bfnet_page ) : ?>
						<option value="<?php echo (int) $bfnet_page->ID; ?>" <?php selected( $event ? (int) $event->regulation_page_id : 0, (int) $bfnet_page->ID ); ?>><?php echo esc_html( $bfnet_page->post_title ); ?></option>
					<?php endforeach; ?>
				</select>
			</div>
		</div>
	</div>
</div>
<div class="bfnet-panel">
	<div class="bfnet-panel__head"><h2><?php esc_html_e( 'Registration window', 'bitforgenet-guest-tickets' ); ?></h2></div>
	<div class="bfnet-panel__body">
		<p class="description" style="margin-top:0"><?php esc_html_e( 'Leave both empty and the form follows the event status alone.', 'bitforgenet-guest-tickets' ); ?></p>
		<div class="bfnet-row">
			<div class="bfnet-field">
				<label for="bfnet-reg-open"><?php esc_html_e( 'Registration opens', 'bitforgenet-guest-tickets' ); ?></label>
				<input type="datetime-local" id="bfnet-reg-open" name="registration_opens_at" value="<?php echo esc_attr( $bfnet_dt( $event ? $event->registration_opens_at : '' ) ); ?>">
			</div>
			<div class="bfnet-field">
				<label for="bfnet-reg-close"><?php esc_html_e( 'Registration closes', 'bitforgenet-guest-tickets' ); ?></label>
				<input type="datetime-local" id="bfnet-reg-close" name="registration_closes_at" value="<?php echo esc_attr( $bfnet_dt( $event ? $event->registration_closes_at : '' ) ); ?>">
			</div>
		</div>
	</div>
</div>
