<?php
/**
 * Admin view: the Ticket and link 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( 'Tickets', 'bitforgenet-guest-tickets' ); ?></h2></div>
	<div class="bfnet-panel__body">
		<div class="bfnet-field">
			<label for="bfnet-template"><?php esc_html_e( 'Ticket design', 'bitforgenet-guest-tickets' ); ?></label>
			<select id="bfnet-template" name="template_id">
				<option value="0"><?php esc_html_e( 'Use the default design', 'bitforgenet-guest-tickets' ); ?></option>
				<?php foreach ( $templates as $template ) : ?>
					<option value="<?php echo (int) $template->id; ?>" <?php selected( $event ? (int) $event->template_id : 0, (int) $template->id ); ?>><?php echo esc_html( $template->name ); ?></option>
				<?php endforeach; ?>
			</select>
			<p class="description"><a href="<?php echo esc_url( BFNET_Util::admin_url( 'bitforgenet-guest-tickets-templates' ) ); ?>"><?php esc_html_e( 'Create a colour variation', 'bitforgenet-guest-tickets' ); ?></a></p>
		</div>

		<div class="bfnet-field">
			<label for="bfnet-prefix"><?php esc_html_e( 'Ticket serial prefix', 'bitforgenet-guest-tickets' ); ?></label>
			<input type="text" id="bfnet-prefix" name="ticket_prefix" maxlength="12" value="<?php echo esc_attr( $event ? $event->ticket_prefix : '' ); ?>" placeholder="<?php esc_attr_e( 'LN01', 'bitforgenet-guest-tickets' ); ?>">
			<p class="description"><?php esc_html_e( 'Produces serials such as LN01-000042.', 'bitforgenet-guest-tickets' ); ?></p>
		</div>

		<div class="bfnet-field">
			<label for="bfnet-max"><?php esc_html_e( 'Max places per booking', 'bitforgenet-guest-tickets' ); ?></label>
			<input type="number" id="bfnet-max" name="max_per_order" class="bfnet-narrow" min="1" max="50" value="<?php echo (int) ( $event ? $event->max_per_order : (int) BFNET_Settings::get( 'default_max_per_order', 10 ) ); ?>">
		</div>

		<div class="bfnet-field">
			<label>
				<input type="checkbox" name="collect_guest_names" value="1" <?php checked( $event ? (int) $event->collect_guest_names : 1, 1 ); ?>>
				<?php esc_html_e( 'Ask for every guest name', 'bitforgenet-guest-tickets' ); ?>
			</label>
			<p class="description"><?php esc_html_e( 'Recommended: each guest then gets a personal, non-transferable ticket.', 'bitforgenet-guest-tickets' ); ?></p>
		</div>
	</div>
</div>

<?php if ( ! $is_new ) : ?>
	<div class="bfnet-panel">
		<div class="bfnet-panel__head"><h2><?php esc_html_e( 'Direct link', 'bitforgenet-guest-tickets' ); ?></h2></div>
		<div class="bfnet-panel__body">
			<code class="bfnet-code"><?php echo esc_html( BFNET_Util::event_url( $event ) ); ?></code>
			<p class="description" style="margin-bottom:0"><?php esc_html_e( 'Share this link to send people straight to this event.', 'bitforgenet-guest-tickets' ); ?></p>
		</div>
	</div>
<?php endif; ?>
			</div>
