<?php
/**
 * Booking Confirmation Page Template
 *
 * Displays the result of a booking confirmation (success, error, or already confirmed).
 *
 * @package KursBooking
 * @since   1.5.0
 *
 * Available variables:
 * @var string $status    Status: 'success', 'error', 'already_confirmed', 'expired', 'invalid'
 * @var string $message   Human-readable message
 * @var int    $buchung_id Booking ID (if found)
 * @var int    $kurs_id   Course ID (if found)
 * @var string $kurs_title Course title (if found)
 * @var string $kurs_date Course date (if found)
 */

defined( 'ABSPATH' ) || exit;

get_header();

// Get variables from query vars (set by Kurs_Booking_Frontend::confirmation_template).
$status     = get_query_var( 'status', 'error' );
$message    = get_query_var( 'message', __( 'Ein unbekannter Fehler ist aufgetreten.', 'kurs-booking' ) );
$buchung_id = (int) get_query_var( 'buchung_id', 0 );
$kurs_id    = (int) get_query_var( 'kurs_id', 0 );
$kurs_title = get_query_var( 'kurs_title', '' );
$kurs_date  = get_query_var( 'kurs_date', '' );

// Status-specific settings.
$status_config = array(
	'success'           => array(
		'icon'       => 'check-circle-fill',
		'icon_color' => '#22c55e',
		'bg_color'   => '#f0fdf4',
		'title'      => __( 'Buchung bestätigt!', 'kurs-booking' ),
	),
	'already_confirmed' => array(
		'icon'       => 'info-circle-fill',
		'icon_color' => '#3b82f6',
		'bg_color'   => '#eff6ff',
		'title'      => __( 'Bereits bestätigt', 'kurs-booking' ),
	),
	'expired'           => array(
		'icon'       => 'clock-history',
		'icon_color' => '#f59e0b',
		'bg_color'   => '#fffbeb',
		'title'      => __( 'Link abgelaufen', 'kurs-booking' ),
	),
	'invalid'           => array(
		'icon'       => 'x-circle-fill',
		'icon_color' => '#ef4444',
		'bg_color'   => '#fef2f2',
		'title'      => __( 'Ungültiger Link', 'kurs-booking' ),
	),
	'error'             => array(
		'icon'       => 'exclamation-triangle-fill',
		'icon_color' => '#ef4444',
		'bg_color'   => '#fef2f2',
		'title'      => __( 'Fehler', 'kurs-booking' ),
	),
);

$config = $status_config[ $status ] ?? $status_config['error'];
?>

