<?php
/**
 * Frontend template: Thank-you / cancellation page.
 *
 * Variables provided by ThankYouPage::renderPage():
 *   @var string         $action          'success' or 'cancel'.
 *   @var \Donatico\Models\Donation|null  $donation  Donation object, or null if not found.
 *   @var string         $currency        ISO currency code.
 *   @var string         $currency_symbol Currency symbol.
 *
 * @package Donatico
 */

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

// Variables are set by ThankYouPage::renderPage() before this template is included.
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound

$is_success = $action === 'success';
?>

<div class="donatico-return-page">
	<div class="donatico-return-card">

		<?php if ( $is_success ) : ?>

			<?php /* ---- Success icon ---- */ ?>
			<div class="donatico-return-icon donatico-return-icon--success" aria-hidden="true">
				<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" width="48" height="48">
					<circle cx="12" cy="12" r="10"/>
					<polyline points="9 12 11.5 14.5 15.5 10"/>
				</svg>
			</div>

			<h1 class="donatico-return-title"><?php esc_html_e( 'Thank you!', 'donatico' ); ?></h1>

			<?php if ( $donation ) : ?>
				<p class="donatico-return-message">
					<?php
					printf(
						/* translators: 1: formatted amount with symbol */
						esc_html__( 'Your donation of %1$s has been received. You\'ll get a confirmation email shortly.', 'donatico' ),
						'<strong>' . esc_html( $currency_symbol . $donation->getFormattedAmount() . ' ' . $donation->getCurrency() ) . '</strong>'
					);
					?>
				</p>

				<?php if ( ! $donation->isAnonymous() ) : ?>
				<p class="donatico-return-meta">
					<?php
					printf(
						/* translators: %s: donor name */
						esc_html__( 'We\'ve noted your name as %s.', 'donatico' ),
						'<strong>' . esc_html( $donation->getDonorName() ) . '</strong>'
					);
					?>
				</p>
				<?php endif; ?>

				<?php if ( $donation->getMessage() ) : ?>
				<blockquote class="donatico-return-quote">
					<?php echo esc_html( $donation->getMessage() ); ?>
				</blockquote>
				<?php endif; ?>

			<?php else : ?>
				<p class="donatico-return-message">
					<?php esc_html_e( 'Your donation has been received. You\'ll get a confirmation email shortly.', 'donatico' ); ?>
				</p>
			<?php endif; ?>

			<div class="donatico-return-actions">
				<a href="<?php echo esc_url( home_url( '/' ) ); ?>" class="donatico-btn donatico-btn--primary">
					<?php esc_html_e( 'Return to Homepage', 'donatico' ); ?>
				</a>
			</div>

		<?php else : ?>

			<?php /* ---- Cancel icon ---- */ ?>
			<div class="donatico-return-icon donatico-return-icon--cancel" aria-hidden="true">
				<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" width="48" height="48">
					<circle cx="12" cy="12" r="10"/>
					<line x1="15" y1="9" x2="9" y2="15"/>
					<line x1="9" y1="9" x2="15" y2="15"/>
				</svg>
			</div>

			<h1 class="donatico-return-title"><?php esc_html_e( 'Donation cancelled', 'donatico' ); ?></h1>
			<p class="donatico-return-message">
				<?php esc_html_e( 'Your donation was not completed. No charge was made.', 'donatico' ); ?>
			</p>

			<div class="donatico-return-actions">
				<a href="<?php echo esc_url( wp_get_referer() ?: home_url( '/' ) ); ?>"
				   class="donatico-btn donatico-btn--primary">
					<?php esc_html_e( 'Try Again', 'donatico' ); ?>
				</a>
				<a href="<?php echo esc_url( home_url( '/' ) ); ?>"
				   class="donatico-btn donatico-btn--secondary">
					<?php esc_html_e( 'Homepage', 'donatico' ); ?>
				</a>
			</div>

		<?php endif; ?>

	</div><!-- .donatico-return-card -->
</div><!-- .donatico-return-page -->
