<?php
/**
 * Printable Qr.
 *
 * @package Noesia_Commerce_Suite
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- View templates receive local variables from their renderer.
$settings       = Noesia_CS_Settings::get_all();
$order_ref      = $passport_service->get_safe_order_reference( $order );
$purchase_date  = $order->get_date_created() ? $order->get_date_created()->date_i18n( get_option( 'date_format' ) ) : '';
$logo           = ! empty( $settings['company_logo'] ) ? esc_url( $settings['company_logo'] ) : '';
$company_name   = ! empty( $settings['company_name'] ) ? $settings['company_name'] : get_bloginfo( 'name' );
$qr_size        = max( 120, min( 420, absint( $settings['qr_size'] ?? 180 ) ) );
?><!doctype html>
<html <?php language_attributes(); ?>>
<head>
	<meta charset="<?php bloginfo( 'charset' ); ?>">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="robots" content="noindex,nofollow">
	<title><?php echo esc_html( sprintf( /* translators: %s: dynamic value. */ __( 'Printable QR for %s', 'noesia-commerce-suite' ), $order_ref ) ); ?></title>
	<?php wp_print_styles(); ?>
	<?php wp_print_scripts(); ?>
</head>
<body class="noesia-cs-print-body">
	<main class="noesia-cs-print-page" style="--noesia-cs-primary:<?php echo esc_attr( $settings['primary_color'] ); ?>;--noesia-cs-accent:<?php echo esc_attr( $settings['accent_color'] ); ?>;">
		<section class="noesia-cs-print-toolbar no-print">
			<a href="<?php echo esc_url( admin_url( 'admin.php?page=noesia-commerce-suite&tab=order-care-hub&noesia_cs_hub_section=access' ) ); ?>"><?php esc_html_e( 'Back to Order Care Hub', 'noesia-commerce-suite' ); ?></a>
			<button type="button" onclick="window.print();"><?php esc_html_e( 'Print QR Insert', 'noesia-commerce-suite' ); ?></button>
		</section>

		<section class="noesia-cs-print-card">
			<header class="noesia-cs-print-header">
				<?php if ( $logo ) : ?>
					<img src="<?php echo esc_url( $logo ); ?>" alt="<?php echo esc_attr( $company_name ); ?>">
				<?php else : ?>
					<div class="noesia-cs-print-mark">N</div>
				<?php endif; ?>
				<div>
					<strong><?php echo esc_html( $company_name ); ?></strong>
					<span><?php esc_html_e( 'Order Care Hub', 'noesia-commerce-suite' ); ?></span>
				</div>
			</header>

			<div class="noesia-cs-print-qr" data-noesia-cs-qr="<?php echo esc_url( $url ); ?>" data-noesia-cs-qr-size="<?php echo esc_attr( $qr_size ); ?>" data-noesia-cs-qr-foreground="<?php echo esc_attr( $settings['qr_foreground_color'] ); ?>" data-noesia-cs-qr-background="<?php echo esc_attr( $settings['qr_background_color'] ); ?>"></div>

			<h1><?php echo esc_html( $settings['qr_label_text'] ); ?></h1>
			<p><?php esc_html_e( 'Scan this QR code to open the secure order care page for warranty, support, review and reorder actions.', 'noesia-commerce-suite' ); ?></p>

			<div class="noesia-cs-print-meta">
				<div><span><?php esc_html_e( 'Order', 'noesia-commerce-suite' ); ?></span><strong><?php echo esc_html( $order_ref ); ?></strong></div>
				<?php if ( $purchase_date ) : ?><div><span><?php esc_html_e( 'Purchase Date', 'noesia-commerce-suite' ); ?></span><strong><?php echo esc_html( $purchase_date ); ?></strong></div><?php endif; ?>
			</div>

			<?php if ( 'yes' === ( $settings['show_product_name'] ?? 'yes' ) ) : ?>
				<div class="noesia-cs-print-products">
					<strong><?php esc_html_e( 'Included Products', 'noesia-commerce-suite' ); ?></strong>
					<ul>
						<?php foreach ( $order->get_items() as $item ) : ?>
							<li><?php echo esc_html( $item->get_name() ); ?></li>
						<?php endforeach; ?>
					</ul>
				</div>
			<?php endif; ?>

			<footer><?php echo esc_html( wp_parse_url( home_url(), PHP_URL_HOST ) ); ?></footer>
		</section>
	</main>
</body>
</html>
