<?php
/**
 * Payment Summary – event details and order summary (cost or quantity).
 * For customization: copy to your theme. Line-item data comes from {@see \WPEventGenius\Common\Services\PaymentSummaryView::build()}.
 *
 * @var \WPEventGenius\Common\Event\EventPost $event_post
 * @var array $initial_type_quantities Optional. Type ID => quantity (e.g. Manage Registration).
 * @var float|null $initial_subtotal    Optional. Pre-filled subtotal.
 * @var float|null $initial_fee         Optional. Pre-filled fee.
 * @var float|null $initial_total       Optional. Pre-filled total.
 */

use WPEventGenius\Common\Services\PaymentSummaryView;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$view = PaymentSummaryView::build(
	$event_post,
	array(
		'initial_type_quantities' => isset( $initial_type_quantities ) && is_array( $initial_type_quantities ) ? $initial_type_quantities : array(),
		'initial_subtotal'        => isset( $initial_subtotal ) ? (float) $initial_subtotal : null,
		'initial_fee'             => isset( $initial_fee ) ? (float) $initial_fee : null,
		'initial_total'           => isset( $initial_total ) ? (float) $initial_total : null,
	)
);
$summary = $view['summary'];
?>

<div class="evge-modal-event-details">
	<div class="evge-modal-title">
		<strong><?php echo esc_html( apply_filters( 'evge_payment_summary_event_title', $event_post->get_the_title(), $event_post ) ); ?></strong>
	</div>
	<div class="evge-modal-date-venue">
		<?php
		$meta_html = apply_filters( 'evge_payment_summary_event_meta', '', $event_post );
		if ( $meta_html !== '' ) {
			echo $meta_html;
		} else {
			EVGE()->template_manager()->get_template( 'events/common/event-meta.php', array(
				'event_post'    => $event_post,
				'show_map'      => false,
				'venue_unlink'  => true,
			) );
		}
		?>
	</div>
</div>
<h3><?php esc_html_e( 'Summary', 'event-genius' ); ?></h3>

<?php if ( $summary['has_cost'] ) : ?>
	<div class="evge-modal-summary evge-modal-cost-details"<?php echo $view['data_attributes_html']; ?> role="region" aria-label="<?php esc_attr_e( 'Order Summary', 'event-genius' ); ?>">
		<?php
		EVGE()->template_manager()->get_template( 'common/payment-table.php', array(
			'event_post'     => $summary['event_post'],
			'payment_table'  => $view['payment_table'],
		) );
		?>
	</div>
<?php else : ?>
	<div class="evge-modal-summary evge-modal-quantity-summary"<?php echo $view['data_attributes_html']; ?> data-has-type-lines="<?php echo $view['quantity_has_type_lines'] ? '1' : '0'; ?>" role="region" aria-label="<?php esc_attr_e( 'Order Summary', 'event-genius' ); ?>">
		<div class="evge-modal-order-detail">
			<?php foreach ( $view['quantity_rows'] as $row ) : ?>
				<div class="<?php echo esc_attr( $row['css_class'] ); ?>" id="<?php echo esc_attr( $row['item_id'] ); ?>"<?php echo $row['data_type_id'] !== '' ? ' data-type-id="' . esc_attr( $row['data_type_id'] ) . '"' : ''; ?>>
					<div class="evge-line-item-quantity"><?php echo esc_html( (string) (int) $row['quantity'] ); ?></div>x<div class="evge-line-item-name"><?php echo esc_html( $row['label'] ); ?></div>
				</div>
			<?php endforeach; ?>
		</div>
	</div>
<?php endif; ?>
