<?php
/**
 * Email Template: Booking Received (Double-Opt-In)
 *
 * §312i BGB - Eingangsbestätigung PFLICHT
 *
 * @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 $kurs_title     Course title.
 * @var string $kurs_date      Formatted course date.
 * @var string $kurs_start     Start time.
 * @var string $kurs_end       End time.
 * @var string                           $kurs_location  Location name.
 * @var array<int, array<string, mixed>> $tickets        Ticket details.
 * @var float                            $total_price    Total price.
 * @var string                           $confirm_url    Confirmation URL.
 * @var array<string, string>            $company        Company data.
 * @var string                           $privacy_url    Privacy policy URL.
 */

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: #2c3e50; color: #ffffff; padding: 24px; text-align: center;">
		<h1 style="margin: 0; font-size: 24px; font-weight: normal;">
			<?php esc_html_e( 'Buchungsanfrage eingegangen', 'kurs-booking' ); ?>
		</h1>
	</div>

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

		<p style="font-size: 16px; color: #333333; margin-bottom: 24px;">
			<?php
			printf(
				/* translators: %s: Customer name */
				esc_html__( 'Guten Tag %s,', 'kurs-booking' ),
				esc_html( $customer_name )
			);
			?>
		</p>

		<p style="font-size: 16px; color: #333333; margin-bottom: 24px;">
			<?php esc_html_e( 'vielen Dank für Ihre Buchungsanfrage!', 'kurs-booking' ); ?>
		</p>

		<!-- Booking Summary Box -->
		<div style="background-color: #f8f9fa; border: 1px solid #dee2e6; border-radius: 6px; padding: 20px; margin-bottom: 24px;">
			<h2 style="font-size: 14px; text-transform: uppercase; color: #6c757d; margin: 0 0 16px 0; letter-spacing: 1px;">
				<?php esc_html_e( 'Ihre Anfrage (noch nicht bestätigt)', 'kurs-booking' ); ?>
			</h2>

			<table style="width: 100%; border-collapse: collapse;">
				<tr>
					<td style="padding: 8px 0; color: #6c757d; width: 140px;"><?php esc_html_e( 'Buchungsnummer:', 'kurs-booking' ); ?></td>
					<td style="padding: 8px 0; color: #333333; font-weight: bold;"><?php echo esc_html( $buchung_nummer ); ?></td>
				</tr>
				<tr>
					<td style="padding: 8px 0; color: #6c757d;"><?php esc_html_e( 'Kurs:', 'kurs-booking' ); ?></td>
					<td style="padding: 8px 0; color: #333333;"><?php echo esc_html( $kurs_title ); ?></td>
				</tr>
				<tr>
					<td style="padding: 8px 0; color: #6c757d;"><?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 if ( ! empty( $kurs_end ) ) : ?>
								– <?php echo esc_html( $kurs_end ); ?>
							<?php endif; ?>
							<?php esc_html_e( 'Uhr', 'kurs-booking' ); ?>
						<?php endif; ?>
					</td>
				</tr>
				<?php if ( ! empty( $kurs_location ) ) : ?>
				<tr>
					<td style="padding: 8px 0; color: #6c757d;"><?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>

			<!-- Tickets -->
			<?php if ( ! empty( $tickets ) ) : ?>
			<div style="margin-top: 16px; padding-top: 16px; border-top: 1px solid #dee2e6;">
				<?php foreach ( $tickets as $ticket ) : ?>
				<div style="display: flex; justify-content: space-between; padding: 4px 0;">
					<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>
			<?php endif; ?>

			<!-- Total -->
			<div style="margin-top: 16px; padding-top: 16px; border-top: 2px solid #333333;">
				<div style="display: flex; justify-content: space-between;">
					<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: #333333;">
						<?php echo esc_html( $format_price( $total_price ) ); ?>
					</span>
				</div>
			</div>
		</div>

		<!-- Important Notice -->
		<div style="background-color: #fff3cd; border: 1px solid #ffc107; border-radius: 6px; padding: 20px; margin-bottom: 24px;">
			<h3 style="margin: 0 0 12px 0; color: #856404; font-size: 16px;">
				<?php esc_html_e( 'Wichtig: Bitte bestätigen Sie Ihre E-Mail-Adresse', 'kurs-booking' ); ?>
			</h3>
			<p style="margin: 0 0 16px 0; color: #856404;">
				<?php esc_html_e( 'Klicken Sie auf den folgenden Button, um Ihre Buchungsanfrage zu bestätigen:', 'kurs-booking' ); ?>
			</p>

			<!-- Confirmation Button -->
			<div style="text-align: center;">
				<a href="<?php echo esc_url( $confirm_url ); ?>"
				   style="display: inline-block; background-color: #28a745; color: #ffffff; padding: 14px 32px; text-decoration: none; border-radius: 6px; font-weight: bold; font-size: 16px;">
					<?php esc_html_e( 'E-Mail-Adresse bestätigen', 'kurs-booking' ); ?>
				</a>
			</div>

			<p style="margin: 16px 0 0 0; color: #856404; font-size: 14px;">
				<?php esc_html_e( 'Der Link ist 48 Stunden gültig. Ohne Bestätigung wird Ihre Buchungsanfrage automatisch gelöscht.', 'kurs-booking' ); ?>
			</p>
		</div>

		<!-- Fallback Link -->
		<p style="font-size: 12px; color: #6c757d; margin-bottom: 24px;">
			<?php esc_html_e( 'Falls der Button nicht funktioniert, kopieren Sie diesen Link in Ihren Browser:', 'kurs-booking' ); ?><br>
			<a href="<?php echo esc_url( $confirm_url ); ?>" style="color: #007bff; word-break: break-all;">
				<?php echo esc_url( $confirm_url ); ?>
			</a>
		</p>

	</div>

	<!-- Footer -->
	<div style="background-color: #f8f9fa; padding: 24px; border-top: 1px solid #e0e0e0;">
		<?php if ( ! empty( $company ) ) : ?>
		<div style="font-size: 12px; color: #6c757d; line-height: 1.6;">
			<strong><?php echo esc_html( $company['name'] ?? '' ); ?></strong><br>
			<?php echo esc_html( $company['address'] ?? '' ); ?><br>
			<?php echo esc_html( $company['zip'] ?? '' ); ?> <?php echo esc_html( $company['city'] ?? '' ); ?><br>

			<?php if ( ! empty( $company['phone'] ) ) : ?>
				<?php esc_html_e( 'Tel:', 'kurs-booking' ); ?> <?php echo esc_html( $company['phone'] ); ?><br>
			<?php endif; ?>

			<?php if ( ! empty( $company['email'] ) ) : ?>
				<?php esc_html_e( 'E-Mail:', 'kurs-booking' ); ?>
				<a href="mailto:<?php echo esc_attr( $company['email'] ); ?>" style="color: #007bff;">
					<?php echo esc_html( $company['email'] ); ?>
				</a><br>
			<?php endif; ?>

			<?php if ( ! empty( $company['website'] ) ) : ?>
				<a href="<?php echo esc_url( $company['website'] ); ?>" style="color: #007bff;">
					<?php echo esc_html( $company['website'] ); ?>
				</a><br>
			<?php endif; ?>

			<br>

			<?php if ( ! empty( $company['ceo'] ) ) : ?>
				<?php esc_html_e( 'Geschäftsführer:', 'kurs-booking' ); ?> <?php echo esc_html( $company['ceo'] ); ?><br>
			<?php endif; ?>

			<?php if ( ! empty( $company['tax_number'] ) ) : ?>
				<?php esc_html_e( 'Steuernummer:', 'kurs-booking' ); ?> <?php echo esc_html( $company['tax_number'] ); ?><br>
			<?php endif; ?>

			<?php if ( ! empty( $company['vat_id'] ) ) : ?>
				<?php esc_html_e( 'USt-IdNr.:', 'kurs-booking' ); ?> <?php echo esc_html( $company['vat_id'] ); ?><br>
			<?php endif; ?>
		</div>
		<?php endif; ?>

		<?php if ( ! empty( $privacy_url ) ) : ?>
		<div style="margin-top: 16px; font-size: 12px;">
			<a href="<?php echo esc_url( $privacy_url ); ?>" style="color: #007bff;">
				<?php esc_html_e( 'Datenschutzerklärung', 'kurs-booking' ); ?>
			</a>
		</div>
		<?php endif; ?>
	</div>

</div>
