<?php
/**
 * Payment Table – line items and optional subtotal/fees/total.
 * For customization: copy to your theme. Data is prepared by {@see \WPEventGenius\Common\Services\PaymentSummaryView}.
 *
 * @var \WPEventGenius\Common\Event\EventPost $event_post
 * @var array|null $payment_table Optional. Pre-built from PaymentSummaryView::payment_table() or build().
 * @var \WPEventGenius\Common\Registration\Payment\Cart\LineItem[]|null $line_items Used when payment_table is not passed.
 * @var bool|null $show_subtotal_block
 * @var float|null $subtotal
 * @var float|null $fee
 * @var float|null $total
 */

use WPEventGenius\Common\Services\PaymentSummaryView;

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

if ( ! isset( $payment_table ) || ! is_array( $payment_table ) ) {
	$payment_table = PaymentSummaryView::payment_table_standalone(
		$event_post,
		isset( $line_items ) && is_array( $line_items ) ? $line_items : array(),
		! empty( $show_subtotal_block ),
		isset( $subtotal ) ? (float) $subtotal : 0.0,
		isset( $fee ) ? (float) $fee : 0.0,
		isset( $total ) ? (float) $total : 0.0
	);
}

$pt = $payment_table;
?>

<div class="evge-modal-order-detail">
	<?php foreach ( $pt['lines'] 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_attr'] !== '' ? ' data-type-id="' . esc_attr( $row['data_type_id_attr'] ) . '"' : ''; ?> data-unit-price="<?php echo esc_attr( (string) $row['unit_price'] ); ?>">
			<div class="evge-line-item-left">
				<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>
			<div class="evge-line-item-right">
				<div class="evge-line-item-total"><span class="evge-line-item-cost" data-amount="<?php echo esc_attr( $row['line_total'] ); ?>"><?php echo esc_html( $row['line_total_formatted'] ); ?></span></div>
			</div>
		</div>
	<?php endforeach; ?>

	<?php if ( ! empty( $pt['show_subtotal_block'] ) ) : ?>
		<hr class="evge-line-item-break" id="evge-subtotal-line-break">
		<div class="evge-modal-line-item" id="evge-line-item-subtotal">
			<div class="evge-line-item-left"><?php esc_html_e( 'Subtotal', 'event-genius' ); ?></div>
			<div class="evge-line-item-right">
				<div class="evge-line-item-total"><span class="evge-line-item-cost" data-amount="<?php echo esc_attr( $pt['subtotal'] ); ?>"><?php echo esc_html( $pt['subtotal_formatted'] ); ?></span></div>
			</div>
		</div>
		<div class="evge-modal-line-item" id="evge-line-item-fees">
			<div class="evge-line-item-left"><?php esc_html_e( 'Fees', 'event-genius' ); ?></div>
			<div class="evge-line-item-right">
				<div class="evge-line-item-total"><span class="evge-line-item-cost" data-amount="<?php echo esc_attr( $pt['fee'] ); ?>"><?php echo esc_html( $pt['fee_formatted'] ); ?></span></div>
			</div>
		</div>
		<hr class="evge-line-item-break" id="evge-subtotal-line-total">
		<div class="evge-modal-line-item evge-modal-line-large" id="evge-line-item-total">
			<div class="evge-line-item-left"><?php esc_html_e( 'Total', 'event-genius' ); ?></div>
			<div class="evge-line-item-right">
				<div class="evge-line-item-total"><span class="evge-line-item-cost" data-amount="<?php echo esc_attr( $pt['total'] ); ?>"><?php echo esc_html( $pt['total_formatted'] ); ?></span></div>
			</div>
		</div>
	<?php endif; ?>
</div>
