<?php
require_once "../config.php";

$id = intval($_GET['id']);

$sql = "SELECT p.*, c.country_name 
        FROM products p
        LEFT JOIN countries c ON p.country_id=c.id
        WHERE p.id=?";

$stmt = $conn->prepare($sql);
$stmt->bind_param("i",$id);
$stmt->execute();
$res = $stmt->get_result();
$p = $res->fetch_assoc();

function show($v){
    return $v ? htmlspecialchars($v) : '—';
}
?>

<h2 style="margin-bottom:15px;"><?php echo show($p['product_name']); ?></h2>

<div class="grid">

<div class="field"><span class="label">Brand</span><span class="value"><?php echo show($p['brand_name']); ?></span></div>
<div class="field"><span class="label">Generic</span><span class="value"><?php echo show($p['generic_name']); ?></span></div>

<div class="field"><span class="label">Country</span><span class="value"><?php echo show($p['country_name']); ?></span></div>
<div class="field"><span class="label">Qty</span><span class="value"><?php echo show($p['qty']); ?></span></div>

<div class="field"><span class="label">Standards</span><span class="value"><?php echo show($p['standards']); ?></span></div>
<div class="field"><span class="label">Strength</span><span class="value"><?php echo show($p['strength']); ?></span></div>

<div class="field"><span class="label">Volume</span><span class="value"><?php echo show($p['volume']); ?></span></div>
<div class="field"><span class="label">Dosage Form</span><span class="value"><?php echo show($p['dosage_form']); ?></span></div>

<div class="field full"><span class="label">Indication</span><span class="value"><?php echo show($p['indication']); ?></span></div>

<div class="field"><span class="label">Primary Packing</span><span class="value"><?php echo show($p['primary_packing']); ?></span></div>
<div class="field"><span class="label">Secondary Packing</span><span class="value"><?php echo show($p['secondary_packing']); ?></span></div>

<div class="field"><span class="label">Shelf Life</span><span class="value"><?php echo show($p['shelf_life']); ?></span></div>
<div class="field"><span class="label">Manufactured By</span><span class="value"><?php echo show($p['manufactured_by']); ?></span></div>

<div class="field"><span class="label">Marketed By</span><span class="value"><?php echo show($p['marketed_by']); ?></span></div>
<div class="field"><span class="label">Dossier</span><span class="value"><?php echo show($p['dossier_number']); ?></span></div>

<div class="field"><span class="label">Submitted To</span><span class="value"><?php echo show($p['submitted_to']); ?></span></div>
<div class="field"><span class="label">Submitted On</span><span class="value"><?php echo show($p['submitted_on']); ?></span></div>

<div class="field"><span class="label">Samples Submitted</span><span class="value"><?php echo show($p['samples_submitted_on']); ?></span></div>
<div class="field"><span class="label">Batch Expiry</span><span class="value"><?php echo show($p['samples_batch_no_expiry']); ?></span></div>

<div class="field"><span class="label">WS Batch</span><span class="value"><?php echo show($p['ws_batch_no']); ?></span></div>
<div class="field"><span class="label">Query Received</span><span class="value"><?php echo show($p['query_received_on']); ?></span></div>

<div class="field"><span class="label">Query Sent</span><span class="value"><?php echo show($p['query_sent_on']); ?></span></div>
<div class="field"><span class="label">FDA Submitted</span><span class="value"><?php echo show($p['submitted_to_fda_on']); ?></span></div>

<div class="field"><span class="label">FDA Query Received</span><span class="value"><?php echo show($p['fda_query_received_on']); ?></span></div>
<div class="field"><span class="label">FDA Query Submitted</span><span class="value"><?php echo show($p['fda_query_submitted_on']); ?></span></div>

<div class="field full"><span class="label">Comments</span><span class="value"><?php echo show($p['result_comments']); ?></span></div>

<div class="field"><span class="label">Registration No</span><span class="value"><?php echo show($p['registration_number']); ?></span></div>
<div class="field"><span class="label">Registration Date</span><span class="value"><?php echo show($p['registration_date']); ?></span></div>

<div class="field"><span class="label">Expiry Date</span><span class="value"><?php echo show($p['registration_exp_date']); ?></span></div>
<div class="field"><span class="label">Renewal Start</span><span class="value"><?php echo show($p['renewal_process_start']); ?></span></div>

<div class="field"><span class="label">Units/Packet</span><span class="value"><?php echo show($p['units_per_packet']); ?></span></div>
<div class="field"><span class="label">Price</span><span class="value"><?php echo show($p['price_per_packet']); ?></span></div>

<div class="field"><span class="label">GST</span><span class="value"><?php echo show($p['gst_percent']); ?></span></div>
<div class="field"><span class="label">Tax</span><span class="value"><?php echo show($p['tax_percent']); ?></span></div>

</div>

<?php if(!empty($p['file_path'])): ?>
<div class="preview">
  <img src="../<?php echo $p['file_path']; ?>">
  <br>
  <a class="download-btn" href="../<?php echo $p['file_path']; ?>" download>Download File</a>
</div>
<?php endif; ?>