<?php
/**
 * Admin.
 *
 * @package Noesia_Commerce_Suite
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- View templates receive local variables from their renderer.
$passport_rows = isset( $passport_rows ) && is_array( $passport_rows ) ? $passport_rows : array();
$qr_settings = isset( $qr_settings ) && is_array( $qr_settings ) ? $qr_settings : array(
	'size'        => 160,
	'foreground'  => '#111827',
	'background'  => '#ffffff',
	'enabled'     => true,
	'printable'   => false,
);
?>
<section class="noesia-cs-feature-hero noesia-cs-feature-hero--passport">
	<div>
		<span><?php esc_html_e( 'Core Engine', 'noesia-commerce-suite' ); ?></span>
		<h2><?php esc_html_e( 'Order-level Product Passport QR', 'noesia-commerce-suite' ); ?></h2>
		<p><?php esc_html_e( 'One secure care token per WooCommerce order. Tokens are generated only by customer QR placement, order admin action, or a deliberate admin action here.', 'noesia-commerce-suite' ); ?></p>
	</div>
	<div class="noesia-cs-hero-orb">QR</div>
</section>
<div class="noesia-cs-panel noesia-cs-qr-settings-panel">
	<div class="noesia-cs-panel__head"><h2><?php esc_html_e( 'QR Rendering Settings', 'noesia-commerce-suite' ); ?></h2><span><?php esc_html_e( 'These values are applied to admin and customer QR rendering. No external QR service is used.', 'noesia-commerce-suite' ); ?></span></div>
	<div class="noesia-cs-mini-grid">
		<div><strong><?php echo esc_html( absint( $qr_settings['size'] ?? 160 ) ); ?>px</strong><span><?php esc_html_e( 'Default QR Size', 'noesia-commerce-suite' ); ?></span></div>
		<div><strong><?php echo esc_html( $qr_settings['foreground'] ?? '#111827' ); ?></strong><span><?php esc_html_e( 'Foreground', 'noesia-commerce-suite' ); ?></span></div>
		<div><strong><?php echo esc_html( $qr_settings['background'] ?? '#ffffff' ); ?></strong><span><?php esc_html_e( 'Background', 'noesia-commerce-suite' ); ?></span></div>
		<div><strong><?php echo ! empty( $qr_settings['enabled'] ) ? esc_html__( 'Enabled', 'noesia-commerce-suite' ) : esc_html__( 'Disabled', 'noesia-commerce-suite' ); ?></strong><span><?php esc_html_e( 'Passport QR', 'noesia-commerce-suite' ); ?></span></div>
	</div>
</div>
<div class="noesia-cs-panel noesia-cs-qr-engine-status">
	<div class="noesia-cs-panel__head"><h2><?php esc_html_e( 'Self-hosted QR Engine', 'noesia-commerce-suite' ); ?></h2><span><?php esc_html_e( 'Local renderer', 'noesia-commerce-suite' ); ?></span></div>
	<div class="noesia-cs-mini-grid">
		<div><strong><?php esc_html_e( 'Self-hosted', 'noesia-commerce-suite' ); ?></strong><span><?php esc_html_e( 'QR renderer source', 'noesia-commerce-suite' ); ?></span></div>
		<div><strong><?php esc_html_e( 'No external API', 'noesia-commerce-suite' ); ?></strong><span><?php esc_html_e( 'No Google Chart, CDN or third-party QR call', 'noesia-commerce-suite' ); ?></span></div>
		<div><strong><?php esc_html_e( 'Scannable when token exists', 'noesia-commerce-suite' ); ?></strong><span><?php esc_html_e( 'Generated QR opens the secure Order Care URL', 'noesia-commerce-suite' ); ?></span></div>
		<div><strong><?php esc_html_e( 'Licensed source noted', 'noesia-commerce-suite' ); ?></strong><span><?php esc_html_e( 'See assets/libs/qrcode/LICENSE.txt and SOURCE.txt', 'noesia-commerce-suite' ); ?></span></div>
	</div>
</div>
<div class="noesia-cs-panel">
	<div class="noesia-cs-panel__head"><h2><?php esc_html_e( 'Recent Order Passports', 'noesia-commerce-suite' ); ?></h2><span><?php esc_html_e( 'Self-hosted QR engine · secure customer care links', 'noesia-commerce-suite' ); ?></span></div>
	<div class="noesia-cs-table-wrap"><table class="noesia-cs-table"><thead><tr><th><?php esc_html_e( 'Order', 'noesia-commerce-suite' ); ?></th><th><?php esc_html_e( 'Customer', 'noesia-commerce-suite' ); ?></th><th><?php esc_html_e( 'Passport', 'noesia-commerce-suite' ); ?></th><th><?php esc_html_e( 'Care Link', 'noesia-commerce-suite' ); ?></th><th><?php esc_html_e( 'QR', 'noesia-commerce-suite' ); ?></th></tr></thead><tbody>
	<?php foreach ( $passport_rows as $row ) : ?>
		<tr>
			<td><strong><?php echo esc_html( $row['reference'] ?? '' ); ?></strong><small><?php echo esc_html( $row['date'] ?? '' ); ?></small></td>
			<td><?php echo esc_html( $row['customer_label'] ?? '' ); ?></td>
			<td><?php if ( ! empty( $row['has_token'] ) ) : ?><span class="noesia-cs-status is-green"><?php esc_html_e( 'Active', 'noesia-commerce-suite' ); ?></span><?php else : ?><span class="noesia-cs-status is-muted"><?php esc_html_e( 'Not generated', 'noesia-commerce-suite' ); ?></span><?php endif; ?></td>
			<td>
				<?php if ( ! empty( $row['has_token'] ) && ! empty( $row['url'] ) ) : ?>
					<button class="noesia-cs-link-button noesia-cs-copy-button" type="button" data-noesia-cs-copy="<?php echo esc_url( $row['url'] ); ?>"><?php esc_html_e( 'Copy Link', 'noesia-commerce-suite' ); ?></button>
					<a class="noesia-cs-link-button" href="<?php echo esc_url( $row['url'] ); ?>" target="_blank" rel="noopener noreferrer nofollow"><?php esc_html_e( 'Open', 'noesia-commerce-suite' ); ?></a>
					<?php if ( ! empty( $qr_settings['printable'] ) && ! empty( $row['print_url'] ) ) : ?>
						<a class="noesia-cs-link-button" href="<?php echo esc_url( $row['print_url'] ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Print QR', 'noesia-commerce-suite' ); ?></a>
					<?php endif; ?>
				<?php else : ?>
					<a class="noesia-cs-link-button" href="<?php echo esc_url( $row['generate_url'] ?? '' ); ?>"><?php esc_html_e( 'Generate Passport', 'noesia-commerce-suite' ); ?></a>
				<?php endif; ?>
			</td>
			<td><?php if ( ! empty( $row['has_token'] ) && ! empty( $row['url'] ) ) : ?><div class="noesia-cs-mini-qr" data-noesia-cs-qr="<?php echo esc_url( $row['url'] ); ?>" data-noesia-cs-qr-size="72" data-noesia-cs-qr-foreground="<?php echo esc_attr( $qr_settings['foreground'] ?? '#111827' ); ?>" data-noesia-cs-qr-background="<?php echo esc_attr( $qr_settings['background'] ?? '#ffffff' ); ?>"></div><?php else : ?><span class="noesia-cs-muted"><?php esc_html_e( 'No QR yet', 'noesia-commerce-suite' ); ?></span><?php endif; ?></td>
		</tr>
	<?php endforeach; ?>
	<?php if ( empty( $passport_rows ) ) : ?><tr><td colspan="5"><?php esc_html_e( 'No WooCommerce orders found yet.', 'noesia-commerce-suite' ); ?></td></tr><?php endif; ?>
	</tbody></table></div>
</div>
<section class="noesia-cs-pro-grid">
	<?php $admin->pro_edition_card( __( 'Customer QR Studio', 'noesia-commerce-suite' ), __( 'Create printable QR cards, labels and package inserts that bring customers back to warranty, support, reviews and reorders.', 'noesia-commerce-suite' ), 'customer_qr_studio' ); ?>
	<?php $admin->pro_edition_card( __( 'QR Card Styles & Use Cases', 'noesia-commerce-suite' ), __( 'Choose ready card styles for packages, labels, warranty cards and reorder inserts.', 'noesia-commerce-suite' ), 'customer_qr_studio' ); ?>
</section>
