<?php
/**
 * Email Template: Admin Notification
 *
 * Sent to admin when a booking is confirmed.
 *
 * @package KursBooking
 * @since   1.0.0
 *
 * @var string $buchung_nummer  Booking number.
 * @var string $customer_name   Customer name.
 * @var string $customer_email  Customer email.
 * @var string $customer_phone  Customer phone.
 * @var string $kurs_title      Course title.
 * @var string $kurs_date       Formatted course date.
 * @var string $kurs_start      Start time.
 * @var string                           $kurs_location   Location name.
 * @var array<int, array<string, mixed>> $tickets         Ticket details.
 * @var float                            $total_price     Total price.
 * @var bool   $deposit_enabled Deposit enabled.
 * @var float  $deposit_amount  Deposit amount.
 * @var string $edit_url        Admin edit URL for booking.
 * @var string $kurs_edit_url   Admin edit URL for kurs.
 */

declare(strict_types=1);

// Prevent direct access.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// Format function.
$format_price = function ( float $amount ): string {
	return number_format( $amount, 2, ',', '.' ) . ' €';
};
?>

<div style="font-family: Arial, Helvetica, sans-serif; max-width: 600px; margin: 0 auto; background-color: #ffffff; border: 1px solid #e0e0e0; border-radius: 8px; overflow: hidden;">

	<!-- Header -->
	<div style="background-color: #007bff; color: #ffffff; padding: 24px; text-align: center;">
		<h1 style="margin: 0; font-size: 24px; font-weight: normal;">
			<?php esc_html_e( 'Neue Buchung eingegangen', 'kurs-booking' ); ?>
		</h1>
	</div>

	<!-- Content -->
	<div style="padding: 32px;">

		<!-- Status Badge -->
		<div style="text-align: center; margin-bottom: 24px;">
			<span style="display: inline-block; background-color: #28a745; color: #ffffff; padding: 8px 16px; border-radius: 20px; font-size: 14px; font-weight: bold;">
				<?php esc_html_e( 'Status: Bestätigt', 'kurs-booking' ); ?>
			</span>
		</div>

		<!-- Booking Summary -->
		<div style="background-color: #f8f9fa; border: 1px solid #dee2e6; border-radius: 6px; padding: 20px; margin-bottom: 24px;">
			<table style="width: 100%; border-collapse: collapse;">
				<tr>
					<td style="padding: 8px 0; color: #666666; width: 160px;"><?php esc_html_e( 'Buchungsnummer:', 'kurs-booking' ); ?></td>
					<td style="padding: 8px 0; color: #333333; font-weight: bold; font-size: 18px;"><?php echo esc_html( $buchung_nummer ); ?></td>
				</tr>
			</table>
		</div>

		<!-- Course Details -->
		<div style="background-color: #e3f2fd; border: 1px solid #2196f3; border-radius: 6px; padding: 20px; margin-bottom: 24px;">
			<h3 style="font-size: 14px; text-transform: uppercase; color: #1565c0; margin: 0 0 16px 0; letter-spacing: 1px;">
				<?php esc_html_e( 'Kurs', 'kurs-booking' ); ?>
			</h3>

			<table style="width: 100%; border-collapse: collapse;">
				<tr>
					<td style="padding: 8px 0; color: #666666; width: 140px;"><?php esc_html_e( 'Kurs:', 'kurs-booking' ); ?></td>
					<td style="padding: 8px 0; color: #333333; font-weight: bold;"><?php echo esc_html( $kurs_title ); ?></td>
				</tr>
				<tr>
					<td style="padding: 8px 0; color: #666666;"><?php esc_html_e( 'Datum:', 'kurs-booking' ); ?></td>
					<td style="padding: 8px 0; color: #333333;">
						<?php echo esc_html( $kurs_date ); ?>
						<?php if ( ! empty( $kurs_start ) ) : ?>
							, <?php echo esc_html( $kurs_start ); ?> <?php esc_html_e( 'Uhr', 'kurs-booking' ); ?>
						<?php endif; ?>
					</td>
				</tr>
				<?php if ( ! empty( $kurs_location ) ) : ?>
				<tr>
					<td style="padding: 8px 0; color: #666666;"><?php esc_html_e( 'Ort:', 'kurs-booking' ); ?></td>
					<td style="padding: 8px 0; color: #333333;"><?php echo esc_html( $kurs_location ); ?></td>
				</tr>
				<?php endif; ?>
			</table>
		</div>

		<!-- Customer Details -->
		<div style="background-color: #f8f9fa; border: 1px solid #dee2e6; border-radius: 6px; padding: 20px; margin-bottom: 24px;">
			<h3 style="font-size: 14px; text-transform: uppercase; color: #6c757d; margin: 0 0 16px 0; letter-spacing: 1px;">
				<?php esc_html_e( 'Kunde', 'kurs-booking' ); ?>
			</h3>

			<table style="width: 100%; border-collapse: collapse;">
				<tr>
					<td style="padding: 8px 0; color: #666666; width: 140px;"><?php esc_html_e( 'Name:', 'kurs-booking' ); ?></td>
					<td style="padding: 8px 0; color: #333333; font-weight: bold;"><?php echo esc_html( $customer_name ); ?></td>
				</tr>
				<tr>
					<td style="padding: 8px 0; color: #666666;"><?php esc_html_e( 'E-Mail:', 'kurs-booking' ); ?></td>
					<td style="padding: 8px 0;">
						<a href="mailto:<?php echo esc_attr( $customer_email ); ?>" style="color: #007bff;">
							<?php echo esc_html( $customer_email ); ?>
						</a>
					</td>
				</tr>
				<?php if ( ! empty( $customer_phone ) ) : ?>
				<tr>
					<td style="padding: 8px 0; color: #666666;"><?php esc_html_e( 'Telefon:', 'kurs-booking' ); ?></td>
					<td style="padding: 8px 0;">
						<a href="tel:<?php echo esc_attr( $customer_phone ); ?>" style="color: #007bff;">
							<?php echo esc_html( $customer_phone ); ?>
						</a>
					</td>
				</tr>
				<?php endif; ?>
			</table>
		</div>

		<!-- Booking Details -->
		<div style="background-color: #f8f9fa; border: 1px solid #dee2e6; border-radius: 6px; padding: 20px; margin-bottom: 24px;">
			<h3 style="font-size: 14px; text-transform: uppercase; color: #6c757d; margin: 0 0 16px 0; letter-spacing: 1px;">
				<?php esc_html_e( 'Buchung', 'kurs-booking' ); ?>
			</h3>

			<?php foreach ( $tickets as $ticket ) : ?>
			<div style="display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #dee2e6;">
				<span style="color: #333333;">
					<?php echo esc_html( $ticket['quantity'] ); ?>× <?php echo esc_html( $ticket['name'] ); ?>
				</span>
				<span style="color: #333333; font-weight: bold;">
					<?php echo esc_html( $format_price( $ticket['subtotal'] ) ); ?>
				</span>
			</div>
			<?php endforeach; ?>

			<div style="display: flex; justify-content: space-between; padding: 16px 0 8px 0; border-top: 2px solid #333333; margin-top: 8px;">
				<span style="font-size: 18px; font-weight: bold; color: #333333;">
					<?php esc_html_e( 'Gesamtpreis:', 'kurs-booking' ); ?>
				</span>
				<span style="font-size: 18px; font-weight: bold; color: #28a745;">
					<?php echo esc_html( $format_price( $total_price ) ); ?>
				</span>
			</div>

			<?php if ( $deposit_enabled && $deposit_amount > 0 ) : ?>
			<div style="display: flex; justify-content: space-between; padding: 8px 0; color: #666666;">
				<span><?php esc_html_e( 'Anzahlung:', 'kurs-booking' ); ?></span>
				<span><?php echo esc_html( $format_price( $deposit_amount ) ); ?></span>
			</div>
			<?php endif; ?>
		</div>

		<!-- Action Buttons -->
		<div style="text-align: center; margin-bottom: 24px;">
			<a href="<?php echo esc_url( $edit_url ); ?>"
			   style="display: inline-block; background-color: #007bff; color: #ffffff; padding: 12px 24px; text-decoration: none; border-radius: 6px; font-weight: bold; margin: 4px;">
				<?php esc_html_e( 'Buchung bearbeiten', 'kurs-booking' ); ?>
			</a>
			<a href="<?php echo esc_url( $kurs_edit_url ); ?>"
			   style="display: inline-block; background-color: #6c757d; color: #ffffff; padding: 12px 24px; text-decoration: none; border-radius: 6px; font-weight: bold; margin: 4px;">
				<?php esc_html_e( 'Kurs anzeigen', 'kurs-booking' ); ?>
			</a>
		</div>

	</div>

	<!-- Footer -->
	<div style="background-color: #f8f9fa; padding: 16px 24px; border-top: 1px solid #e0e0e0; text-align: center;">
		<p style="margin: 0; font-size: 12px; color: #6c757d;">
			<?php esc_html_e( 'Diese E-Mail wurde automatisch vom Kurs-Booking System gesendet.', 'kurs-booking' ); ?>
		</p>
	</div>

</div>
