<?php
/**
 * Debug Invoice Page View
 *
 * Displays comprehensive debug information for a Verifactu invoice.
 *
 * @package FreeFacTu
 * @since   1.0.0
 * 
 * @var int      $order_id             The order ID
 * @var object   $invoice_db           Invoice database record
 * @var WC_Order $order                Order object (may be null)
 * @var bool     $order_exists         Whether the order still exists
 * @var array    $options              Plugin settings
 * @var string   $csv                  CSV code from AEAT
 * @var bool     $sent_to_aeat         Whether invoice was sent to AEAT
 * @var string   $company_nif          Company NIF
 * @var string   $env                  Environment (test/production)
 * @var string   $invoice_number       Invoice number
 * @var string   $invoice_date         Invoice date
 * @var float    $invoice_total        Invoice total
 * @var string   $invoice_date_formatted Formatted invoice date
 * @var string   $qr_url               QR verification URL
 * @var string   $cache_key            QR cache key
 * @var bool     $qr_can_be_created    Whether QR can be generated
 * @var bool     $qr_is_cached         Whether QR is cached
 * @var string   $pdf_path             Path to PDF file
 * @var bool     $pdf_exists           Whether PDF file exists
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
	<meta charset="<?php bloginfo( 'charset' ); ?>">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title><?php esc_html_e( 'Debug Información Verifactu', 'freefactu' ); ?> - <?php echo $order_exists ? esc_html( $order->get_order_number() ) : esc_html( '#' . $order_id ); ?></title>
	<?php wp_admin_css( 'common' ); ?>
	<?php wp_admin_css( 'forms' ); ?>
	<?php
	wp_enqueue_style( 'dashicons' );
	wp_enqueue_style( 'freefactu-admin', FREEFACTU_PLUGIN_URL . 'assets/css/freefactu-admin.css', array(), FREEFACTU_VERSION );
	wp_enqueue_style( 'freefactu-debug', FREEFACTU_PLUGIN_URL . 'assets/css/freefactu-debug.css', array(), FREEFACTU_VERSION );
	wp_print_styles();
	?>
	<?php
	// Inline style removed - moved to freefactu-modals.css / admin css
	?>
</head>
<body class="freefactu-debug-page">
	<div class="freefactu-debug-container">
		<a href="<?php echo esc_url( admin_url( 'admin.php?page=freefactu' ) ); ?>" class="button freefactu-back-button">
			← <?php esc_html_e( 'Volver a Facturas Verifactu', 'freefactu' ); ?>
		</a>

		<h1><?php esc_html_e( 'Información de Depuración Verifactu', 'freefactu' ); ?></h1>
		<p>
			<strong><?php esc_html_e( 'Pedido:', 'freefactu' ); ?></strong>
			<?php if ( $order_exists ) : ?>
				<a href="<?php echo esc_url( admin_url( 'post.php?post=' . $order_id . '&action=edit' ) ); ?>" target="_blank">
					#<?php echo esc_html( $order->get_order_number() ); ?>
				</a>
			<?php else : ?>
				#<?php echo esc_html( $order_id ); ?> <span class="freefactu-deleted-order">(<?php esc_html_e( 'Pedido eliminado', 'freefactu' ); ?>)</span>
			<?php endif; ?>
		</p>

		<?php if ( ! $order_exists ) : ?>
			<div class="freefactu-warning-box">
				<strong><?php esc_html_e( 'Aviso:', 'freefactu' ); ?></strong>
				<?php esc_html_e( 'El pedido asociado a esta factura ha sido eliminado. La información mostrada proviene de la base de datos de Freefactu.', 'freefactu' ); ?>
			</div>
		<?php endif; ?>

		<h2><?php esc_html_e( 'Estado de Operaciones', 'freefactu' ); ?></h2>
		<div class="freefactu-status-grid">
			<div class="freefactu-status-card">
				<h3><?php esc_html_e( 'Snapshot', 'freefactu' ); ?></h3>
				<div class="freefactu-status-card__value <?php echo ! empty( $invoice_db->invoice_snapshot ) ? 'status-yes' : 'status-no'; ?>">
				<?php echo ! empty( $invoice_db->invoice_snapshot ) ? '<span class="dashicons dashicons-yes-alt"></span> ' . esc_html__( 'Guardado', 'freefactu' ) : '<span class="dashicons dashicons-no-alt"></span> ' . esc_html__( 'No disponible', 'freefactu' ); ?>
			</div>
				<small>
					<?php
					if ( ! empty( $invoice_db->invoice_snapshot ) ) {
						$freefactu_snapshot_size = strlen( $invoice_db->invoice_snapshot );
						printf(
							/* translators: %s: snapshot size in bytes */
							esc_html__( '%s bytes', 'freefactu' ),
							esc_html( number_format( $freefactu_snapshot_size ) ) 
						);
					} else {
						esc_html_e( 'Sin datos guardados', 'freefactu' );
					}
					?>
				</small>
			</div>

			<div class="freefactu-status-card">
				<h3><?php esc_html_e( 'Enviado a AEAT', 'freefactu' ); ?></h3>
				<div class="freefactu-status-card__value <?php echo esc_attr( $sent_to_aeat ? 'status-yes' : 'status-no' ); ?>">
				<?php echo $sent_to_aeat ? '<span class="dashicons dashicons-yes-alt"></span> ' . esc_html__( 'Sí', 'freefactu' ) : '<span class="dashicons dashicons-no-alt"></span> ' . esc_html__( 'No', 'freefactu' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded HTML + esc_html__(). ?>
			</div>
				<?php if ( $sent_to_aeat ) : ?>
					<small><?php esc_html_e( 'CSV:', 'freefactu' ); ?> <code><?php echo esc_html( $csv ); ?></code></small>
				<?php endif; ?>
			</div>

			<div class="freefactu-status-card">
				<h3><?php esc_html_e( 'Código QR', 'freefactu' ); ?></h3>
				<div class="freefactu-status-card__value <?php echo esc_attr( $qr_can_be_created ? 'status-yes' : 'status-no' ); ?>">
				<?php echo $qr_can_be_created ? '<span class="dashicons dashicons-yes-alt"></span> ' . esc_html__( 'Disponible', 'freefactu' ) : '<span class="dashicons dashicons-no-alt"></span> ' . esc_html__( 'No disponible', 'freefactu' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded HTML + esc_html__(). ?>
			</div>
				<small>
					<?php if ( $qr_is_cached ) : ?>
						<?php esc_html_e( 'En caché', 'freefactu' ); ?>
					<?php elseif ( $qr_can_be_created ) : ?>
						<?php esc_html_e( 'Se genera al visualizar', 'freefactu' ); ?>
					<?php else : ?>
						<?php esc_html_e( 'Requiere CSV de AEAT', 'freefactu' ); ?>
					<?php endif; ?>
				</small>
			</div>

			<div class="freefactu-status-card">
				<h3><?php esc_html_e( 'PDF Creado', 'freefactu' ); ?></h3>
				<div class="freefactu-status-card__value <?php echo esc_attr( $pdf_exists ? 'status-yes' : 'status-no' ); ?>">
				<?php echo $pdf_exists ? '<span class="dashicons dashicons-yes-alt"></span> ' . esc_html__( 'Sí', 'freefactu' ) : '<span class="dashicons dashicons-no-alt"></span> ' . esc_html__( 'No', 'freefactu' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded HTML + esc_html__(). ?>
			</div>
				<?php if ( $pdf_exists ) : ?>
					<small><?php esc_html_e( 'Archivo existe', 'freefactu' ); ?></small>
				<?php endif; ?>
			</div>

			<div class="freefactu-status-card">
				<h3><?php esc_html_e( 'Estado General', 'freefactu' ); ?></h3>
				<div class="freefactu-status-card__value">
					<?php
					$status = $invoice_db->status;
					$freefactu_status_labels = array(
						'success'    => __( 'Éxito', 'freefactu' ),
						'alert_aeat' => __( 'Error AEAT', 'freefactu' ),
						'alert_qr'   => __( 'Error QR', 'freefactu' ),
						'alert_pdf'  => __( 'Error PDF', 'freefactu' ),
					);
					$freefactu_status_label = isset( $freefactu_status_labels[ $status ] ) ? $freefactu_status_labels[ $status ] : __( 'Desconocido', 'freefactu' );
					$freefactu_status_class = $status === 'success' ? 'status-yes' : 'status-no';
					?>
					<span class="<?php echo esc_attr( $freefactu_status_class ); ?>"><?php echo esc_html( $freefactu_status_label ); ?></span>
				</div>
			</div>
		</div>

		<?php if ( $invoice_db && ! empty( $invoice_db->error_message ) ) : ?>
			<div class="freefactu-error-box">
				<strong><?php esc_html_e( 'Mensaje de Error:', 'freefactu' ); ?></strong><br>
				<?php echo esc_html( $invoice_db->error_message ); ?>
			</div>
		<?php endif; ?>

		<h2><?php esc_html_e( 'Datos de la Factura', 'freefactu' ); ?></h2>
		<table class="freefactu-meta-table">
			<tr>
				<th scope="col"><?php esc_html_e( 'Campo', 'freefactu' ); ?></th>
				<th scope="col"><?php esc_html_e( 'Valor', 'freefactu' ); ?></th>
			</tr>
			<tr>
				<td><?php esc_html_e( 'Número de Factura', 'freefactu' ); ?></td>
				<td>
					<code><?php echo esc_html( $invoice_number ? $invoice_number : __( 'No asignado', 'freefactu' ) ); ?></code>
					<?php 
					$freefactu_is_rectificativa = ! empty( $invoice_db->tipo_factura ) && in_array( $invoice_db->tipo_factura, array( 'R1', 'R2', 'R3', 'R4', 'R5' ), true );
					if ( $freefactu_is_rectificativa ) {
						echo ' <span class="freefactu-badge-rectificativa" title="' . esc_attr__( 'Factura rectificativa', 'freefactu' ) . '">R</span>';
					}
					?>
				</td>
			</tr>
			<?php 
			// Rectificativa additional information
			if ( $freefactu_is_rectificativa ) :
				$freefactu_original_invoice = null;
				if ( ! empty( $invoice_db->rectified_invoice_id ) ) {
					$freefactu_original_invoice = Freefactu_DB::get_invoice( $invoice_db->rectified_invoice_id );
				}
				
				$freefactu_tipo_labels = array(
					'R1' => __( 'R1 - Rectificativa por error fundado en derecho', 'freefactu' ),
					'R2' => __( 'R2 - Rectificativa por artículo 80.3 LIVA', 'freefactu' ),
					'R3' => __( 'R3 - Rectificativa por artículo 80.4 LIVA', 'freefactu' ),
					'R4' => __( 'R4 - Resto de rectificativas', 'freefactu' ),
					'R5' => __( 'R5 - Rectificativa simplificada', 'freefactu' ),
				);
				$freefactu_tipo_label = isset( $freefactu_tipo_labels[ $invoice_db->tipo_factura ] ) ? $freefactu_tipo_labels[ $invoice_db->tipo_factura ] : $invoice_db->tipo_factura;
				
				$freefactu_metodo_labels = array(
					'S' => __( 'Sustitución (Importe total correcto)', 'freefactu' ),
					'I' => __( 'Diferencias (Solo la diferencia)', 'freefactu' ),
				);
				$freefactu_metodo = isset( $invoice_db->tipo_rectificativa ) ? $invoice_db->tipo_rectificativa : '';
				$freefactu_metodo_label = isset( $freefactu_metodo_labels[ $freefactu_metodo ] ) ? $freefactu_metodo_labels[ $freefactu_metodo ] : $freefactu_metodo;
			?>
			<tr>
				<td><?php esc_html_e( 'Tipo de Rectificativa', 'freefactu' ); ?></td>
				<td>
					<span class="freefactu-rectificativa-label">
						<?php echo esc_html( $freefactu_tipo_label ); ?>
					</span>
				</td>
			</tr>
			<?php if ( ! empty( $freefactu_metodo_label ) ) : ?>
			<tr>
				<td><?php esc_html_e( 'Método de Rectificación', 'freefactu' ); ?></td>
				<td><?php echo esc_html( $freefactu_metodo_label ); ?></td>
			</tr>
			<?php endif; ?>
			<tr>
				<td><?php esc_html_e( 'Factura Original Rectificada', 'freefactu' ); ?></td>
				<td>
					<?php if ( $freefactu_original_invoice ) : 
						$freefactu_original_debug_url = wp_nonce_url( 
							admin_url( 'admin-post.php?action=freefactu_debug_invoice&order_id=' . $freefactu_original_invoice->order_id ), 
							'freefactu_debug_invoice' 
						);
					?>
						<a href="<?php echo esc_url( $freefactu_original_debug_url ); ?>" class="freefactu-debug-link">
							<code><?php echo esc_html( $freefactu_original_invoice->invoice_number ); ?></code>
							<span class="dashicons dashicons-external" aria-hidden="true"></span>
							<span><?php esc_html_e( 'Ver detalles', 'freefactu' ); ?></span>
						</a>
						<br>
						<small class="freefactu-text-muted">
							<?php 
							printf( 
								/* translators: %1$d: invoice ID, %2$d: order ID, %3$s: price */
								esc_html__( 'ID de factura: %1$d | Pedido: #%2$d | Total: %3$s', 'freefactu' ), 
								esc_html( $freefactu_original_invoice->id ),
								esc_html( $freefactu_original_invoice->order_id ),
								wp_kses_post( wc_price( $freefactu_original_invoice->total ) )
							);
							?>
						</small>
					<?php else : ?>
						<span class="freefactu-deleted-order">
							<span class="dashicons dashicons-warning" aria-hidden="true"></span>
							<?php 
							if ( ! empty( $invoice_db->rectified_invoice_id ) ) {
								printf( 
									/* translators: %d: invoice ID */
									esc_html__( 'Factura original no encontrada (ID: %d)', 'freefactu' ), 
									esc_html( $invoice_db->rectified_invoice_id ) 
								);
							} else {
								esc_html_e( 'ID de factura original no registrado', 'freefactu' );
							}
							?>
						</span>
					<?php endif; ?>
				</td>
			</tr>
			<?php endif; ?>
			<tr>
				<td><?php esc_html_e( 'Fecha de Factura', 'freefactu' ); ?></td>
				<td><?php
					if ( is_numeric( $invoice_date ) ) {
						echo esc_html( date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $invoice_date ) );
					} elseif ( ! empty( $invoice_date ) ) {
						echo esc_html( date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $invoice_date ) ) );
					} else {
						echo esc_html__( 'No asignada', 'freefactu' );
					}
				?></td>
			</tr>
			<tr>
				<td><?php esc_html_e( 'Total del Pedido', 'freefactu' ); ?></td>
				<td><?php echo wp_kses_post( wc_price( $invoice_total ) ); ?></td>
			</tr>
			<tr>
				<td><?php esc_html_e( 'CSV (Código Verifactu)', 'freefactu' ); ?></td>
				<td><code><?php echo esc_html( $csv ? $csv : __( 'No disponible', 'freefactu' ) ); ?></code></td>
			</tr>
			<tr>
				<td><?php esc_html_e( 'Huella (Hash)', 'freefactu' ); ?></td>
				<td>
					<?php
					$freefactu_hash = $invoice_db->hash;
					if ( $freefactu_hash ) :
						$freefactu_hash_short = substr( $freefactu_hash, 0, 16 ) . '...' . substr( $freefactu_hash, -8 );
					?>
						<div class="freefactu-hash-display">
							<code class="hash-short" title="<?php echo esc_attr( $freefactu_hash ); ?>">
								<?php echo esc_html( $freefactu_hash_short ); ?>
							</code>
							<button type="button" class="button button-small freefactu-copy-btn copy-hash-btn" 
								data-hash="<?php echo esc_attr( $freefactu_hash ); ?>"
								title="<?php esc_attr_e( 'Copiar hash completo', 'freefactu' ); ?>">
								<span class="dashicons dashicons-clipboard" aria-hidden="true"></span>
								<span><?php esc_html_e( 'Copiar', 'freefactu' ); ?></span>
							</button>
							<button type="button" class="button button-small freefactu-toggle-btn toggle-hash-btn"
								data-full="<?php echo esc_attr( $freefactu_hash ); ?>"
								data-short="<?php echo esc_attr( $freefactu_hash_short ); ?>"
								title="<?php esc_attr_e( 'Mostrar/ocultar hash completo', 'freefactu' ); ?>">
								<span class="dashicons dashicons-visibility" aria-hidden="true"></span>
								<span><?php esc_html_e( 'Ver completo', 'freefactu' ); ?></span>
							</button>
						</div>
						<div class="hash-full" style="display: none;">
							<code><?php echo esc_html( $freefactu_hash ); ?></code>
						</div>
					<?php else : ?>
						<span class="text-muted"><?php esc_html_e( 'No disponible', 'freefactu' ); ?></span>
					<?php endif; ?>
				</td>
			</tr>
			<tr>
				<td><?php esc_html_e( 'Integridad de Cadena', 'freefactu' ); ?></td>
				<td>
					<?php
					if ( ! empty( $invoice_db->hash ) ) :
						$freefactu_prev_invoice = Freefactu_DB::get_previous_chained_invoice( $invoice_db->id );
						
						if ( $freefactu_prev_invoice ) :
					?>
						<span class="freefactu-chain-valid">
							<span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
							<?php 
							printf( 
								/* translators: %s: previous invoice number */
								esc_html__( 'Encadenada con %s', 'freefactu' ), 
								esc_html( $freefactu_prev_invoice->invoice_number ) 
							); 
							?>
						</span>
					<?php else : ?>
						<span class="freefactu-chain-first">
							<span class="dashicons dashicons-flag" aria-hidden="true"></span>
							<?php esc_html_e( 'Primera factura de la cadena', 'freefactu' ); ?>
						</span>
					<?php 
						endif;
					else : 
					?>
						<span class="freefactu-chain-invalid">
							<span class="dashicons dashicons-warning" aria-hidden="true"></span>
							<?php esc_html_e( 'Sin hash - No encadenada', 'freefactu' ); ?>
						</span>
					<?php endif; ?>
				</td>
			</tr>
			<tr>
				<td><?php esc_html_e( 'Ruta del PDF', 'freefactu' ); ?></td>
				<td><code><?php echo esc_html( $pdf_path ? $pdf_path : __( 'No disponible', 'freefactu' ) ); ?></code></td>
			</tr>
		</table>

		<h2><?php esc_html_e( 'Información de Base de Datos', 'freefactu' ); ?></h2>
		<?php if ( $invoice_db ) : ?>
			<table class="freefactu-meta-table">
				<tr>
					<th scope="col"><?php esc_html_e( 'Campo', 'freefactu' ); ?></th>
					<th scope="col"><?php esc_html_e( 'Valor', 'freefactu' ); ?></th>
				</tr>
				<tr>
					<td><?php esc_html_e( 'ID', 'freefactu' ); ?></td>
					<td><?php echo esc_html( $invoice_db->id ); ?></td>
				</tr>
				<tr>
					<td><?php esc_html_e( 'Fecha de Creación', 'freefactu' ); ?></td>
					<td><?php echo esc_html( $invoice_db->created_at ); ?></td>
				</tr>
				<tr>
					<td><?php esc_html_e( 'Estado', 'freefactu' ); ?></td>
					<td><code><?php echo esc_html( $invoice_db->status ); ?></code></td>
				</tr>
			</table>
		<?php else : ?>
			<div class="freefactu-warning-box">
				<?php esc_html_e( 'No se encontró registro en la base de datos de Freefactu.', 'freefactu' ); ?>
			</div>
		<?php endif; ?>

		<h2><?php esc_html_e( 'XML Enviado a AEAT (Request)', 'freefactu' ); ?></h2>
		<?php if ( ! empty( $invoice_db->aeat_xml_request ) ) : ?>
			<div class="freefactu-xml-wrapper">
				<button type="button" class="button toggle-xml-btn">
					<span class="dashicons dashicons-visibility" aria-hidden="true"></span>
					<?php esc_html_e( 'Ver/Ocultar XML Completo', 'freefactu' ); ?>
				</button>
				<button type="button" class="button copy-xml-btn" data-xml="<?php echo esc_attr( $invoice_db->aeat_xml_request ); ?>">
					<span class="dashicons dashicons-clipboard" aria-hidden="true"></span>
					<?php esc_html_e( 'Copiar XML', 'freefactu' ); ?>
				</button>
				<div class="xml-container freefactu-mt-10" style="display: none;">
					<?php 
					// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Function escapes XML with htmlspecialchars() then adds only hardcoded span tags. See docblock in class-freefactu-history.php.
					echo Freefactu_History::format_and_highlight_xml( $invoice_db->aeat_xml_request ); 
					?>
				</div>
			</div>
		<?php else : ?>
			<div class="freefactu-warning-box">
				<?php esc_html_e( 'No hay XML de solicitud guardado para esta factura. Se guardará automáticamente en los próximos envíos.', 'freefactu' ); ?>
			</div>
		<?php endif; ?>

		<h2><?php esc_html_e( 'Respuesta XML AEAT', 'freefactu' ); ?></h2>
		<?php if ( ! empty( $invoice_db->aeat_xml_response ) ) : ?>
			<div class="freefactu-xml-wrapper">
				<button type="button" class="button toggle-xml-btn">
					<span class="dashicons dashicons-visibility" aria-hidden="true"></span>
					<?php esc_html_e( 'Ver/Ocultar XML Completo', 'freefactu' ); ?>
				</button>
				<button type="button" class="button copy-xml-btn" data-xml="<?php echo esc_attr( $invoice_db->aeat_xml_response ); ?>">
					<span class="dashicons dashicons-clipboard" aria-hidden="true"></span>
					<?php esc_html_e( 'Copiar XML', 'freefactu' ); ?>
				</button>
				<div class="xml-container freefactu-mt-10" style="display: none;">
					<?php 
					// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Function escapes XML with htmlspecialchars() then adds only hardcoded span tags. See docblock in class-freefactu-history.php.
					echo Freefactu_History::format_and_highlight_xml( $invoice_db->aeat_xml_response ); 
					?>
				</div>
			</div>
		<?php else : ?>
			<div class="freefactu-warning-box">
				<?php esc_html_e( 'No hay respuesta XML guardada para esta factura.', 'freefactu' ); ?>
			</div>
		<?php endif; ?>

		<?php
		// Include the snapshot comparison section
		include FREEFACTU_PLUGIN_DIR . 'includes/admin/partials/debug-snapshot-section.php';
		?>

		<h2><?php esc_html_e( 'Información del Sistema', 'freefactu' ); ?></h2>
		<table class="freefactu-meta-table">
			<tr>
				<th scope="col"><?php esc_html_e( 'Campo', 'freefactu' ); ?></th>
				<th scope="col"><?php esc_html_e( 'Valor', 'freefactu' ); ?></th>
			</tr>
			<tr>
				<td><?php esc_html_e( 'Entorno', 'freefactu' ); ?></td>
				<td><code><?php echo esc_html( $env === 'production' ? __( 'Producción', 'freefactu' ) : __( 'Pruebas', 'freefactu' ) ); ?></code></td>
			</tr>
			<tr>
				<td><?php esc_html_e( 'NIF Empresa', 'freefactu' ); ?></td>
				<td><code><?php echo esc_html( $company_nif ); ?></code></td>
			</tr>
			<tr>
				<td><?php esc_html_e( 'URL QR', 'freefactu' ); ?></td>
				<td><code><?php echo esc_html( $qr_url ); ?></code></td>
			</tr>
			<tr>
				<td><?php esc_html_e( 'Cache Key QR', 'freefactu' ); ?></td>
				<td><code><?php echo esc_html( $cache_key ); ?></code></td>
			</tr>
			<tr>
				<td><?php esc_html_e( 'QR en Caché', 'freefactu' ); ?></td>
				<td><code><?php echo esc_html( $qr_is_cached ? __( 'Sí', 'freefactu' ) : __( 'No', 'freefactu' ) ); ?></code></td>
			</tr>
			<tr>
				<td><?php esc_html_e( 'QR Puede Generarse', 'freefactu' ); ?></td>
				<td><code><?php echo esc_html( $qr_can_be_created ? __( 'Sí (tiene CSV)', 'freefactu' ) : __( 'No (falta CSV)', 'freefactu' ) ); ?></code></td>
			</tr>
		</table>

		<div class="freefactu-debug-footer">
			<small><?php esc_html_e( 'Esta información es solo para depuración y no debe compartirse públicamente.', 'freefactu' ); ?></small>
		</div>
	</div>
</body>
<?php
// Inline script removed - moved to assets/js/freefactu-debug.js and enqueued via freefactu_debug_invoice action handler
?>
<?php
wp_enqueue_script( 'freefactu-debug', FREEFACTU_PLUGIN_URL . 'assets/js/freefactu-debug.js', array(), FREEFACTU_VERSION, array( 'in_footer' => true, 'strategy' => 'defer' ) );
wp_print_scripts( 'freefactu-debug' );
?>
</html>
