<?php
/**
 * Swish awaiting payment page
 */

defined( 'ABSPATH' ) || exit;

/**
 * CSS file url
 *
 * @var string $css_link
 */

/**
 * JS file urls
 *
 * @var string[] $js_links
 */

/**
 * JS file variables
 *
 * @var string[] $js_local
 */

/**
 * Logo URL
 *
 * @var string $logo
 */

/**
 * Swish environment
 *
 * @var string $swish_environment
 */

/**
 * WC order
 *
 * @var WC_Order $order
 */

// @phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet
// @phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript

?>
<!DOCTYPE html>
<!--suppress HtmlRequiredLangAttribute -->
<html <?php language_attributes(); ?>>
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
	<title><?php esc_html_e( 'Please approve your payment in the Swish app', 'flo-checkout-plugin' ); ?></title>
	<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;700&display=swap" rel="stylesheet">
	<link rel="stylesheet" href="<?php echo esc_attr( $css_link ); ?>" />
	<?php foreach ( $js_links as $js_link ) { ?>
		<script src="<?php echo esc_attr( $js_link ); ?>"></script>
	<?php } ?>
	<script>
		const swishAjax = <?php echo wp_json_encode( $js_local ); ?>;
	</script>
</head>
<body>
	<div class="moreflo-swish mf-swish-pay mf-swish-pay--processing">
		<div>
			<img class="mf-swish-pay__image" src="<?php echo esc_attr( $logo ); ?>"  alt="Swish logo"/>
		</div>

		<div class="moreflo-swish-messages">
			<span class="moreflo-swish-status"><?php esc_html_e( 'You\'re paying with Swish', 'flo-checkout-plugin' ); ?></span>
			<p class="moreflo-swish-status-info"><?php esc_html_e( 'Open your Swish app to complete the payment', 'flo-checkout-plugin' ); ?></p>
		</div>

		<div>
			<div class="lds-ellipsis">
				<div></div>
				<div></div>
				<div></div>
				<div></div>
			</div>
		</div>

		<!-- Error message -->
		<div class="moreflo-swish-error">
			<p class="moreflo-swish-error__message">
				<?php esc_html_e( 'Could not cancel your payment. You might have to cancel it manually in your Swish app before you try again.', 'flo-checkout-plugin' ); ?>
			</p>
			<a href="<?php echo esc_url( $order->get_cancel_order_url_raw() ); ?>"><?php esc_html_e( 'Go back', 'flo-checkout-plugin' ); ?></a>
		</div>

		<p><a href="swish://" class="mf-swish-pay__open-app"><?php esc_html_e( 'Open Swish on this device', 'flo-checkout-plugin' ); ?></a></p>
		<p><a href="<?php echo esc_url( $order->get_cancel_order_url_raw() ); ?>" class="mf-swish-pay__cancel"><?php esc_html_e( 'Cancel payment', 'flo-checkout-plugin' ); ?></a></p>
		<?php
		if (
			( 'sandbox' === $swish_environment || 'mss' === $swish_environment ) &&
			'local' === wp_get_environment_type()
		) {
			$local_dev_swish_url = home_url( '?wc-api=swish_pay_gateway_local_dev&event=payment&status=paid&order_id=' . $order->get_id() );
			echo '<a href="' . esc_url( $local_dev_swish_url ) . '" target="_blank">Trigger DEV pay</a>';
		}
		?>
	</div>
</body>
</html>
