<?php
require_once __DIR__ . '/qrcode_generator.php';

$dataFile = __DIR__ . '/data/products.json';
$productsList = json_decode(file_get_contents($dataFile), true);

$products = [];
foreach ($productsList as $pr) { 
    $products[$pr['id']] = $pr; 
}

$id = 38;
$p = $products[$id] ?? null;

if (!$p) {
    echo "Product not found";
    exit;
}

echo "<h1>" . $p['title'] . "</h1>\n";
echo "<hr>\n";
echo "<h3>QR Code Section:</h3>\n";

$srNo = !empty($p['sr_no']) ? $p['sr_no'] : null;
$qrCodeUrl = getProductQRCode($p['id'], $srNo);

echo "SR NO value: " . var_export($srNo, true) . "\n";
echo "Is empty?: " . (!empty($srNo) ? "NO" : "YES") . "\n";
echo "QR URL: " . $qrCodeUrl . "\n\n";

echo "<div class=\"qr-code-section\">\n";
echo "  <h4>Product Code</h4>\n";
echo "  <img src=\"" . htmlspecialchars($qrCodeUrl) . "\" alt=\"Product QR Code\" style=\"max-width:150px;\">\n";
if (!empty($srNo)) {
    echo "  <p style=\"font-size:12px; color:#333; margin:8px 0; font-weight:600;\">SR NO: <strong style=\"color:#F07E2D;\">" . formatProductSRNo($srNo) . "</strong></p>\n";
} else {
    echo "  <!-- SR NO is empty, not displaying -->\n";
}
echo "  <p style=\"font-size:11px; color:#999; margin:8px 0 0 0;\">Scan QR code to view product</p>\n";
echo "</div>\n";
?>
