<?php
/**
 * Registration Types: type names and quantities only (Submissions tab).
 *
 * @var array $breakdown From RegistrationRecord::get_registration_type_breakdown().
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
$lines = isset( $breakdown['lines'] ) && is_array( $breakdown['lines'] ) ? $breakdown['lines'] : array();
$rows  = array();
foreach ( $lines as $line ) {
	$qty = isset( $line['quantity'] ) ? (int) $line['quantity'] : 0;
	if ( $qty <= 0 ) {
		continue;
	}
	$name = isset( $line['name'] ) ? (string) $line['name'] : '';
	if ( $name === '' || $name === '—' ) {
		$name = __( 'General', 'event-genius' );
	}
	$rows[] = array(
		'name'               => $name,
		'qty'                => $qty,
		'registrant_label'   => isset( $line['registrant_label'] ) ? (string) $line['registrant_label'] : '',
	);
}
$show_registrant_column = false;
foreach ( $rows as $r ) {
	if ( $r['registrant_label'] !== '' ) {
		$show_registrant_column = true;
		break;
	}
}
?>
<div class="evge-dashboard-item evge-registration-types-quantity-summary">
	<div class="evge-dashboard-item-header">
		<h3><?php esc_html_e( 'Registration Types', 'event-genius' ); ?></h3>
	</div>
	<div class="evge-dashboard-item-content">
		<?php if ( empty( $rows ) ) : ?>
			<p class="evge-no-types"><?php esc_html_e( 'No type information available.', 'event-genius' ); ?></p>
		<?php else : ?>
			<table class="evge-registration-types-table widefat striped evge-registration-types-qty-only">
				<thead>
					<tr>
						<?php if ( $show_registrant_column ) : ?>
						<th><?php esc_html_e( 'Registrant', 'event-genius' ); ?></th>
						<?php endif; ?>
						<th><?php esc_html_e( 'Type', 'event-genius' ); ?></th>
						<th><?php esc_html_e( 'Quantity', 'event-genius' ); ?></th>
					</tr>
				</thead>
				<tbody>
					<?php foreach ( $rows as $row ) : ?>
					<tr>
						<?php if ( $show_registrant_column ) : ?>
						<td><?php echo esc_html( $row['registrant_label'] !== '' ? $row['registrant_label'] : '—' ); ?></td>
						<?php endif; ?>
						<td><?php echo esc_html( $row['name'] ); ?></td>
						<td><?php echo esc_html( (string) $row['qty'] ); ?></td>
					</tr>
					<?php endforeach; ?>
				</tbody>
			</table>
		<?php endif; ?>
	</div>
</div>
