<?php
/**
 * Email Template: Video Access
 *
 * Sent after purchase of a Video-Kurs (digital product).
 *
 * @package KursBooking
 * @since   1.3.0
 *
 * @var string $buchung_nummer  Booking number.
 * @var string $buchung_date    Booking date.
 * @var string $customer_name   Customer name.
 * @var string $customer_email  Customer email.
 * @var string                           $kurs_title        Course title.
 * @var array<int, array<string, mixed>> $tickets           Ticket details.
 * @var float                            $total_price       Total price.
 * @var string                           $video_url         Video access URL.
 * @var int                              $video_access_days Access duration (0 = unlimited).
 * @var array<string, string>            $company           Company data.
 */

declare(strict_types=1);

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

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

// Get access duration info.
$access_info = '';
if ( isset( $video_access_days ) && $video_access_days > 0 ) {
	$access_info = sprintf(
		/* translators: %d: number of days */
		__( '%d Tage ab heute', 'kurs-booking' ),
		$video_access_days
	);
} else {
	$access_info = __( 'Unbegrenzter Zugang', 'kurs-booking' );
}
?>

<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: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #ffffff; padding: 32px; text-align: center;">
		<div style="font-size: 48px; margin-bottom: 8px;">&#9658;</div>
		<h1 style="margin: 0; font-size: 24px; font-weight: normal;">
			<?php esc_html_e( 'Ihr Video-Kurs ist bereit!', '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__( 'Hallo %s,', 'kurs-booking' ),
				esc_html( $customer_name ?? '' )
			);
			?>
		</p>

		<p style="font-size: 16px; color: #333333; margin-bottom: 24px;">
			<?php esc_html_e( 'vielen Dank fuer Ihren Kauf! Ihr Video-Kurs steht ab sofort fuer Sie bereit.', 'kurs-booking' ); ?>
		</p>

		<!-- Course Info Box -->
		<div style="background-color: #f8f9fa; border-radius: 8px; padding: 20px; margin-bottom: 24px;">
			<h2 style="margin: 0 0 16px 0; color: #333333; font-size: 18px; border-bottom: 2px solid #667eea; padding-bottom: 8px;">
				<?php echo esc_html( $kurs_title ?? '' ); ?>
			</h2>

			<table style="width: 100%; border-collapse: collapse;">
				<tr>
					<td style="padding: 8px 0; color: #666666; vertical-align: top; width: 40%;">
						<?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: #666666; vertical-align: top;">
						<?php esc_html_e( 'Zugang gueltig:', 'kurs-booking' ); ?>
					</td>
					<td style="padding: 8px 0; color: #333333;">
						<?php echo esc_html( $access_info ); ?>
					</td>
				</tr>
				<tr>
					<td style="padding: 8px 0; color: #666666; vertical-align: top;">
						<?php esc_html_e( 'Gesamtpreis:', 'kurs-booking' ); ?>
					</td>
					<td style="padding: 8px 0; color: #333333; font-weight: bold;">
						<?php echo esc_html( $format_price( $total_price ?? 0 ) ); ?>
					</td>
				</tr>
			</table>
		</div>

		<!-- CTA Button -->
		<div style="text-align: center; margin: 32px 0;">
			<a href="<?php echo esc_url( $video_url ?? '#' ); ?>"
			   style="display: inline-block; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #ffffff; text-decoration: none; padding: 16px 40px; border-radius: 30px; font-size: 18px; font-weight: bold; box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);">
				<?php esc_html_e( 'Jetzt Videos ansehen', 'kurs-booking' ); ?>
			</a>
		</div>

		<p style="text-align: center; font-size: 14px; color: #666666; margin-bottom: 24px;">
			<?php esc_html_e( 'Funktioniert der Button nicht? Kopieren Sie diesen Link:', 'kurs-booking' ); ?><br>
			<a href="<?php echo esc_url( $video_url ?? '#' ); ?>" style="color: #667eea; word-break: break-all;">
				<?php echo esc_html( $video_url ?? '' ); ?>
			</a>
		</p>

		<!-- Info Box -->
		<div style="background-color: #e8f4fd; border-left: 4px solid #2196f3; padding: 16px; margin-bottom: 24px;">
			<p style="margin: 0; color: #333333; font-size: 14px;">
				<strong><?php esc_html_e( 'Hinweis:', 'kurs-booking' ); ?></strong>
				<?php esc_html_e( 'Dieser Link ist persoenlich und sollte nicht weitergegeben werden. Der Zugang ist an Ihre Buchung gebunden.', 'kurs-booking' ); ?>
			</p>
		</div>

		<!-- Digital Product Notice -->
		<div style="background-color: #fff8e1; border-left: 4px solid #ff9800; padding: 16px; margin-bottom: 24px;">
			<p style="margin: 0; color: #333333; font-size: 14px;">
				<strong><?php esc_html_e( 'Digitales Produkt:', 'kurs-booking' ); ?></strong>
				<?php esc_html_e( 'Bei digitalen Produkten erlischt das Widerrufsrecht mit Beginn der Ausfuehrung (Freischaltung des Zugangs).', 'kurs-booking' ); ?>
			</p>
		</div>

		<p style="font-size: 16px; color: #333333; margin-bottom: 8px;">
			<?php esc_html_e( 'Viel Spass beim Lernen!', 'kurs-booking' ); ?>
		</p>

		<p style="font-size: 16px; color: #333333; margin-bottom: 0;">
			<?php esc_html_e( 'Herzliche Gruesse', 'kurs-booking' ); ?><br>
			<?php echo esc_html( $company['name'] ?? '' ); ?>
		</p>
	</div>

	<!-- Footer -->
	<div style="background-color: #f8f9fa; padding: 24px; text-align: center; border-top: 1px solid #e0e0e0;">
		<p style="margin: 0 0 8px 0; color: #666666; font-size: 14px;">
			<?php echo esc_html( $company['name'] ?? '' ); ?>
		</p>
		<?php if ( ! empty( $company['address'] ) ) : ?>
			<p style="margin: 0 0 8px 0; color: #999999; font-size: 12px;">
				<?php echo esc_html( $company['address'] ); ?>
			</p>
		<?php endif; ?>
		<?php if ( ! empty( $company['email'] ) ) : ?>
			<p style="margin: 0; color: #999999; font-size: 12px;">
				<a href="mailto:<?php echo esc_attr( $company['email'] ); ?>" style="color: #667eea; text-decoration: none;">
					<?php echo esc_html( $company['email'] ); ?>
				</a>
			</p>
		<?php endif; ?>
	</div>

</div>