<div class="kb-confirmation-page" style="min-height: 60vh; display: flex; align-items: center; justify-content: center; padding: 2rem;">
	<div class="kb-confirmation-container" style="max-width: 600px; width: 100%; text-align: center;">

		<!-- Status Card -->
		<div class="kb-confirmation-card" style="background: <?php echo esc_attr( $config['bg_color'] ); ?>; border-radius: 16px; padding: 3rem 2rem; box-shadow: 0 4px 20px rgba(0,0,0,0.1);">

			<!-- Icon -->
			<div class="kb-confirmation-icon" style="margin-bottom: 1.5rem;">
				<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80" fill="<?php echo esc_attr( $config['icon_color'] ); ?>" viewBox="0 0 16 16">
					<?php if ( 'check-circle-fill' === $config['icon'] ) : ?>
						<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/>
					<?php elseif ( 'info-circle-fill' === $config['icon'] ) : ?>
						<path d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16zm.93-9.412-1 4.705c-.07.34.029.533.304.533.194 0 .487-.07.686-.246l-.088.416c-.287.346-.92.598-1.465.598-.703 0-1.002-.422-.808-1.319l.738-3.468c.064-.293.006-.399-.287-.47l-.451-.081.082-.381 2.29-.287zM8 5.5a1 1 0 1 1 0-2 1 1 0 0 1 0 2z"/>
					<?php elseif ( 'clock-history' === $config['icon'] ) : ?>
						<path d="M8.515 1.019A7 7 0 0 0 8 1V0a8 8 0 0 1 .589.022l-.074.997zm2.004.45a7.003 7.003 0 0 0-.985-.299l.219-.976c.383.086.76.2 1.126.342l-.36.933zm1.37.71a7.01 7.01 0 0 0-.439-.27l.493-.87a8.025 8.025 0 0 1 .979.654l-.615.789a6.996 6.996 0 0 0-.418-.302zm1.834 1.79a6.99 6.99 0 0 0-.653-.796l.724-.69c.27.285.52.59.747.91l-.818.576zm.744 1.352a7.08 7.08 0 0 0-.214-.468l.893-.45a7.976 7.976 0 0 1 .45 1.088l-.95.313a7.023 7.023 0 0 0-.179-.483zm.53 2.507a6.991 6.991 0 0 0-.1-1.025l.985-.17c.067.386.106.778.116 1.17l-1 .025zm-.131 1.538c.033-.17.06-.339.081-.51l.993.123a7.957 7.957 0 0 1-.23 1.155l-.964-.267c.046-.165.086-.332.12-.501zm-.952 2.379c.184-.29.346-.594.486-.908l.914.405c-.16.36-.345.706-.555 1.038l-.845-.535zm-.964 1.205c.122-.122.239-.248.35-.378l.758.653a8.073 8.073 0 0 1-.401.432l-.707-.707z"/>
						<path d="M8 1a7 7 0 1 0 4.95 11.95l.707.707A8.001 8.001 0 1 1 8 0v1z"/>
						<path d="M7.5 3a.5.5 0 0 1 .5.5v5.21l3.248 1.856a.5.5 0 0 1-.496.868l-3.5-2A.5.5 0 0 1 7 9V3.5a.5.5 0 0 1 .5-.5z"/>
					<?php elseif ( 'x-circle-fill' === $config['icon'] ) : ?>
						<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM5.354 4.646a.5.5 0 1 0-.708.708L7.293 8l-2.647 2.646a.5.5 0 0 0 .708.708L8 8.707l2.646 2.647a.5.5 0 0 0 .708-.708L8.707 8l2.647-2.646a.5.5 0 0 0-.708-.708L8 7.293 5.354 4.646z"/>
					<?php else : ?>
						<path d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/>
					<?php endif; ?>
				</svg>
			</div>

			<!-- Title -->
			<h1 style="font-size: 1.75rem; font-weight: 700; color: #1f2937; margin: 0 0 1rem 0;">
				<?php echo esc_html( $config['title'] ); ?>
			</h1>

			<!-- Message -->
			<p style="font-size: 1.125rem; color: #4b5563; margin: 0 0 1.5rem 0; line-height: 1.6;">
				<?php echo esc_html( $message ); ?>
			</p>

			<?php if ( 'success' === $status && $kurs_title ) : ?>
				<!-- Booking Details -->
				<div class="kb-booking-details" style="background: #fff; border-radius: 12px; padding: 1.5rem; margin-top: 1.5rem; text-align: left;">
					<h3 style="font-size: 1rem; font-weight: 600; color: #374151; margin: 0 0 1rem 0; padding-bottom: 0.75rem; border-bottom: 1px solid #e5e7eb;">
						<?php esc_html_e( 'Ihre Buchung', 'kurs-booking' ); ?>
					</h3>

					<div style="display: grid; gap: 0.75rem;">
						<?php if ( $kurs_title ) : ?>
							<div style="display: flex; justify-content: space-between; align-items: center;">
								<span style="color: #6b7280; font-size: 0.875rem;"><?php esc_html_e( 'Kurs', 'kurs-booking' ); ?></span>
								<span style="color: #1f2937; font-weight: 500;"><?php echo esc_html( $kurs_title ); ?></span>
							</div>
						<?php endif; ?>

						<?php if ( $kurs_date ) : ?>
							<div style="display: flex; justify-content: space-between; align-items: center;">
								<span style="color: #6b7280; font-size: 0.875rem;"><?php esc_html_e( 'Datum', 'kurs-booking' ); ?></span>
								<span style="color: #1f2937; font-weight: 500;"><?php echo esc_html( $kurs_date ); ?></span>
							</div>
						<?php endif; ?>

						<?php if ( $buchung_id ) : ?>
							<div style="display: flex; justify-content: space-between; align-items: center;">
								<span style="color: #6b7280; font-size: 0.875rem;"><?php esc_html_e( 'Buchungsnummer', 'kurs-booking' ); ?></span>
								<span style="color: #1f2937; font-weight: 500; font-family: monospace;">#<?php echo esc_html( $buchung_id ); ?></span>
							</div>
						<?php endif; ?>
					</div>
				</div>

				<p style="font-size: 0.875rem; color: #6b7280; margin-top: 1.5rem;">
					<?php esc_html_e( 'Sie erhalten in Kürze eine Bestätigungs-E-Mail mit allen Details.', 'kurs-booking' ); ?>
				</p>
			<?php endif; ?>

		</div>

		<!-- Actions -->
		<div class="kb-confirmation-actions" style="margin-top: 2rem; display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap;">
			<a href="<?php echo esc_url( home_url( '/' ) ); ?>"
			   style="display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.75rem 1.5rem; background: var(--global-palette1, #00868b); color: #fff; text-decoration: none; border-radius: 8px; font-weight: 500; transition: background 0.2s;">
				<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
					<path d="M8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4.5a.5.5 0 0 0 .5-.5v-4h2v4a.5.5 0 0 0 .5.5H14a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146zM2.5 14V7.707l5.5-5.5 5.5 5.5V14H10v-4a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5v4H2.5z"/>
				</svg>
				<?php esc_html_e( 'Zur Startseite', 'kurs-booking' ); ?>
			</a>

			<?php if ( $kurs_id ) : ?>
				<a href="<?php echo esc_url( get_permalink( $kurs_id ) ); ?>"
				   style="display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.75rem 1.5rem; background: #fff; color: #374151; text-decoration: none; border-radius: 8px; font-weight: 500; border: 1px solid #d1d5db; transition: background 0.2s;">
					<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
						<path d="M11 6.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5v-1zm-3 0a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5v-1zm-5 3a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5v-1zm3 0a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5v-1z"/>
						<path d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zM1 4v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V4H1z"/>
					</svg>
					<?php esc_html_e( 'Zum Kurs', 'kurs-booking' ); ?>
				</a>
			<?php endif; ?>
		</div>

	</div>
</div>

<style>
.kb-confirmation-actions a:hover {
	opacity: 0.9;
}
</style>

<?php
get_footer();
