<?php
/**
 * Admin view: the Pricing and capacity 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( 'Pricing and capacity', 'bitforgenet-guest-tickets' ); ?></h2></div>
	<div class="bfnet-panel__body">
		<div class="bfnet-row bfnet-row--3">
			<div class="bfnet-field">
				<label for="bfnet-price"><?php esc_html_e( 'Base price', 'bitforgenet-guest-tickets' ); ?></label>
				<input type="text" id="bfnet-price" name="price" inputmode="decimal" value="<?php echo esc_attr( $event ? number_format( $event->price_cents / 100, 2, '.', '' ) : '0.00' ); ?>">
			</div>
			<div class="bfnet-field">
				<label for="bfnet-currency"><?php esc_html_e( 'Currency', 'bitforgenet-guest-tickets' ); ?></label>
				<select id="bfnet-currency" name="currency">
					<?php foreach ( $currencies as $code => $meta ) : ?>
						<option value="<?php echo esc_attr( $code ); ?>" <?php selected( $event ? $event->currency : BFNET_Settings::get( 'currency', 'CAD' ), $code ); ?>><?php echo esc_html( $meta['label'] ); ?></option>
					<?php endforeach; ?>
				</select>
			</div>
			<div class="bfnet-field">
				<label for="bfnet-capacity"><?php esc_html_e( 'Capacity', 'bitforgenet-guest-tickets' ); ?></label>
				<input type="number" id="bfnet-capacity" name="capacity" class="bfnet-narrow" min="0" value="<?php echo (int) ( $event ? $event->capacity : 0 ); ?>">
				<p class="description"><?php esc_html_e( '0 = unlimited', 'bitforgenet-guest-tickets' ); ?></p>
			</div>
		</div>

		<?php
		/**
		 * Where a seating module puts its own fields on this tab.
		 *
		 * Whether a night seats its guests, how the room is numbered and how
		 * it is divided into zones are all questions only something that can
		 * place a booking has any business asking.
		 *
		 * @param object|null $event The event being edited.
		 */
		do_action( 'bfnet_event_tab_seating', $event );
		?>


		<?php
		/**
		 * Where a pricing module puts its own fields on this tab.
		 *
		 * Ticket categories used to be written out here, which meant the tab
		 * could not be rendered without them — and a build without them would
		 * have shown an empty repeater for rows that can never exist.
		 *
		 * @param object|null $event The event being edited.
		 */
		do_action( 'bfnet_event_tab_pricing', $event );
		?>


		<div class="bfnet-field" style="margin-top:22px">
			<label class="bfnet-label">
				<input type="checkbox" name="menu_enabled" value="1" <?php checked( $event && $event->menu_enabled ); ?>>
				<?php esc_html_e( 'This event serves food or drinks', 'bitforgenet-guest-tickets' ); ?>
			</label>
			<p class="description" style="margin-top:0">
				<?php esc_html_e( 'Off by default. Nothing about a menu appears anywhere until this is ticked — some nights are a dinner, most are not.', 'bitforgenet-guest-tickets' ); ?>
			</p>

			<div class="bfnet-row" style="margin-top:10px">
				<div class="bfnet-field">
					<label for="bfnet-menu-title"><?php esc_html_e( 'What to call it', 'bitforgenet-guest-tickets' ); ?></label>
					<input type="text" id="bfnet-menu-title" name="menu_title" maxlength="180"
						value="<?php echo esc_attr( $event ? $event->menu_title : '' ); ?>"
						placeholder="<?php esc_attr_e( 'Buffet dinner and dessert', 'bitforgenet-guest-tickets' ); ?>">
				</div>
			</div>
			<div class="bfnet-field">
				<label for="bfnet-menu-body"><?php esc_html_e( 'The menu', 'bitforgenet-guest-tickets' ); ?></label>
				<textarea id="bfnet-menu-body" name="menu_body" rows="6"
					placeholder="<?php esc_attr_e( 'Starters, mains, dessert, what is included and what is not…', 'bitforgenet-guest-tickets' ); ?>"><?php echo esc_textarea( $event ? $event->menu_body : '' ); ?></textarea>
				<p class="description"><?php esc_html_e( 'Shown on the booking page under the event details. Say plainly what the price does not cover — drinks, the cloakroom — because that is what gets asked at the door.', 'bitforgenet-guest-tickets' ); ?></p>
			</div>
		</div>

		<div class="bfnet-field">
			<label class="bfnet-label"><?php esc_html_e( 'Sponsor strip on the ticket', 'bitforgenet-guest-tickets' ); ?></label>
			<div class="bfnet-media">
				<div class="bfnet-media__preview" data-bfnet-preview
					<?php if ( $event && $event->sponsors_image ) : ?>
						style="background-image:url('<?php echo esc_url( wp_get_attachment_image_url( (int) $event->sponsors_image, 'medium' ) ); ?>')"
					<?php endif; ?>>
					<?php if ( ! ( $event && $event->sponsors_image ) ) : ?><?php esc_html_e( 'No logos', 'bitforgenet-guest-tickets' ); ?><?php endif; ?>
				</div>
				<div>
					<input type="hidden" name="sponsors_image" value="<?php echo (int) ( $event ? $event->sponsors_image : 0 ); ?>" data-bfnet-media-id>
					<p><button type="button" class="button" data-bfnet-media><?php esc_html_e( 'Choose an image', 'bitforgenet-guest-tickets' ); ?></button></p>
					<p class="description">
						<?php esc_html_e( 'Drops into the clear strip beneath the QR code — about 100 x 15 mm. A single wide image with every logo already arranged on it gives you full control of the spacing.', 'bitforgenet-guest-tickets' ); ?>
					</p>
				</div>
			</div>
		</div>
	</div>
</div>
